Class GBContext.GBContextBuilder

java.lang.Object
growthbook.sdk.java.model.GBContext.GBContextBuilder
Enclosing class:
GBContext

public static class GBContext.GBContextBuilder extends Object
The builder class to help create a context. You can use GBContext.builder() or the GBContext constructor
  • Method Details

    • attributesJson

      public GBContext.GBContextBuilder attributesJson(@Nullable String attributesJson)
      Parameters:
      attributesJson - User attributes as JSON string
      Returns:
      this.
    • attributes

      public GBContext.GBContextBuilder attributes(@Nullable com.google.gson.JsonObject attributes)
      Parameters:
      attributes - User attributes as JSON Object, either set this or `attributesJson`
      Returns:
      this.
    • featuresJson

      public GBContext.GBContextBuilder featuresJson(@Nullable String featuresJson)
      Parameters:
      featuresJson - Features response as JSON string, or the encrypted payload. Encrypted payload requires `encryptionKey`
      Returns:
      this.
    • features

      public GBContext.GBContextBuilder features(@Nullable Map<String,Feature<?>> features)
      Parameters:
      features - Features response as JSON Object, either set this or `featuresJson`
      Returns:
      this.
    • encryptionKey

      public GBContext.GBContextBuilder encryptionKey(@Nullable String encryptionKey)
      Parameters:
      encryptionKey - Optional encryption key. If this is not null, featuresJson should be an encrypted payload.
      Returns:
      this.
    • enabled

      public GBContext.GBContextBuilder enabled(@Nullable Boolean enabled)
      Parameters:
      enabled - Whether globally all experiments are enabled (default: true)
      Returns:
      this.
    • isQaMode

      public GBContext.GBContextBuilder isQaMode(Boolean isQaMode)
      Parameters:
      isQaMode - If true, random assignment is disabled and only explicitly forced variations are used.
      Returns:
      this.
    • url

      public GBContext.GBContextBuilder url(@Nullable String url)
      Parameters:
      url - A URL string that is used for experiment evaluation, as well as forcing feature values.
      Returns:
      this.
    • allowUrlOverrides

      public GBContext.GBContextBuilder allowUrlOverrides(Boolean allowUrlOverrides)
      Parameters:
      allowUrlOverrides - Boolean flag to allow URL overrides (default: false)
      Returns:
      this.
    • forcedVariationsMap

      public GBContext.GBContextBuilder forcedVariationsMap(@Nullable Map<String,?> forcedVariationsMap)
      Parameters:
      forcedVariationsMap - Force specific experiments to always assign a specific variation (used for QA)
      Returns:
      this.
    • trackingCallback

      public GBContext.GBContextBuilder trackingCallback(@Nullable TrackingCallback trackingCallback)
      Parameters:
      trackingCallback - A function that takes Experiment and ExperimentResult as arguments.
      Returns:
      this.
    • featureUsageCallback

      public GBContext.GBContextBuilder featureUsageCallback(@Nullable FeatureUsageCallback featureUsageCallback)
      Parameters:
      featureUsageCallback - A function that takes String and FeatureResult as arguments. A callback that will be invoked every time a feature is viewed. Listen for feature usage events
      Returns:
      this.
    • stickyBucketService

      public GBContext.GBContextBuilder stickyBucketService(@Nullable StickyBucketService stickyBucketService)
      Parameters:
      stickyBucketService - Service that provide functionality of Sticky Bucketing.
      Returns:
      this.
    • stickyBucketAssignmentDocs

      public GBContext.GBContextBuilder stickyBucketAssignmentDocs(@Nullable Map<String,StickyAssignmentsDocument> stickyBucketAssignmentDocs)
      Parameters:
      stickyBucketAssignmentDocs - Map of Sticky Bucket documents.
      Returns:
      this.
    • stickyBucketIdentifierAttributes

      public GBContext.GBContextBuilder stickyBucketIdentifierAttributes(@Nullable List<String> stickyBucketIdentifierAttributes)
      Parameters:
      stickyBucketIdentifierAttributes - List of user's attributes keys.
      Returns:
      this.
    • savedGroups

      public GBContext.GBContextBuilder savedGroups(@Nullable com.google.gson.JsonObject savedGroups)
      Parameters:
      savedGroups - Saved Groups data.
      Returns:
      this.
    • apiHost

      public GBContext.GBContextBuilder apiHost(@Nullable String apiHost)
      Parameters:
      apiHost - GrowthBook API host for remote evaluation.
      Returns:
      this.
    • clientKey

      public GBContext.GBContextBuilder clientKey(@Nullable String clientKey)
      Parameters:
      clientKey - GrowthBook SDK client key for remote evaluation.
      Returns:
      this.
    • remoteEval

      public GBContext.GBContextBuilder remoteEval(@Nullable Boolean remoteEval)
      Parameters:
      remoteEval - Whether to use remote evaluation.
      Returns:
      this.
    • cacheKeyAttributes

      public GBContext.GBContextBuilder cacheKeyAttributes(@Nullable List<String> cacheKeyAttributes)
      Parameters:
      cacheKeyAttributes - Attribute names used to build the remote eval cache key.
      Returns:
      this.
    • remoteEvalCacheSize

      public GBContext.GBContextBuilder remoteEvalCacheSize(@Nullable Integer remoteEvalCacheSize)
      Parameters:
      remoteEvalCacheSize - Maximum number of remote eval responses kept in memory.
      Returns:
      this.
    • remoteEvalCacheTtlSeconds

      public GBContext.GBContextBuilder remoteEvalCacheTtlSeconds(@Nullable Integer remoteEvalCacheTtlSeconds)
      Returns:
      this.
    • build

      public GBContext build()
    • toString

      public String toString()
      Overrides:
      toString in class Object