All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.launchdarkly.client.FeatureFlagBuilder Maven / Gradle / Ivy

There is a newer version: 4.61
Show newest version
package com.launchdarkly.client;

import com.google.gson.JsonElement;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class FeatureFlagBuilder {
  private String key;
  private int version;
  private boolean on;
  private List prerequisites = new ArrayList<>();
  private String salt;
  private List targets = new ArrayList<>();
  private List rules = new ArrayList<>();
  private VariationOrRollout fallthrough;
  private Integer offVariation;
  private List variations = new ArrayList<>();
  private boolean clientSide;
  private boolean trackEvents;
  private Long debugEventsUntilDate;
  private boolean deleted;

  FeatureFlagBuilder(String key) {
    this.key = key;
  }

  FeatureFlagBuilder(FeatureFlag f) {
    if (f != null) {
      this.key = f.getKey();
      this.version = f.getVersion();
      this.on = f.isOn();
      this.prerequisites = f.getPrerequisites();
      this.salt = f.getSalt();
      this.targets = f.getTargets();
      this.rules = f.getRules();
      this.fallthrough = f.getFallthrough();
      this.offVariation = f.getOffVariation();
      this.variations = f.getVariations();
      this.clientSide = f.isClientSide();
      this.trackEvents = f.isTrackEvents();
      this.debugEventsUntilDate = f.getDebugEventsUntilDate();
      this.deleted = f.isDeleted();
    }
  }

  FeatureFlagBuilder version(int version) {
    this.version = version;
    return this;
  }

  FeatureFlagBuilder on(boolean on) {
    this.on = on;
    return this;
  }

  FeatureFlagBuilder prerequisites(List prerequisites) {
    this.prerequisites = prerequisites;
    return this;
  }

  FeatureFlagBuilder salt(String salt) {
    this.salt = salt;
    return this;
  }

  FeatureFlagBuilder targets(List targets) {
    this.targets = targets;
    return this;
  }

  FeatureFlagBuilder rules(List rules) {
    this.rules = rules;
    return this;
  }

  FeatureFlagBuilder fallthrough(VariationOrRollout fallthrough) {
    this.fallthrough = fallthrough;
    return this;
  }

  FeatureFlagBuilder offVariation(Integer offVariation) {
    this.offVariation = offVariation;
    return this;
  }

  FeatureFlagBuilder variations(List variations) {
    this.variations = variations;
    return this;
  }

  FeatureFlagBuilder variations(JsonElement... variations) {
    return variations(Arrays.asList(variations));
  }

  FeatureFlagBuilder clientSide(boolean clientSide) {
    this.clientSide = clientSide;
    return this;
  }
  
  FeatureFlagBuilder trackEvents(boolean trackEvents) {
    this.trackEvents = trackEvents;
    return this;
  }
  
  FeatureFlagBuilder debugEventsUntilDate(Long debugEventsUntilDate) {
    this.debugEventsUntilDate = debugEventsUntilDate;
    return this;
  }
  
  FeatureFlagBuilder deleted(boolean deleted) {
    this.deleted = deleted;
    return this;
  }

  FeatureFlag build() {
    return new FeatureFlag(key, version, on, prerequisites, salt, targets, rules, fallthrough, offVariation, variations,
        clientSide, trackEvents, debugEventsUntilDate, deleted);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy