Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 0c07f35

Browse files
committed
Add a new method allFlags that returns the set of all feature flags for a given user.
1 parent 876e1d3 commit 0c07f35

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/main/java/com/launchdarkly/client/LDClient.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.io.Closeable;
1111
import java.io.IOException;
1212
import java.net.URL;
13+
import java.util.HashMap;
14+
import java.util.Map;
1315
import java.util.concurrent.Future;
1416
import java.util.concurrent.TimeUnit;
1517
import java.util.concurrent.TimeoutException;
@@ -176,6 +178,35 @@ public boolean getFlag(String featureKey, LDUser user, boolean defaultValue) {
176178
return toggle(featureKey, user, defaultValue);
177179
}
178180

181+
/**
182+
* Returns a map from feature flag keys to boolean feature flag values for a given user. The map will contain {@code null}
183+
* entries for any flags that are off. If the client is offline or has not been initialized, a {@code null} map will be returned.
184+
* This method will not send analytics events back to LaunchDarkly.
185+
*
186+
* The most common use case for this method is to bootstrap a set of client-side feature flags from a back-end service.
187+
*
188+
* @param user the end user requesting the feature flags
189+
* @return a map from feature flag keys to boolean feature flag values for the specified user
190+
*/
191+
public Map<String, Boolean> allFlags(LDUser user) {
192+
if (isOffline()) {
193+
return null;
194+
}
195+
196+
if (!initialized()) {
197+
return null;
198+
}
199+
200+
Map<String, FeatureRep<?>> flags = this.config.featureStore.all();
201+
Map<String, Boolean> result = new HashMap<>();
202+
203+
for (String key: flags.keySet()) {
204+
result.put(key, evaluate(key, user, null));
205+
}
206+
207+
return result;
208+
}
209+
179210
/**
180211
* Calculates the value of a feature flag for a given user.
181212
*
@@ -193,7 +224,7 @@ public boolean toggle(String featureKey, LDUser user, boolean defaultValue) {
193224
return value;
194225
}
195226

196-
private boolean evaluate(String featureKey, LDUser user, boolean defaultValue) {
227+
private Boolean evaluate(String featureKey, LDUser user, Boolean defaultValue) {
197228
if (!initialized()) {
198229
return defaultValue;
199230
}

0 commit comments

Comments
 (0)