Class TestData.FlagBuilder
- Enclosing class:
- TestData
TestData
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A functional interface for use withvariationFunc(VariationFunc)
orvariationIndexFunc(VariationFunc)
. -
Method Summary
Modifier and TypeMethodDescriptionA shortcut for setting the flag to use the standard boolean configuration.variation
(boolean variation) Sets the flag to return the specified boolean variation for all contexts by default.variation
(int variationIndex) Sets the flag to return the specified variation for all contexts by default.Sets the flag to return the specified variation for all contexts by default.variationForKey
(ContextKind contextKind, String contextKey, boolean variation) Sets the flag to return the specified boolean variation for a specific context by kind and key, overriding any other defaults.variationForKey
(ContextKind contextKind, String contextKey, int variationIndex) Sets the flag to return the specified variation for a specific context by kind and key, overriding any other defaults.variationForKey
(ContextKind contextKind, String contextKey, LDValue value) Sets the flag to return the specified variation for a specific context by kind and key, overriding any other defaults.variationForUser
(String userKey, boolean variation) Sets the flag to return the specified boolean variation for a specific user key, overriding any other defaults.variationForUser
(String userKey, int variationIndex) Sets the flag to return the specified variation for a specific user key, overriding any other defaults.variationForUser
(String userKey, LDValue value) Sets the flag to return the specified variation for a specific user key, overriding any other defaults.variationFunc
(TestData.FlagBuilder.VariationFunc<Boolean> variationFunc) Sets the flag to use a function to determine whether to return true or false for any given context.variationIndexFunc
(TestData.FlagBuilder.VariationFunc<Integer> variationFunc) Sets the flag to use a function to determine the variation index to return for any given context.variations
(LDValue... values) Changes the allowable variation values for the flag.variationValueFunc
(TestData.FlagBuilder.VariationFunc<LDValue> variationFunc) Sets the flag to use a function to determine the variation index to return for any given context.
-
Method Details
-
booleanFlag
A shortcut for setting the flag to use the standard boolean configuration.This is the default for all new flags created with
TestData.flag(String)
. The flag will have two variations,true
andfalse
(in that order); it will returnfalse
whenever targeting is off, andtrue
when targeting is on if no other settings specify otherwise.- Returns:
- the builder
-
variation
Sets the flag to return the specified boolean variation for all contexts by default.The flag's variations are set to
true
andfalse
if they are not already (equivalent to callingbooleanFlag()
).- Parameters:
variation
- the desired true/false variation to be returned by default- Returns:
- the builder
-
variation
Sets the flag to return the specified variation for all contexts by default.The variation is specified by number, out of whatever variation values have already been defined.
- Parameters:
variationIndex
- the desired variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
-
variation
Sets the flag to return the specified variation for all contexts by default.The value may be of any JSON type, as defined by
LDValue
. If the value matches one of the values previously specified withvariations(LDValue...)
, then the variation index is set to the index of that value. Otherwise, the value is added to the variation list.- Parameters:
value
- the desired value to be returned for all contexts- Returns:
- the builder
-
variationForUser
Sets the flag to return the specified boolean variation for a specific user key, overriding any other defaults.The flag's variations are set to
true
andfalse
if they are not already (equivalent to callingbooleanFlag()
).- Parameters:
userKey
- a user keyvariation
- the desired true/false variation to be returned for this user- Returns:
- the builder
- See Also:
-
variationForUser
Sets the flag to return the specified variation for a specific user key, overriding any other defaults.- Parameters:
userKey
- a user keyvariationIndex
- the desired variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
- See Also:
-
variationForUser
Sets the flag to return the specified variation for a specific user key, overriding any other defaults.The value may be of any JSON type, as defined by
LDValue
. If the value matches one of the values previously specified withvariations(LDValue...)
, then the variation index is set to the index of that value. Otherwise, the value is added to the variation list.- Parameters:
userKey
- a user keyvalue
- the desired variation value- Returns:
- the builder
- See Also:
-
variationForKey
public TestData.FlagBuilder variationForKey(ContextKind contextKind, String contextKey, boolean variation) Sets the flag to return the specified boolean variation for a specific context by kind and key, overriding any other defaults.The flag's variations are set to
true
andfalse
if they are not already (equivalent to callingbooleanFlag()
).- Parameters:
contextKind
- the context kind (if null,ContextKind.DEFAULT
is used)contextKey
- the context keyvariation
- the desired true/false variation to be returned for this context- Returns:
- the builder
- See Also:
-
variationForKey
public TestData.FlagBuilder variationForKey(ContextKind contextKind, String contextKey, int variationIndex) Sets the flag to return the specified variation for a specific context by kind and key, overriding any other defaults.- Parameters:
contextKind
- the context kind (if null,ContextKind.DEFAULT
is used)contextKey
- the context keyvariationIndex
- the desired variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
- See Also:
-
variationForKey
public TestData.FlagBuilder variationForKey(ContextKind contextKind, String contextKey, LDValue value) Sets the flag to return the specified variation for a specific context by kind and key, overriding any other defaults.The value may be of any JSON type, as defined by
LDValue
. If the value matches one of the values previously specified withvariations(LDValue...)
, then the variation index is set to the index of that value. Otherwise, the value is added to the variation list.- Parameters:
contextKind
- the context kind (if null,ContextKind.DEFAULT
is used)contextKey
- the context keyvalue
- the desired variation value- Returns:
- the builder
- See Also:
-
variationFunc
public TestData.FlagBuilder variationFunc(TestData.FlagBuilder.VariationFunc<Boolean> variationFunc) Sets the flag to use a function to determine whether to return true or false for any given context.This function takes an evaluation context and returns
true
,false
, ornull
. Anull
result means that the flag will fall back to its default variation.The flag's variations are set to
true
andfalse
if they are not already (equivalent to callingbooleanFlag()
).This function is called only if the context was not specifically targeted with
variationForUser(String, boolean)
orvariationForKey(ContextKind, String, boolean)
.- Parameters:
variationFunc
- a function to determine the variation- Returns:
- the builder
-
variationValueFunc
public TestData.FlagBuilder variationValueFunc(TestData.FlagBuilder.VariationFunc<LDValue> variationFunc) Sets the flag to use a function to determine the variation index to return for any given context.This function takes an evaluation context and returns an
LDValue
. The value must match one of the values already specified withvariations(LDValue...)
; otherwise, the function will have no effect.This function is called only if the context was not specifically targeted with a method such as
variationForUser(String, int)
orvariationForKey(ContextKind, String, int)
.- Parameters:
variationFunc
- a function to determine the variation- Returns:
- the builder
-
variationIndexFunc
public TestData.FlagBuilder variationIndexFunc(TestData.FlagBuilder.VariationFunc<Integer> variationFunc) Sets the flag to use a function to determine the variation index to return for any given context.This function takes an evaluation context and returns an integer variation index or
null
. Anull
result means that the flag will fall back to its default variation.This function is called only if the context was not specifically targeted with
variationForUser(String, int)
orvariationForKey(ContextKind, String, int)
.- Parameters:
variationFunc
- a function to determine the variation- Returns:
- the builder
-
variations
Changes the allowable variation values for the flag.The value may be of any JSON type, as defined by
LDValue
. For instance, a boolean flag normally hasLDValue.of(true), LDValue.of(false)
; a string-valued flag might haveLDValue.of("red"), LDValue.of("green")
; etc.- Parameters:
values
- the desired variations- Returns:
- the builder
-