@Test public void createPrefixMap() { Properties properties = new Properties(); properties.put("abcde", "abcde"); properties.put("abc0", "abc0"); properties.put("abc", "abc"); properties.put("ab", "ab"); properties.put("abbde", "abbde"); properties.put("abd", "abd"); properties.put("bcdef", "bcdef"); char[] array = "abc[]".toCharArray(); properties.put(array, "abc[]"); properties.put("abc[]", array); Map<String, String> answer = new HashMap<>(); answer.put("de", "abcde"); answer.put("0", "abc0"); answer.put("", "abc"); assertThat(PropertiesUtil.createPrefixMap(properties, "abc"), is(answer)); }
public static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (prefix == null) { throw new IllegalArgumentException("prefix must not be null"); } NavigableMap<String, String> results = new TreeMap<>(); 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(prefix) == false) { continue; } results.put(name.substring(prefix.length()), (String) entry.getValue()); } return results; }
PropertiesUtil { public static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (prefix == null) { throw new IllegalArgumentException("prefix must not be null"); } NavigableMap<String, String> results = new TreeMap<>(); 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(prefix) == false) { continue; } results.put(name.substring(prefix.length()), (String) entry.getValue()); } return results; } }
PropertiesUtil { public static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (prefix == null) { throw new IllegalArgumentException("prefix must not be null"); } NavigableMap<String, String> results = new TreeMap<>(); 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(prefix) == false) { continue; } results.put(name.substring(prefix.length()), (String) entry.getValue()); } return results; } private  PropertiesUtil(); }
PropertiesUtil { public static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (prefix == null) { throw new IllegalArgumentException("prefix must not be null"); } NavigableMap<String, String> results = new TreeMap<>(); 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(prefix) == false) { continue; } results.put(name.substring(prefix.length()), (String) entry.getValue()); } return results; } private  PropertiesUtil(); static void removeKeyPrefix(Properties properties, String prefix); static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix); static void checkAbsentKey(Properties properties, String key); static void checkAbsentKeyPrefix(Properties properties, String keyPrefix); }
PropertiesUtil { public static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (prefix == null) { throw new IllegalArgumentException("prefix must not be null"); } NavigableMap<String, String> results = new TreeMap<>(); 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(prefix) == false) { continue; } results.put(name.substring(prefix.length()), (String) entry.getValue()); } return results; } private  PropertiesUtil(); static void removeKeyPrefix(Properties properties, String prefix); static NavigableMap<String, String> createPrefixMap(Map<?, ?> properties, String prefix); static void checkAbsentKey(Properties properties, String key); static void checkAbsentKeyPrefix(Properties properties, String keyPrefix);  }