Package com.launchdarkly.sdk.server
Class FeatureFlagsState
- java.lang.Object
-
- com.launchdarkly.sdk.server.FeatureFlagsState
-
- All Implemented Interfaces:
JsonSerializable
public final class FeatureFlagsState extends java.lang.Object implements JsonSerializable
A snapshot of the state of all feature flags with regard to a specific user, generated by callingLDClientInterface.allFlagsState(com.launchdarkly.sdk.LDContext, FlagsStateOption...)
.LaunchDarkly defines a standard JSON encoding for this object, suitable for bootstrapping the LaunchDarkly JavaScript browser SDK. You can convert it to JSON in any of these ways:
- With
JsonSerialization
. - With Gson, if and only if you configure your
Gson
instance withLDGson
. - With Jackson, if and only if you configure your
ObjectMapper
instance withLDJackson
.
- Since:
- 4.3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FeatureFlagsState.Builder
A builder for aFeatureFlagsState
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FeatureFlagsState.Builder
builder(FlagsStateOption... options)
Returns aFeatureFlagsState.Builder
for creating instances.boolean
equals(java.lang.Object other)
EvaluationReason
getFlagReason(java.lang.String key)
Returns the evaluation reason for an individual feature flag at the time the state was recorded.LDValue
getFlagValue(java.lang.String key)
Returns the value of an individual feature flag at the time the state was recorded.int
hashCode()
boolean
isValid()
Returns true if this object contains a valid snapshot of feature flag state, or false if the state could not be computed (for instance, because the client was offline or there was no user).java.util.Map<java.lang.String,LDValue>
toValuesMap()
Returns a map of flag keys to flag values.
-
-
-
Method Detail
-
builder
public static FeatureFlagsState.Builder builder(FlagsStateOption... options)
Returns aFeatureFlagsState.Builder
for creating instances.Application code will not normally use this builder, since the SDK creates its own instances. However, it may be useful in testing, to simulate values that might be returned by
LDClient.allFlagsState(com.launchdarkly.sdk.LDContext, FlagsStateOption...)
.- Parameters:
options
- the sameFlagsStateOption
s, if any, that would be passed toLDClient.allFlagsState(com.launchdarkly.sdk.LDContext, FlagsStateOption...)
- Returns:
- a builder object
- Since:
- 5.6.0
-
isValid
public boolean isValid()
Returns true if this object contains a valid snapshot of feature flag state, or false if the state could not be computed (for instance, because the client was offline or there was no user).- Returns:
- true if the state is valid
-
getFlagValue
public LDValue getFlagValue(java.lang.String key)
Returns the value of an individual feature flag at the time the state was recorded.- Parameters:
key
- the feature flag key- Returns:
- the flag's JSON value;
LDValue.ofNull()
if the flag returned the default value;null
if there was no such flag
-
getFlagReason
public EvaluationReason getFlagReason(java.lang.String key)
Returns the evaluation reason for an individual feature flag at the time the state was recorded.- Parameters:
key
- the feature flag key- Returns:
- an
EvaluationReason
; null if reasons were not recorded, or if there was no such flag
-
toValuesMap
public java.util.Map<java.lang.String,LDValue> toValuesMap()
Returns a map of flag keys to flag values. If a flag would have evaluated to the default value, its value will be null.The returned map is unmodifiable.
Do not use this method if you are passing data to the front end to "bootstrap" the JavaScript client. Instead, serialize the FeatureFlagsState object to JSON using
Gson.toJson()
orGson.toJsonTree()
.- Returns:
- an immutable map of flag keys to JSON values
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-