Package com.launchdarkly.sdk
Class EvaluationDetail<T>
- java.lang.Object
-
- com.launchdarkly.sdk.EvaluationDetail<T>
-
- Type Parameters:
T
- the type of the wrapped value
- All Implemented Interfaces:
JsonSerializable
public final class EvaluationDetail<T> extends java.lang.Object implements JsonSerializable
An object returned by the SDK's "variation detail" methods such asboolVariationDetail
, combining the result of a flag evaluation with an explanation of how it was calculated.EvaluationReason
can be converted to and from JSON in any of these ways:- With
JsonSerialization
. - With Gson, if and only if you configure your
Gson
instance withLDGson
. - With Jackson, if and only if you configure your
ObjectMapper
instance withLDJackson
.
EvaluationDetail<T>
, or else it will assume that `T` is `LDValue`. If you use eitherJsonSerialization
or Jackson, there is no way to specify the runtime type and you will always get anEvaluationDetail<LDValue>
. That is only for deserialization; serialization will always use the correct value type.
-
-
Field Summary
Fields Modifier and Type Field Description static int
NO_VARIATION
IfgetVariationIndex()
is equal to this constant, it means no variation was chosen (evaluation failed and returned a default value).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
static EvaluationDetail<LDValue>
error(EvaluationReason.ErrorKind errorKind, LDValue defaultValue)
Shortcut for creating an instance with an error result.static <T> EvaluationDetail<T>
fromValue(T value, int variationIndex, EvaluationReason reason)
Factory method for an arbitrary value.EvaluationReason
getReason()
An object describing the main factor that influenced the flag evaluation value.T
getValue()
The result of the flag evaluation.int
getVariationIndex()
The index of the returned value within the flag's list of variations, e.g.int
hashCode()
boolean
isDefaultValue()
Returns true if the flag evaluation returned the default value, rather than one of the flag's variations.java.lang.String
toString()
Returns a simple string representation of this instance.
-
-
-
Field Detail
-
NO_VARIATION
public static final int NO_VARIATION
IfgetVariationIndex()
is equal to this constant, it means no variation was chosen (evaluation failed and returned a default value).- See Also:
- Constant Field Values
-
-
Method Detail
-
fromValue
public static <T> EvaluationDetail<T> fromValue(T value, int variationIndex, EvaluationReason reason)
Factory method for an arbitrary value.- Type Parameters:
T
- the type of the value- Parameters:
value
- a value of the desired typevariationIndex
- a variation index, orNO_VARIATION
(any negative number will be changed toNO_VARIATION
)reason
- anEvaluationReason
(should not be null)- Returns:
- an
EvaluationDetail
-
error
public static EvaluationDetail<LDValue> error(EvaluationReason.ErrorKind errorKind, LDValue defaultValue)
Shortcut for creating an instance with an error result.- Parameters:
errorKind
- the type of errordefaultValue
- the application default value- Returns:
- an
EvaluationDetail
-
getReason
public EvaluationReason getReason()
An object describing the main factor that influenced the flag evaluation value.- Returns:
- an
EvaluationReason
-
getVariationIndex
public int getVariationIndex()
The index of the returned value within the flag's list of variations, e.g. 0 for the first variation, orNO_VARIATION
.- Returns:
- the variation index if applicable
-
getValue
public T getValue()
The result of the flag evaluation. This will be either one of the flag's variations or the default value that was passed to thevariation
method.- Returns:
- the flag value
-
isDefaultValue
public boolean isDefaultValue()
Returns true if the flag evaluation returned the default value, rather than one of the flag's variations. If so,getVariationIndex()
will beNO_VARIATION
.- Returns:
- true if this is the default value
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a simple string representation of this instance.This is a convenience method for debugging and any other use cases where a human-readable string is helpful. The exact format of the string is subject to change; if you need to make programmatic decisions based on the object's properties, use other methods like
getValue()
.- Overrides:
toString
in classjava.lang.Object
-
-