@Test public void computeChanges_generic() { Map<String, Object> oldMap = new HashMap<String, Object>() {{ put("a", true); put("b", false); put("c", true); put("d", false); put("g", 5); put("h", 5); }}; Map<String, Object> newMap = new HashMap<String, Object>() {{ put("a", true); put("b", true); put("c", false); put("e", true); put("f", false); put("h", 7); }}; Map<String, Change> changes = FeatureFlags.computeChanges(oldMap, newMap); assertFalse(changes.containsKey("a")); assertEquals(Change.ENABLED, changes.get("b")); assertEquals(Change.DISABLED, changes.get("c")); assertEquals(Change.REMOVED, changes.get("d")); assertEquals(Change.ENABLED, changes.get("e")); assertEquals(Change.DISABLED, changes.get("f")); assertEquals(Change.CHANGED, changes.get("h")); }
@VisibleForTesting static @NonNull Map<String, Change> computeChanges(@NonNull Map<String, Object> oldMap, @NonNull Map<String, Object> newMap) { Map<String, Change> changes = new HashMap<>(); Set<String> allKeys = new HashSet<>(); allKeys.addAll(oldMap.keySet()); allKeys.addAll(newMap.keySet()); for (String key : allKeys) { Object oldValue = oldMap.get(key); Object newValue = newMap.get(key); if (oldValue == null && newValue == null) { throw new AssertionError("Should not be possible."); } else if (oldValue != null && newValue == null) { changes.put(key, Change.REMOVED); } else if (newValue != oldValue && newValue instanceof Boolean) { changes.put(key, (boolean) newValue ? Change.ENABLED : Change.DISABLED); } else if (newValue != oldValue) { changes.put(key, Change.CHANGED); } } return changes; }
FeatureFlags { @VisibleForTesting static @NonNull Map<String, Change> computeChanges(@NonNull Map<String, Object> oldMap, @NonNull Map<String, Object> newMap) { Map<String, Change> changes = new HashMap<>(); Set<String> allKeys = new HashSet<>(); allKeys.addAll(oldMap.keySet()); allKeys.addAll(newMap.keySet()); for (String key : allKeys) { Object oldValue = oldMap.get(key); Object newValue = newMap.get(key); if (oldValue == null && newValue == null) { throw new AssertionError("Should not be possible."); } else if (oldValue != null && newValue == null) { changes.put(key, Change.REMOVED); } else if (newValue != oldValue && newValue instanceof Boolean) { changes.put(key, (boolean) newValue ? Change.ENABLED : Change.DISABLED); } else if (newValue != oldValue) { changes.put(key, Change.CHANGED); } } return changes; } }
FeatureFlags { @VisibleForTesting static @NonNull Map<String, Change> computeChanges(@NonNull Map<String, Object> oldMap, @NonNull Map<String, Object> newMap) { Map<String, Change> changes = new HashMap<>(); Set<String> allKeys = new HashSet<>(); allKeys.addAll(oldMap.keySet()); allKeys.addAll(newMap.keySet()); for (String key : allKeys) { Object oldValue = oldMap.get(key); Object newValue = newMap.get(key); if (oldValue == null && newValue == null) { throw new AssertionError("Should not be possible."); } else if (oldValue != null && newValue == null) { changes.put(key, Change.REMOVED); } else if (newValue != oldValue && newValue instanceof Boolean) { changes.put(key, (boolean) newValue ? Change.ENABLED : Change.DISABLED); } else if (newValue != oldValue) { changes.put(key, Change.CHANGED); } } return changes; } private  FeatureFlags(); }
FeatureFlags { @VisibleForTesting static @NonNull Map<String, Change> computeChanges(@NonNull Map<String, Object> oldMap, @NonNull Map<String, Object> newMap) { Map<String, Change> changes = new HashMap<>(); Set<String> allKeys = new HashSet<>(); allKeys.addAll(oldMap.keySet()); allKeys.addAll(newMap.keySet()); for (String key : allKeys) { Object oldValue = oldMap.get(key); Object newValue = newMap.get(key); if (oldValue == null && newValue == null) { throw new AssertionError("Should not be possible."); } else if (oldValue != null && newValue == null) { changes.put(key, Change.REMOVED); } else if (newValue != oldValue && newValue instanceof Boolean) { changes.put(key, (boolean) newValue ? Change.ENABLED : Change.DISABLED); } else if (newValue != oldValue) { changes.put(key, Change.CHANGED); } } return changes; } private  FeatureFlags(); static synchronized void init(); static synchronized void refreshIfNecessary(); static synchronized void update(@NonNull Map<String, Object> config); static synchronized boolean usernames(); static boolean groupsV2create(); static boolean groupsV2manageGroupLinks(); static int gv2GroupCapacity(); static GroupJoinStatus clientLocalGroupJoinStatus(); static boolean internalUser(); static boolean mentions(); static boolean verifyV2(); static String clientExpiration(); static String researchMegaphone(); static boolean phoneNumberPrivacy(); static synchronized @NonNull Map<String, Object> getMemoryValues(); static synchronized @NonNull Map<String, Object> getDiskValues(); static synchronized @NonNull Map<String, Object> getPendingDiskValues(); static synchronized @NonNull Map<String, Object> getForcedValues(); }
FeatureFlags { @VisibleForTesting static @NonNull Map<String, Change> computeChanges(@NonNull Map<String, Object> oldMap, @NonNull Map<String, Object> newMap) { Map<String, Change> changes = new HashMap<>(); Set<String> allKeys = new HashSet<>(); allKeys.addAll(oldMap.keySet()); allKeys.addAll(newMap.keySet()); for (String key : allKeys) { Object oldValue = oldMap.get(key); Object newValue = newMap.get(key); if (oldValue == null && newValue == null) { throw new AssertionError("Should not be possible."); } else if (oldValue != null && newValue == null) { changes.put(key, Change.REMOVED); } else if (newValue != oldValue && newValue instanceof Boolean) { changes.put(key, (boolean) newValue ? Change.ENABLED : Change.DISABLED); } else if (newValue != oldValue) { changes.put(key, Change.CHANGED); } } return changes; } private  FeatureFlags(); static synchronized void init(); static synchronized void refreshIfNecessary(); static synchronized void update(@NonNull Map<String, Object> config); static synchronized boolean usernames(); static boolean groupsV2create(); static boolean groupsV2manageGroupLinks(); static int gv2GroupCapacity(); static GroupJoinStatus clientLocalGroupJoinStatus(); static boolean internalUser(); static boolean mentions(); static boolean verifyV2(); static String clientExpiration(); static String researchMegaphone(); static boolean phoneNumberPrivacy(); static synchronized @NonNull Map<String, Object> getMemoryValues(); static synchronized @NonNull Map<String, Object> getDiskValues(); static synchronized @NonNull Map<String, Object> getPendingDiskValues(); static synchronized @NonNull Map<String, Object> getForcedValues(); static final String RESEARCH_MEGAPHONE_1; }