1010import java .io .Closeable ;
1111import java .io .IOException ;
1212import java .net .URL ;
13+ import java .util .HashMap ;
14+ import java .util .Map ;
1315import java .util .concurrent .Future ;
1416import java .util .concurrent .TimeUnit ;
1517import 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