Class TestData.FlagBuilder.FlagRuleBuilder
- java.lang.Object
-
- com.launchdarkly.sdk.server.integrations.TestData.FlagBuilder.FlagRuleBuilder
-
- Enclosing class:
- TestData.FlagBuilder
public final class TestData.FlagBuilder.FlagRuleBuilder extends java.lang.ObjectA builder for feature flag rules to be used withTestData.FlagBuilder.In the LaunchDarkly model, a flag can have any number of rules, and a rule can have any number of clauses. A clause is an individual test such as "name is 'X'". A rule matches a user if all of the rule's clauses match the user.
To start defining a rule, use one of the flag builder's matching methods such as
TestData.FlagBuilder.ifMatch(String, LDValue...). This defines the first clause for the rule. Optionally, you may add more clauses with the rule builder's methods such asandMatch(String, LDValue...). Finally, callthenReturn(boolean)orthenReturn(int)to finish defining the rule.
-
-
Constructor Summary
Constructors Constructor Description FlagRuleBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TestData.FlagBuilder.FlagRuleBuilderandMatch(ContextKind contextKind, java.lang.String attribute, LDValue... values)Adds another clause, using the "is one of" operator.TestData.FlagBuilder.FlagRuleBuilderandMatch(java.lang.String attribute, LDValue... values)Adds another clause, using the "is one of" operator.TestData.FlagBuilder.FlagRuleBuilderandNotMatch(ContextKind contextKind, java.lang.String attribute, LDValue... values)Adds another clause, using the "is not one of" operator.TestData.FlagBuilder.FlagRuleBuilderandNotMatch(java.lang.String attribute, LDValue... values)Adds another clause, using the "is not one of" operator.TestData.FlagBuilderthenReturn(boolean variation)Finishes defining the rule, specifying the result value as a boolean.TestData.FlagBuilderthenReturn(int variationIndex)Finishes defining the rule, specifying the result as a variation index.
-
-
-
Method Detail
-
andMatch
public TestData.FlagBuilder.FlagRuleBuilder andMatch(ContextKind contextKind, java.lang.String attribute, LDValue... values)
Adds another clause, using the "is one of" operator. This matching expression only applies to contexts of a specific kind.For example, this creates a rule that returns
trueif the name attribute for the "company" context is "Ella" and the country is "gb":testData.flag("flag") .ifMatch(ContextKind.of("company"), "name", LDValue.of("Ella")) .andMatch(ContextKind.of("company"), "country", LDValue.of("gb")) .thenReturn(true));- Parameters:
contextKind- the context kind to matchattribute- the attribute to match againstvalues- values to compare to- Returns:
- the rule builder
- Since:
- 6.0.0
- See Also:
andNotMatch(ContextKind, String, LDValue...),andMatch(String, LDValue...)
-
andMatch
public TestData.FlagBuilder.FlagRuleBuilder andMatch(java.lang.String attribute, LDValue... values)
Adds another clause, using the "is one of" operator. This is a shortcut for callingandMatch(ContextKind, String, LDValue...)withContextKind.DEFAULTas the context kind.For example, this creates a rule that returns
trueif the name is "Patsy" and the country is "gb":testData.flag("flag") .ifMatch("name", LDValue.of("Patsy")) .andMatch("country", LDValue.of("gb")) .thenReturn(true));- Parameters:
attribute- the user attribute to match againstvalues- values to compare to- Returns:
- the rule builder
- See Also:
andNotMatch(String, LDValue...),andMatch(ContextKind, String, LDValue...)
-
andNotMatch
public TestData.FlagBuilder.FlagRuleBuilder andNotMatch(ContextKind contextKind, java.lang.String attribute, LDValue... values)
Adds another clause, using the "is not one of" operator. This matching expression only applies to contexts of a specific kind.For example, this creates a rule that returns
trueif the name attribute for the "company" context is "Ella" and the country is not "gb":testData.flag("flag") .ifMatch(ContextKind.of("company"), "name", LDValue.of("Ella")) .andNotMatch(ContextKind.of("company"), "country", LDValue.of("gb")) .thenReturn(true));- Parameters:
contextKind- the context kind to matchattribute- the user attribute to match againstvalues- values to compare to- Returns:
- the rule builder
- Since:
- 6.0.0
- See Also:
andMatch(ContextKind, String, LDValue...),andNotMatch(String, LDValue...)
-
andNotMatch
public TestData.FlagBuilder.FlagRuleBuilder andNotMatch(java.lang.String attribute, LDValue... values)
Adds another clause, using the "is not one of" operator.For example, this creates a rule that returns
trueif the name is "Patsy" and the country is not "gb":testData.flag("flag") .ifMatch("name", LDValue.of("Patsy")) .andNotMatch("country", LDValue.of("gb")) .thenReturn(true));- Parameters:
attribute- the user attribute to match againstvalues- values to compare to- Returns:
- the rule builder
- See Also:
andMatch(String, LDValue...),andNotMatch(ContextKind, String, LDValue...)
-
thenReturn
public TestData.FlagBuilder thenReturn(boolean variation)
Finishes defining the rule, specifying the result value as a boolean.- Parameters:
variation- the value to return if the rule matches the user- Returns:
- the flag builder
-
thenReturn
public TestData.FlagBuilder thenReturn(int variationIndex)
Finishes defining the rule, specifying the result as a variation index.- Parameters:
variationIndex- the variation to return if the rule matches the user: 0 for the first, 1 for the second, etc.- Returns:
- the flag builder
-
-