Class 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 EvaluationDetail by the SDK's "variation detail" methods such as boolVariationDetail.

    Note that while EvaluationReason has 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 as getKind() or getRuleIndex() to inspect the reason.

    LaunchDarkly defines a standard JSON encoding for evaluation reasons, used in analytics events. EvaluationReason can be converted to and from JSON in any of these ways:

    1. With JsonSerialization.
    2. With Gson, if and only if you configure your Gson instance with LDGson.
    3. With Jackson, if and only if you configure your ObjectMapper instance with LDJackson.
    • Method Detail

      • getRuleIndex

        public int getRuleIndex()
        The index of the rule that was matched (0 for the first rule in the feature flag), if the kind is EvaluationReason.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 the kind is EvaluationReason.Kind.RULE_MATCH. Otherwise null.

        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 the kind is EvaluationReason.Kind.PREREQUISITE_FAILED. Otherwise null.
        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
      • getException

        public java.lang.Exception getException()
        The exception that caused the error condition, if the kind is EvaluationReason.Kind.ERROR and the errorKind is EvaluationReason.ErrorKind.EXCEPTION. Otherwise null.

        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
      • 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:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • fallthrough

        public static EvaluationReason fallthrough​(boolean inExperiment)
        Returns an instance whose kind is EvaluationReason.Kind.FALLTHROUGH and 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
      • ruleMatch

        public static EvaluationReason ruleMatch​(int ruleIndex,
                                                 java.lang.String ruleId)
        Returns an instance whose kind is EvaluationReason.Kind.RULE_MATCH.
        Parameters:
        ruleIndex - the rule index
        ruleId - the rule identifier
        Returns:
        a reason object
      • ruleMatch

        public static EvaluationReason ruleMatch​(int ruleIndex,
                                                 java.lang.String ruleId,
                                                 boolean inExperiment)
        Returns an instance whose kind is EvaluationReason.Kind.RULE_MATCH and where the inExperiment parameter represents whether the evaluation was part of an experiment.
        Parameters:
        ruleIndex - the rule index
        ruleId - the rule identifier
        inExperiment - whether the evaluation was part of an experiment
        Returns:
        a reason object
      • prerequisiteFailed

        public static EvaluationReason prerequisiteFailed​(java.lang.String prerequisiteKey)
        Returns an instance whose kind is EvaluationReason.Kind.PREREQUISITE_FAILED.
        Parameters:
        prerequisiteKey - the flag key of the prerequisite that failed
        Returns:
        a reason object
      • exception

        public static EvaluationReason exception​(java.lang.Exception exception)
        Returns an instance whose kind is EvaluationReason.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