Class EvaluationReason
- java.lang.Object
-
- com.launchdarkly.sdk.EvaluationReason
-
- All Implemented Interfaces:
JsonSerializable
public final class EvaluationReason extends java.lang.Object implements JsonSerializable
Describes the reason that a flag evaluation produced a particular value.This is returned within
EvaluationDetailby the SDK's "variation detail" methods such asboolVariationDetail.Note that while
EvaluationReasonhas subclasses as an implementation detail, the subclasses are not public and may be removed in the future. Always use methods of the base class such asgetKind()orgetRuleIndex()to inspect the reason.LaunchDarkly defines a standard JSON encoding for evaluation reasons, used in analytics events.
EvaluationReasoncan be converted to and from JSON in any of these ways:- With
JsonSerialization. - With Gson, if and only if you configure your
Gsoninstance withLDGson. - With Jackson, if and only if you configure your
ObjectMapperinstance withLDJackson.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEvaluationReason.BigSegmentsStatusEnumerated type defining the possible values ofgetBigSegmentsStatus().static classEvaluationReason.ErrorKindEnumerated type defining the possible values ofgetErrorKind().static classEvaluationReason.KindEnumerated type defining the possible values ofgetKind().
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object other)static EvaluationReasonerror(EvaluationReason.ErrorKind errorKind)Returns an instance whosekindisEvaluationReason.Kind.ERROR.static EvaluationReasonexception(java.lang.Exception exception)Returns an instance whosekindisEvaluationReason.Kind.ERROR, with an exception instance.static EvaluationReasonfallthrough()Returns an instance whosekindisEvaluationReason.Kind.FALLTHROUGH.static EvaluationReasonfallthrough(boolean inExperiment)Returns an instance whosekindisEvaluationReason.Kind.FALLTHROUGHand where the inExperiment parameter represents whether the evaluation was part of an experiment.EvaluationReason.BigSegmentsStatusgetBigSegmentsStatus()Describes the validity of Big Segment information, if and only if the flag evaluation required querying at least one Big Segment.EvaluationReason.ErrorKindgetErrorKind()An enumeration value indicating the general category of error, if thekindisEvaluationReason.Kind.PREREQUISITE_FAILED.java.lang.ExceptiongetException()The exception that caused the error condition, if thekindisEvaluationReason.Kind.ERRORand theerrorKindisEvaluationReason.ErrorKind.EXCEPTION.EvaluationReason.KindgetKind()Returns an enum indicating the general category of the reason.java.lang.StringgetPrerequisiteKey()The key of the prerequisite flag that did not return the desired variation, if thekindisEvaluationReason.Kind.PREREQUISITE_FAILED.java.lang.StringgetRuleId()The unique identifier of the rule that was matched, if thekindisEvaluationReason.Kind.RULE_MATCH.intgetRuleIndex()The index of the rule that was matched (0 for the first rule in the feature flag), if thekindisEvaluationReason.Kind.RULE_MATCH.inthashCode()booleanisInExperiment()Whether the evaluation was part of an experiment.static EvaluationReasonoff()Returns an instance whosekindisEvaluationReason.Kind.OFF.static EvaluationReasonprerequisiteFailed(java.lang.String prerequisiteKey)Returns an instance whosekindisEvaluationReason.Kind.PREREQUISITE_FAILED.static EvaluationReasonruleMatch(int ruleIndex, java.lang.String ruleId)Returns an instance whosekindisEvaluationReason.Kind.RULE_MATCH.static EvaluationReasonruleMatch(int ruleIndex, java.lang.String ruleId, boolean inExperiment)Returns an instance whosekindisEvaluationReason.Kind.RULE_MATCHand where the inExperiment parameter represents whether the evaluation was part of an experiment.static EvaluationReasontargetMatch()Returns an instance whosekindisEvaluationReason.Kind.TARGET_MATCH.java.lang.StringtoString()Returns a simple string representation of the reason.EvaluationReasonwithBigSegmentsStatus(EvaluationReason.BigSegmentsStatus bigSegmentsStatus)Returns a copy of thisEvaluationReasonwith a specificEvaluationReason.BigSegmentsStatusvalue.
-
-
-
Method Detail
-
getKind
public EvaluationReason.Kind getKind()
Returns an enum indicating the general category of the reason.- Returns:
- a
EvaluationReason.Kindvalue
-
getRuleIndex
public int getRuleIndex()
The index of the rule that was matched (0 for the first rule in the feature flag), if thekindisEvaluationReason.Kind.RULE_MATCH. Otherwise this returns -1.- Returns:
- the rule index or -1
-
getRuleId
public java.lang.String getRuleId()
The unique identifier of the rule that was matched, if thekindisEvaluationReason.Kind.RULE_MATCH. Otherwisenull.Unlike the rule index, this identifier will not change if other rules are added or deleted.
- Returns:
- the rule identifier or null
-
getPrerequisiteKey
public java.lang.String getPrerequisiteKey()
The key of the prerequisite flag that did not return the desired variation, if thekindisEvaluationReason.Kind.PREREQUISITE_FAILED. Otherwisenull.- Returns:
- the prerequisite flag key or null
-
isInExperiment
public boolean isInExperiment()
Whether the evaluation was part of an experiment. Returns true if the evaluation resulted in an experiment rollout *and* served one of the variations in the experiment. Otherwise it returns false.- Returns:
- whether the evaluation was part of an experiment
-
getErrorKind
public EvaluationReason.ErrorKind getErrorKind()
An enumeration value indicating the general category of error, if thekindisEvaluationReason.Kind.PREREQUISITE_FAILED. Otherwisenull.- Returns:
- the error kind or null
-
getException
public java.lang.Exception getException()
The exception that caused the error condition, if thekindisEvaluationReason.Kind.ERRORand theerrorKindisEvaluationReason.ErrorKind.EXCEPTION. Otherwisenull.Note that the exception will not be included in the JSON serialization of the reason when it appears in analytics events; it is only provided informationally for use by application code.
- Returns:
- the exception instance
-
getBigSegmentsStatus
public EvaluationReason.BigSegmentsStatus getBigSegmentsStatus()
Describes the validity of Big Segment information, if and only if the flag evaluation required querying at least one Big Segment. Otherwise it returnsnull.Big Segments are a specific type of user segments. For more information, read the LaunchDarkly documentation .
- Returns:
- the
EvaluationReason.BigSegmentsStatusfrom the evaluation ornull
-
withBigSegmentsStatus
public EvaluationReason withBigSegmentsStatus(EvaluationReason.BigSegmentsStatus bigSegmentsStatus)
Returns a copy of thisEvaluationReasonwith a specificEvaluationReason.BigSegmentsStatusvalue.- Parameters:
bigSegmentsStatus- the new property value- Returns:
- a new reason object
-
toString
public java.lang.String toString()
Returns a simple string representation of the reason.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 reason properties, use other methods like
getKind().- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
off
public static EvaluationReason off()
Returns an instance whosekindisEvaluationReason.Kind.OFF.- Returns:
- a reason object
-
fallthrough
public static EvaluationReason fallthrough()
Returns an instance whosekindisEvaluationReason.Kind.FALLTHROUGH.- Returns:
- a reason object
-
fallthrough
public static EvaluationReason fallthrough(boolean inExperiment)
Returns an instance whosekindisEvaluationReason.Kind.FALLTHROUGHand where the inExperiment parameter represents whether the evaluation was part of an experiment.- Parameters:
inExperiment- whether the evaluation was part of an experiment- Returns:
- a reason object
-
targetMatch
public static EvaluationReason targetMatch()
Returns an instance whosekindisEvaluationReason.Kind.TARGET_MATCH.- Returns:
- a reason object
-
ruleMatch
public static EvaluationReason ruleMatch(int ruleIndex, java.lang.String ruleId)
Returns an instance whosekindisEvaluationReason.Kind.RULE_MATCH.- Parameters:
ruleIndex- the rule indexruleId- the rule identifier- Returns:
- a reason object
-
ruleMatch
public static EvaluationReason ruleMatch(int ruleIndex, java.lang.String ruleId, boolean inExperiment)
Returns an instance whosekindisEvaluationReason.Kind.RULE_MATCHand where the inExperiment parameter represents whether the evaluation was part of an experiment.- Parameters:
ruleIndex- the rule indexruleId- the rule identifierinExperiment- whether the evaluation was part of an experiment- Returns:
- a reason object
-
prerequisiteFailed
public static EvaluationReason prerequisiteFailed(java.lang.String prerequisiteKey)
Returns an instance whosekindisEvaluationReason.Kind.PREREQUISITE_FAILED.- Parameters:
prerequisiteKey- the flag key of the prerequisite that failed- Returns:
- a reason object
-
error
public static EvaluationReason error(EvaluationReason.ErrorKind errorKind)
Returns an instance whosekindisEvaluationReason.Kind.ERROR.- Parameters:
errorKind- describes the type of error- Returns:
- a reason object
-
exception
public static EvaluationReason exception(java.lang.Exception exception)
Returns an instance whosekindisEvaluationReason.Kind.ERROR, with an exception instance.Note that the exception will not be included in the JSON serialization of the reason when it appears in analytics events; it is only provided informationally for use by application code.
- Parameters:
exception- the exception that caused the error- Returns:
- a reason object
-
-