@Test public void testFindFullPrefixKeys() { Properties props = new Properties(); props.setProperty("a.b", "123"); props.setProperty("a.b1", "123"); props.setProperty("b", "123"); props.setProperty("b_a", "123"); props.setProperty("a.b.c", "123"); props.setProperty("a.b.c.d.e", "123"); props.setProperty("b.a", "123"); Set<String> fullPrefixKeys = ConfigUtils.findFullPrefixKeys(props, Optional.<String>absent()); Assert.assertEquals(fullPrefixKeys, new HashSet<>(Arrays.asList("a.b", "a.b.c", "b"))); fullPrefixKeys = ConfigUtils.findFullPrefixKeys(props, Optional.of("a.")); Assert.assertEquals(fullPrefixKeys, new HashSet<>(Arrays.asList("a.b", "a.b.c"))); fullPrefixKeys = ConfigUtils.findFullPrefixKeys(props, Optional.of("c.")); Assert.assertTrue(fullPrefixKeys.isEmpty()); props = new Properties(); props.setProperty("a.b", "123"); props.setProperty("a.b1", "123"); props.setProperty("b", "123"); props.setProperty("b_a", "123"); fullPrefixKeys = ConfigUtils.findFullPrefixKeys(props, Optional.<String>absent()); Assert.assertTrue(fullPrefixKeys.isEmpty()); }
public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) { TreeSet<String> propNames = new TreeSet<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) { propNames.add(entryKey); } } Set<String> result = new HashSet<>(); String lastKey = null; Iterator<String> sortedKeysIter = propNames.iterator(); while(sortedKeysIter.hasNext()) { String propName = sortedKeysIter.next(); if (null != lastKey && propName.startsWith(lastKey + ".")) { result.add(lastKey); } lastKey = propName; } return result; }
ConfigUtils { public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) { TreeSet<String> propNames = new TreeSet<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) { propNames.add(entryKey); } } Set<String> result = new HashSet<>(); String lastKey = null; Iterator<String> sortedKeysIter = propNames.iterator(); while(sortedKeysIter.hasNext()) { String propName = sortedKeysIter.next(); if (null != lastKey && propName.startsWith(lastKey + ".")) { result.add(lastKey); } lastKey = propName; } return result; } }
ConfigUtils { public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) { TreeSet<String> propNames = new TreeSet<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) { propNames.add(entryKey); } } Set<String> result = new HashSet<>(); String lastKey = null; Iterator<String> sortedKeysIter = propNames.iterator(); while(sortedKeysIter.hasNext()) { String propName = sortedKeysIter.next(); if (null != lastKey && propName.startsWith(lastKey + ".")) { result.add(lastKey); } lastKey = propName; } return result; } ConfigUtils(FileUtils fileUtils); }
ConfigUtils { public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) { TreeSet<String> propNames = new TreeSet<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) { propNames.add(entryKey); } } Set<String> result = new HashSet<>(); String lastKey = null; Iterator<String> sortedKeysIter = propNames.iterator(); while(sortedKeysIter.hasNext()) { String propName = sortedKeysIter.next(); if (null != lastKey && propName.startsWith(lastKey + ".")) { result.add(lastKey); } lastKey = propName; } return result; } ConfigUtils(FileUtils fileUtils); void saveConfigToFile(final Config config, final Path destPath); static Properties configToProperties(Config config); static Properties configToProperties(Config config, Optional<String> prefix); static Properties configToProperties(Config config, String prefix); static Config getConfigOrEmpty(Config config, String key); static State configToState(Config config); static Config propertiesToConfig(Properties properties); static Set<String> findFullPrefixKeys(Properties properties,
                                               Optional<String> keyPrefix); static Config propertiesToConfig(Properties properties, Optional<String> prefix); static String sanitizeFullPrefixKey(String propKey); static boolean sanitizedKey(String propKey); static String desanitizeKey(String propKey); static Config propertiesToTypedConfig(Properties properties, Optional<String> prefix); static String emptyIfNotPresent(Config config, String path); static String getString(Config config, String path, String def); static TimeUnit getTimeUnit(Config config, String path, TimeUnit def); static Long getLong(Config config, String path, Long def); static Integer getInt(Config config, String path, Integer def); static boolean getBoolean(Config config, String path, boolean def); static double getDouble(Config config, String path, double def); static Config getConfig(Config config, String path, Config def); static List<String> getStringList(Config config, String path); static boolean hasNonEmptyPath(Config config, String key); static boolean verifySubset(Config superConfig, Config subConfig); static Config resolveEncrypted(Config config, Optional<String> encConfigPath); }
ConfigUtils { public static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix) { TreeSet<String> propNames = new TreeSet<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) { propNames.add(entryKey); } } Set<String> result = new HashSet<>(); String lastKey = null; Iterator<String> sortedKeysIter = propNames.iterator(); while(sortedKeysIter.hasNext()) { String propName = sortedKeysIter.next(); if (null != lastKey && propName.startsWith(lastKey + ".")) { result.add(lastKey); } lastKey = propName; } return result; } ConfigUtils(FileUtils fileUtils); void saveConfigToFile(final Config config, final Path destPath); static Properties configToProperties(Config config); static Properties configToProperties(Config config, Optional<String> prefix); static Properties configToProperties(Config config, String prefix); static Config getConfigOrEmpty(Config config, String key); static State configToState(Config config); static Config propertiesToConfig(Properties properties); static Set<String> findFullPrefixKeys(Properties properties,
                                               Optional<String> keyPrefix); static Config propertiesToConfig(Properties properties, Optional<String> prefix); static String sanitizeFullPrefixKey(String propKey); static boolean sanitizedKey(String propKey); static String desanitizeKey(String propKey); static Config propertiesToTypedConfig(Properties properties, Optional<String> prefix); static String emptyIfNotPresent(Config config, String path); static String getString(Config config, String path, String def); static TimeUnit getTimeUnit(Config config, String path, TimeUnit def); static Long getLong(Config config, String path, Long def); static Integer getInt(Config config, String path, Integer def); static boolean getBoolean(Config config, String path, boolean def); static double getDouble(Config config, String path, double def); static Config getConfig(Config config, String path, Config def); static List<String> getStringList(Config config, String path); static boolean hasNonEmptyPath(Config config, String key); static boolean verifySubset(Config superConfig, Config subConfig); static Config resolveEncrypted(Config config, Optional<String> encConfigPath); static final String STRIP_SUFFIX; }