/** * Gets all the config keys for the given types (for duplicates, the first class in the list of types takes precedence). */ public static Map<String, ConfigKey<?>> findAllConfigKeys(Object optionalInstance, Iterable<? extends Class<?>> types) { Map<String, ConfigKey<?>> result = Maps.newLinkedHashMap(); for (Class<?> type : types) { List<ConfigKey<?>> keys = FlagUtils.findAllConfigKeys(optionalInstance, type); for (ConfigKey<?> key : keys) { if (!result.containsKey(key.getName())) result.put(key.getName(), key); } } return result; }
@Test public void testFindAllConfigKeys() { Map<String, ConfigKey<?>> keys = FlagUtils.findAllConfigKeys(null, ImmutableList.of(SubFooCK.class)); assertEquals(keys, ImmutableMap.of( FooCK.CK1.getName(), FooCK.CK1, FooCK.CK2.getName(), FooCK.CK2, FooCK.CK3.getName(), FooCK.CK3, SubFooCK.CK4.getName(), SubFooCK.CK4)); }