@Test public void testSplitNames() throws Exception { Map<String, Set<String>> result = PropertiesExt.splitNames(asList("top1", "top2.nested2"), 1); assertThat(result).containsEntry("top1", null); assertThat(result).containsEntry("top2", asSet("nested2")); }
public static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments) { Map<String, Set<String>> topNames = new HashMap<>(); names.forEach(n -> { Pair<String, String> parts = split(n, rootSegments); if (parts == null) { topNames.put(n, null); } else { Set<String> nested = topNames.get(parts.getLeft()); if (nested == null) { nested = new HashSet<>(); topNames.put(parts.getLeft(), nested); } nested.add(parts.getRight()); } }); return topNames; }
PropertiesExt { public static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments) { Map<String, Set<String>> topNames = new HashMap<>(); names.forEach(n -> { Pair<String, String> parts = split(n, rootSegments); if (parts == null) { topNames.put(n, null); } else { Set<String> nested = topNames.get(parts.getLeft()); if (nested == null) { nested = new HashSet<>(); topNames.put(parts.getLeft(), nested); } nested.add(parts.getRight()); } }); return topNames; } }
PropertiesExt { public static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments) { Map<String, Set<String>> topNames = new HashMap<>(); names.forEach(n -> { Pair<String, String> parts = split(n, rootSegments); if (parts == null) { topNames.put(n, null); } else { Set<String> nested = topNames.get(parts.getLeft()); if (nested == null) { nested = new HashSet<>(); topNames.put(parts.getLeft(), nested); } nested.add(parts.getRight()); } }); return topNames; } private  PropertiesExt(); }
PropertiesExt { public static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments) { Map<String, Set<String>> topNames = new HashMap<>(); names.forEach(n -> { Pair<String, String> parts = split(n, rootSegments); if (parts == null) { topNames.put(n, null); } else { Set<String> nested = topNames.get(parts.getLeft()); if (nested == null) { nested = new HashSet<>(); topNames.put(parts.getLeft(), nested); } nested.add(parts.getRight()); } }); return topNames; } private  PropertiesExt(); static Optional<Map<String, String>> loadFromClassPath(String resourceName); static Map<String, Map<String, String>> groupByRootName(Map<String, String> properties, int rootParts); static Map<String, String> getPropertiesOf(String namePrefix, Map<String, String> properties); static List<String> verifyRootNames(Map<String, String> properties, Set<String> expectedRootNames); static Set<String> getRootNames(Collection<String> names, int rootSegments); static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments); static Pair<String, String> split(String name, int rootParts); static PropertyNode<Boolean> fullSplit(Collection<String> names); }
PropertiesExt { public static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments) { Map<String, Set<String>> topNames = new HashMap<>(); names.forEach(n -> { Pair<String, String> parts = split(n, rootSegments); if (parts == null) { topNames.put(n, null); } else { Set<String> nested = topNames.get(parts.getLeft()); if (nested == null) { nested = new HashSet<>(); topNames.put(parts.getLeft(), nested); } nested.add(parts.getRight()); } }); return topNames; } private  PropertiesExt(); static Optional<Map<String, String>> loadFromClassPath(String resourceName); static Map<String, Map<String, String>> groupByRootName(Map<String, String> properties, int rootParts); static Map<String, String> getPropertiesOf(String namePrefix, Map<String, String> properties); static List<String> verifyRootNames(Map<String, String> properties, Set<String> expectedRootNames); static Set<String> getRootNames(Collection<String> names, int rootSegments); static Map<String, Set<String>> splitNames(Collection<String> names, int rootSegments); static Pair<String, String> split(String name, int rootParts); static PropertyNode<Boolean> fullSplit(Collection<String> names);  }