PropertiesExt { public static PropertyNode<Boolean> fullSplit(Collection<String> names) { PropertyNode<Boolean> root = new PropertyNode<>("ROOT", Optional.empty(), new HashMap<>()); names.forEach(n -> { List<String> parts = StringExt.splitByDot(n); PropertyNode<Boolean> current = root; int lastIdx = parts.size() - 1; for (int i = 0; i < parts.size(); i++) { String name = parts.get(i); PropertyNode<Boolean> next = current.getChildren().get(name); if (next == null) { next = new PropertyNode<>(name, Optional.empty(), new HashMap<>()); current.getChildren().put(name, next); } if (i == lastIdx) { next.value = Optional.of(Boolean.TRUE); } current = next; } }); return root; } 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);  }
@Test public void testFullSplit() throws Exception { PropertiesExt.PropertyNode<Boolean> result = PropertiesExt.fullSplit(asList("top1", "top2.nested2")); assertThat(result.getChildren()).containsKeys("top1", "top2"); assertThat(result.getChildren().get("top1").getValue()).contains(true); assertThat(result.getChildren().get("top2").getValue()).isEmpty(); assertThat(result.getChildren().get("top2").getChildren()).containsKeys("nested2"); assertThat(result.getChildren().get("top2").getChildren().get("nested2").getValue()).contains(true); }