PropertiesExt { public static Map<String, String> getPropertiesOf(String namePrefix, Map<String, String> properties) { if (CollectionsExt.isNullOrEmpty(properties)) { return Collections.emptyMap(); } String namePrefixWithDot = namePrefix + '.'; Map<String, String> result = new HashMap<>(); for (Map.Entry<String, String> entry : properties.entrySet()) { String name = entry.getKey().trim(); if (name.isEmpty() || !name.startsWith(namePrefixWithDot)) { continue; } String internalName = name.substring(namePrefixWithDot.length()); result.put(internalName, entry.getValue()); } return result; } 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 testGetPropertiesOf() throws Exception { Map<String, String> properties = asMap( "root.my.a", "valueA", "root.my.b", "valueB", "your.x", "valueX" ); Map<String, String> subProps = PropertiesExt.getPropertiesOf("root.my", properties); assertThat(subProps).containsAllEntriesOf(asMap("a", "valueA", "b", "valueB")); }