Class ConditionEvaluator

java.lang.Object
growthbook.sdk.java.evaluators.ConditionEvaluator
All Implemented Interfaces:
IConditionEvaluator

public class ConditionEvaluator extends Object implements IConditionEvaluator
INTERNAL: Implementation of condition evaluation.

Public only so the evaluators package can share it; it is not part of the supported API. Even so, getPath(com.google.gson.JsonElement, java.lang.String) and isOperatorObject(com.google.gson.JsonElement) keep the exact return types published in 0.11.0: a return type is part of the JVM method descriptor, so narrowing one is a NoSuchMethodError for anything linked against that release, which no compiler warns about. Internally use resolvePath(com.google.gson.JsonElement, java.lang.String) and isOperatorObjectInternal(com.google.gson.JsonElement), which carry the precise types.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    evaluateCondition(com.google.gson.JsonObject attributes, com.google.gson.JsonObject conditionJson, com.google.gson.JsonObject savedGroups)
    Evaluate a condition for a set of user attributes based on the provided condition.
    getPath(com.google.gson.JsonElement attributes, String path)
    Resolves a dot-separated path against the attributes.
    isOperatorObject(com.google.gson.JsonElement object)
    Returns a boxed Boolean to keep the signature published in 0.11.0: a return type is part of the JVM method descriptor, so narrowing it to boolean is a NoSuchMethodError for callers compiled against that release.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConditionEvaluator

      public ConditionEvaluator()
  • Method Details

    • evaluateCondition

      public Boolean evaluateCondition(com.google.gson.JsonObject attributes, com.google.gson.JsonObject conditionJson, @Nullable com.google.gson.JsonObject savedGroups)
      Evaluate a condition for a set of user attributes based on the provided condition. The condition syntax closely resembles MongoDB's syntax. This is defined in the Feature's targeting conditions' Advanced settings.
      Specified by:
      evaluateCondition in interface IConditionEvaluator
      Parameters:
      attributes - A JsonObject of the user attributes to evaluate
      conditionJson - A JsonObject of the condition
      Returns:
      Whether the condition should be true for the user
    • isOperatorObject

      public Boolean isOperatorObject(com.google.gson.JsonElement object)
      Returns a boxed Boolean to keep the signature published in 0.11.0: a return type is part of the JVM method descriptor, so narrowing it to boolean is a NoSuchMethodError for callers compiled against that release. The value is never null; prefer isOperatorObjectInternal(com.google.gson.JsonElement) inside this class.
      Parameters:
      object - The object to evaluate
      Returns:
      true if the object is empty or every key is an operator (starts with $)
    • getPath

      @Nullable public Object getPath(com.google.gson.JsonElement attributes, String path)
      Resolves a dot-separated path against the attributes.

      Declared as Object to keep the signature published in 0.11.0, for the same binary-compatibility reason as isOperatorObject(com.google.gson.JsonElement). Every value it can return is a JsonElement or null; use resolvePath(com.google.gson.JsonElement, java.lang.String) inside this class to get that type without a cast.

      Parameters:
      attributes - User attributes
      path - String path, e.g. path.to.something
      Returns:
      the value at that path, or null if the path doesn't exist