@Test public void getChildKeys() { Properties properties = new Properties(); properties.put("aaa", ""); properties.put("aaa.bbb", ""); properties.put("aaa.ccc.1", ""); properties.put("aaa.ccc.2", ""); properties.put("aaa.ddd", ""); properties.put("aaa.ddd.1", ""); properties.put("aab.1", ""); properties.put("aa9.1", ""); Set<String> keys = PropertiesUtil.getChildKeys(properties, "aaa.", "."); assertThat(keys.size(), is(3)); assertThat(keys, hasItem("aaa.bbb")); assertThat(keys, hasItem("aaa.ccc")); assertThat(keys, hasItem("aaa.ddd")); }
public static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (parentPrefix == null) { throw new IllegalArgumentException("prefix must not be null"); } if (delimitier == null) { throw new IllegalArgumentException("delimitier must not be null"); } int parentLength = parentPrefix.length(); Set<String> results = new TreeSet<>(); for (Map.Entry<?, ?> entry : properties.entrySet()) { if ((entry.getKey() instanceof String) == false || (entry.getValue() instanceof String) == false) { continue; } String name = (String) entry.getKey(); if (name.startsWith(parentPrefix) == false) { continue; } int index = name.indexOf(delimitier, parentLength); if (index < 0) { results.add(name); } else { results.add(name.substring(0, index)); } } return results; }
PropertiesUtil { public static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (parentPrefix == null) { throw new IllegalArgumentException("prefix must not be null"); } if (delimitier == null) { throw new IllegalArgumentException("delimitier must not be null"); } int parentLength = parentPrefix.length(); Set<String> results = new TreeSet<>(); for (Map.Entry<?, ?> entry : properties.entrySet()) { if ((entry.getKey() instanceof String) == false || (entry.getValue() instanceof String) == false) { continue; } String name = (String) entry.getKey(); if (name.startsWith(parentPrefix) == false) { continue; } int index = name.indexOf(delimitier, parentLength); if (index < 0) { results.add(name); } else { results.add(name.substring(0, index)); } } return results; } }
PropertiesUtil { public static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (parentPrefix == null) { throw new IllegalArgumentException("prefix must not be null"); } if (delimitier == null) { throw new IllegalArgumentException("delimitier must not be null"); } int parentLength = parentPrefix.length(); Set<String> results = new TreeSet<>(); for (Map.Entry<?, ?> entry : properties.entrySet()) { if ((entry.getKey() instanceof String) == false || (entry.getValue() instanceof String) == false) { continue; } String name = (String) entry.getKey(); if (name.startsWith(parentPrefix) == false) { continue; } int index = name.indexOf(delimitier, parentLength); if (index < 0) { results.add(name); } else { results.add(name.substring(0, index)); } } return results; } private  PropertiesUtil(); }
PropertiesUtil { public static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (parentPrefix == null) { throw new IllegalArgumentException("prefix must not be null"); } if (delimitier == null) { throw new IllegalArgumentException("delimitier must not be null"); } int parentLength = parentPrefix.length(); Set<String> results = new TreeSet<>(); for (Map.Entry<?, ?> entry : properties.entrySet()) { if ((entry.getKey() instanceof String) == false || (entry.getValue() instanceof String) == false) { continue; } String name = (String) entry.getKey(); if (name.startsWith(parentPrefix) == false) { continue; } int index = name.indexOf(delimitier, parentLength); if (index < 0) { results.add(name); } else { results.add(name.substring(0, index)); } } return results; } private  PropertiesUtil(); static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier); static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix); }
PropertiesUtil { public static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (parentPrefix == null) { throw new IllegalArgumentException("prefix must not be null"); } if (delimitier == null) { throw new IllegalArgumentException("delimitier must not be null"); } int parentLength = parentPrefix.length(); Set<String> results = new TreeSet<>(); for (Map.Entry<?, ?> entry : properties.entrySet()) { if ((entry.getKey() instanceof String) == false || (entry.getValue() instanceof String) == false) { continue; } String name = (String) entry.getKey(); if (name.startsWith(parentPrefix) == false) { continue; } int index = name.indexOf(delimitier, parentLength); if (index < 0) { results.add(name); } else { results.add(name.substring(0, index)); } } return results; } private  PropertiesUtil(); static Set<String> getChildKeys(Map<?, ?> properties, String parentPrefix, String delimitier); static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix);  }