@Test public void onlyPrefixShouldFailMapFromProperties() throws Exception { try (InputStream is = MapsTest.class.getClassLoader().getResourceAsStream("wrong.properties")) { try { Maps.fromProperties(is); fail(); } catch (IllegalArgumentException expected) { } } }
public static Map<String, Object> fromProperties(Map<String, Object> properties) { Map<String, Object> result = new HashMap<>(); for (Object key : properties.keySet()) { String k = String.valueOf(key); if (k.startsWith(PROPERTY_PREFIX)) { Object value = properties.get(key); final String[] split = k.split(MULTIPART_SEPARATOR_PATTERN); if (split.length == 1) { throw new IllegalArgumentException("Invalid entry '" + k + "=" + value + "'. Must provide generator key"); } final String[] parts = new String[split.length - 1]; System.arraycopy(split, 1, parts, 0, split.length - 1); Map<String, Object> kv = asMap(parts, value); merge(result, kv); } } unrollArrays(result); return result; }
Maps { public static Map<String, Object> fromProperties(Map<String, Object> properties) { Map<String, Object> result = new HashMap<>(); for (Object key : properties.keySet()) { String k = String.valueOf(key); if (k.startsWith(PROPERTY_PREFIX)) { Object value = properties.get(key); final String[] split = k.split(MULTIPART_SEPARATOR_PATTERN); if (split.length == 1) { throw new IllegalArgumentException("Invalid entry '" + k + "=" + value + "'. Must provide generator key"); } final String[] parts = new String[split.length - 1]; System.arraycopy(split, 1, parts, 0, split.length - 1); Map<String, Object> kv = asMap(parts, value); merge(result, kv); } } unrollArrays(result); return result; } }
Maps { public static Map<String, Object> fromProperties(Map<String, Object> properties) { Map<String, Object> result = new HashMap<>(); for (Object key : properties.keySet()) { String k = String.valueOf(key); if (k.startsWith(PROPERTY_PREFIX)) { Object value = properties.get(key); final String[] split = k.split(MULTIPART_SEPARATOR_PATTERN); if (split.length == 1) { throw new IllegalArgumentException("Invalid entry '" + k + "=" + value + "'. Must provide generator key"); } final String[] parts = new String[split.length - 1]; System.arraycopy(split, 1, parts, 0, split.length - 1); Map<String, Object> kv = asMap(parts, value); merge(result, kv); } } unrollArrays(result); return result; }  }
Maps { public static Map<String, Object> fromProperties(Map<String, Object> properties) { Map<String, Object> result = new HashMap<>(); for (Object key : properties.keySet()) { String k = String.valueOf(key); if (k.startsWith(PROPERTY_PREFIX)) { Object value = properties.get(key); final String[] split = k.split(MULTIPART_SEPARATOR_PATTERN); if (split.length == 1) { throw new IllegalArgumentException("Invalid entry '" + k + "=" + value + "'. Must provide generator key"); } final String[] parts = new String[split.length - 1]; System.arraycopy(split, 1, parts, 0, split.length - 1); Map<String, Object> kv = asMap(parts, value); merge(result, kv); } } unrollArrays(result); return result; }  static Map<String, String> from(String... values); static Map<String, Object> fromProperties(Map<String, Object> properties); static Map<String, Object> fromProperties(InputStream is); static Map<String, Object> fromYaml(InputStream is); static Map<String, Object> fromAnnotation(String root, A annotation,
      Class<? extends A> type); static Map<String, Object> fromAnnotation(A annotation, Class<? extends A> type); static void merge(Map<String, Object> existing, Map<String, Object> map); static Map<String, T> kebabToCamelCase(Map<String, T> map); }
Maps { public static Map<String, Object> fromProperties(Map<String, Object> properties) { Map<String, Object> result = new HashMap<>(); for (Object key : properties.keySet()) { String k = String.valueOf(key); if (k.startsWith(PROPERTY_PREFIX)) { Object value = properties.get(key); final String[] split = k.split(MULTIPART_SEPARATOR_PATTERN); if (split.length == 1) { throw new IllegalArgumentException("Invalid entry '" + k + "=" + value + "'. Must provide generator key"); } final String[] parts = new String[split.length - 1]; System.arraycopy(split, 1, parts, 0, split.length - 1); Map<String, Object> kv = asMap(parts, value); merge(result, kv); } } unrollArrays(result); return result; }  static Map<String, String> from(String... values); static Map<String, Object> fromProperties(Map<String, Object> properties); static Map<String, Object> fromProperties(InputStream is); static Map<String, Object> fromYaml(InputStream is); static Map<String, Object> fromAnnotation(String root, A annotation,
      Class<? extends A> type); static Map<String, Object> fromAnnotation(A annotation, Class<? extends A> type); static void merge(Map<String, Object> existing, Map<String, Object> map); static Map<String, T> kebabToCamelCase(Map<String, T> map);  }