PropertyCollapser extends AbstractPathCollapser implements StringCollapser { @Override public <T> Map<String, Collection<T>> collapse(Map<String, Collection<T>> input) { Map<PathName, Collection<T>> inputMap = new HashMap<PathName, Collection<T>>(input.size()); for (Map.Entry<String, Collection<T>> entry : input.entrySet()) { inputMap.put(new PathName(entry.getKey().split("\\."), null), entry.getValue()); } Map<PathName, Collection<T>> outputMap = collapsePaths(inputMap); Map<String, Collection<T>> output = new HashMap<String, Collection<T>>(outputMap.size()); for (Map.Entry<PathName, Collection<T>> entry : outputMap.entrySet()) { output.put(StringUtil.join(".", entry.getKey().getPathComponents()), entry.getValue()); } return output; } PropertyCollapser(int collapseThreshold); @Override Map<String, Collection<T>> collapse(Map<String, Collection<T>> input); boolean pathNameMatches(String matcher, String matchee);  }
@Test public void testPropertyPermissionCollapser() { List<String> props = Arrays.asList( "a.b.c.d", "a.b.c.e", "b.c.d.e", "b.c.d.f", "b.d.d.e", "b.d.d.f", "b.e.e.f", "c.d.e.f", "e.f.g.h", "e.f.g.g", "e.f.h.h", "e.f.h.i"); props = new ArrayList<String>(new PropertyCollapser(2).collapse(nullMap(props)).keySet()); Collections.sort(props); assertEquals(props, Arrays.asList( "a.b.c.*", "b.c.d.*", "b.d.d.*", "b.e.e.f", "c.d.e.f", "e.f.*")); }
@Test public void testCollapseToRoot() { Collection<String> props = new PropertyCollapser(2).collapse(nullMap(Arrays.asList( "a.b", "a.c", "b.b", "b.c"))).keySet(); assertEquals(props, Arrays.asList("*")); props = new PropertyCollapser(0).collapse(nullMap(Arrays.asList( "a.b", "*"))).keySet(); assertEquals(props, Arrays.asList("*")); props = new PropertyCollapser(0).collapse(nullMap(Arrays.asList( "*", "a.b"))).keySet(); assertEquals(props, Arrays.asList("*")); props = new PropertyCollapser(0).collapse(nullMap(Arrays.asList( "*", "*"))).keySet(); assertEquals(props, Arrays.asList("*")); }