@Test public void testCheckAbsentKeyPrefix() { Properties properties = new Properties(); properties.put("ab", "ab"); properties.put("abbde", "abbde"); properties.put("abd", "abd"); properties.put("bcdef", "bcdef"); char[] array = "abc[]".toCharArray(); properties.put(array, "abc[]"); PropertiesUtil.checkAbsentKeyPrefix(properties, "abc"); try { properties.put("abc", "abc"); PropertiesUtil.checkAbsentKeyPrefix(properties, "abc"); fail(); } catch (IllegalArgumentException e) { properties.remove("abc"); } try { properties.put("abcde", "abcde"); PropertiesUtil.checkAbsentKeyPrefix(properties, "abc"); fail(); } catch (IllegalArgumentException e) { properties.remove("abcde"); } }
public static void checkAbsentKeyPrefix(Properties properties, String keyPrefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (keyPrefix == null) { throw new IllegalArgumentException("keyPrefix must not be null"); } for (String key : properties.stringPropertyNames()) { if (key.startsWith(keyPrefix)) { throw new IllegalArgumentException(MessageFormat.format( "Target properties already contain \"{0}\"", key)); } } }
PropertiesUtil { public static void checkAbsentKeyPrefix(Properties properties, String keyPrefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (keyPrefix == null) { throw new IllegalArgumentException("keyPrefix must not be null"); } for (String key : properties.stringPropertyNames()) { if (key.startsWith(keyPrefix)) { throw new IllegalArgumentException(MessageFormat.format( "Target properties already contain \"{0}\"", key)); } } } }
PropertiesUtil { public static void checkAbsentKeyPrefix(Properties properties, String keyPrefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (keyPrefix == null) { throw new IllegalArgumentException("keyPrefix must not be null"); } for (String key : properties.stringPropertyNames()) { if (key.startsWith(keyPrefix)) { throw new IllegalArgumentException(MessageFormat.format( "Target properties already contain \"{0}\"", key)); } } } private  PropertiesUtil(); }
PropertiesUtil { public static void checkAbsentKeyPrefix(Properties properties, String keyPrefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (keyPrefix == null) { throw new IllegalArgumentException("keyPrefix must not be null"); } for (String key : properties.stringPropertyNames()) { if (key.startsWith(keyPrefix)) { throw new IllegalArgumentException(MessageFormat.format( "Target properties already contain \"{0}\"", key)); } } } 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 void checkAbsentKeyPrefix(Properties properties, String keyPrefix) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); } if (keyPrefix == null) { throw new IllegalArgumentException("keyPrefix must not be null"); } for (String key : properties.stringPropertyNames()) { if (key.startsWith(keyPrefix)) { throw new IllegalArgumentException(MessageFormat.format( "Target properties already contain \"{0}\"", key)); } } } 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);  }