1package {package_name}; 2 3import java.util.HashMap; 4import java.util.Map; 5import java.util.function.Predicate; 6 7{{ -if single_exported_file }} 8{{ -if library_exported }} 9@Deprecated {#- PREFER ExportedFlags #} 10{{ -endif }} 11{{ -else }} 12/** @hide */ 13{{ -endif }} 14public class FakeFeatureFlagsImpl extends CustomFeatureFlags \{ 15 private final Map<String, Boolean> mFlagMap = new HashMap<>(); 16 private final FeatureFlags mDefaults; 17 18 public FakeFeatureFlagsImpl() \{ 19 this(null); 20 } 21 22 public FakeFeatureFlagsImpl(FeatureFlags defaults) \{ 23 super(null); 24 mDefaults = defaults; 25 // Initialize the map with null values 26 for (String flagName : getFlagNames()) \{ 27 mFlagMap.put(flagName, null); 28 } 29 } 30 31 @Override 32 protected boolean getValue(String flagName, Predicate<FeatureFlags> getter) \{ 33 Boolean value = this.mFlagMap.get(flagName); 34 if (value != null) \{ 35 return value; 36 } 37 if (mDefaults != null) \{ 38 return getter.test(mDefaults); 39 } 40 throw new IllegalArgumentException(flagName + " is not set"); 41 } 42 43 public void setFlag(String flagName, boolean value) \{ 44 if (!this.mFlagMap.containsKey(flagName)) \{ 45 throw new IllegalArgumentException("no such flag " + flagName); 46 } 47 this.mFlagMap.put(flagName, value); 48 } 49 50 public void resetAll() \{ 51 for (Map.Entry entry : mFlagMap.entrySet()) \{ 52 entry.setValue(null); 53 } 54 } 55} 56