GlobPattern implements RestrictionPattern { static GlobPattern create(@NotNull String nodePath, @NotNull String restrictions) { return new GlobPattern(nodePath, restrictions); } private  GlobPattern(@NotNull String path, @NotNull String restriction); @Override boolean matches(@NotNull Tree tree, @Nullable PropertyState property); @Override boolean matches(@NotNull String path); @Override boolean matches(); @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj);  }
@Test public void testMatchesWildcardAll() { Map<String,Boolean> tests = new HashMap<>(); GlobPattern gp = GlobPattern.create("/a/b/c", "*"); tests.put("/a/b/c", true); tests.put("/a/b/c/d", true); tests.put("/a/b/c/d/e", true); tests.put("/a/b/c/d/e/f", true); tests.put("/a/b/cde", true); tests.put("/a/b/cde/e/f", true); tests.put("/", false); tests.put("/a", false); tests.put("/b/c", false); for (String testPath : tests.keySet()) { assertMatch(gp, testPath, tests.get(testPath)); } gp = GlobPattern.create("/a/b/c", "*e"); tests = new HashMap<>(); tests.put("/a/b/c/e", true); tests.put("/a/b/c/d/e", true); tests.put("/a/b/c/gge", true); tests.put("/a/b/c/d/gge", true); tests.put("/a/b/ce", true); tests.put("/a/b/chee", true); tests.put("/a/b/cd/e", true); tests.put("/a/b/cd/f/e", true); tests.put("/a/b/cd/name", true); tests.put("/a/b/cd/f/name", true); tests.put("/", false); tests.put("/a", false); tests.put("/b/c", false); tests.put("/a/b/c", false); tests.put("/a/b/c/d", false); tests.put("/a/b/c/d/e/f", false); tests.put("/a/b/c/d/f/e/f", false); tests.put("/a/b/c/d/f/efg", false); tests.put("/a/b/c/d/f/f", false); tests.put("/a/b/c/e/f", false); tests.put("/a/b/ce/", false); tests.put("/a/b/ceg", false); for (String testPath : tests.keySet()) { assertMatch(gp, testPath, tests.get(testPath)); } gp = GlobPattern.create("/a/b/c", "*/e"); tests = new HashMap<>(); tests.put("/a/b/c/e", true); tests.put("/a/b/c/d/e", true); tests.put("/a/b/cd/e", true); tests.put("/a/b/cd/f/e", true); tests.put("/", false); tests.put("/a", false); tests.put("/b/c", false); tests.put("/a/b/c", false); tests.put("/a/b/c/d", false); tests.put("/a/b/c/d/e/f", false); tests.put("/a/b/c/d/f/e/f", false); tests.put("/a/b/c/d/f/efg", false); tests.put("/a/b/c/d/f/f", false); tests.put("/a/b/c/e/f", false); tests.put("/a/b/ce/", false); for (String testPath : tests.keySet()) { assertMatch(gp, testPath, tests.get(testPath)); } gp = GlobPattern.create("/a/b/c/e", "*"); tests = new HashMap<>(); tests.put("/a/b/c/e/f/g/h", true); tests.put("/a/b/c/e/d/e/f", true); tests.put("/a/b/c/e/d/e/g", true); tests.put("/a/b/c/e", true); tests.put("/a/b/c/e/", true); tests.put("/a/b/c/ef", true); tests.put("/a/b/c/ef/g", true); tests.put("/a/b/ce/f/g/h", false); tests.put("/a/b/ce/d/e/f", false); tests.put("/a/b/c", false); tests.put("/a/b/c/d", false); tests.put("/a/b/c/d/e/f", false); tests.put("/a/b/c/d/f/f", false); tests.put("/a/b/c/d/f/e/f", false); tests.put("/a/b/cee/d/e/f", false); for (String testPath : tests.keySet()) { assertMatch(gp, testPath, tests.get(testPath)); } gp = GlobPattern.create("/a/b/c/e", "cat matches all non-direct descendants of /foo named "cat" gp = GlobPattern.create("/a/b/c", "/*/cat"); tests = new HashMap<>(); tests.put("/a/b/c/a/cat", true); tests.put("/a/b/c/d/e/f/cat", true); tests.put("/a/b/c/cat", false); tests.put("/a/b/c/cate", false); tests.put("/a/b/c/acat", false); tests.put("/a/b/c/cat/d", false); tests.put("/a/b/c/d/acat", false); tests.put("/a/b/c/d/cate", false); tests.put("/a/b/c/d/cat/e", false); tests.put("/a/b/c/d/acat/e", false); tests.put("/a/b/c/d/cata/e", false); tests.put("/a/b/cat", false); tests.put("/a/b/cat/ed/f/f", false); tests.put("/a/b/ced/cat", false); tests.put("/a/b/ced/f/cat", false); for (String testPath : tests.keySet()) { assertMatch(gp, testPath, tests.get(testPath)); } gp = GlobPattern.create("/a/b/c", "/cat*"); tests = new HashMap<>(); tests.put("/a/b/c/cat", true); tests.put("/a/b/c/cats", true); tests.put("/a/b/c/cat/s", true); tests.put("/a/b/c/cats/d/e/f", true); tests.put("/a/b/c/d/cat", false); tests.put("/a/b/c/d/cats", false); tests.put("/a/b/c/d/e/cat", false); tests.put("/a/b/c/d/e/cats", false); tests.put("/a/b/c/acat", false); tests.put("/a/b/c/d/acat", false); tests.put("/a/b/c/d/cat/e", false); tests.put("/a/b/c/d/acat/e", false); tests.put("/a/b/c/d/cata/e", false); tests.put("/a/b/cat", false); tests.put("/a/b/cat/ed/f/f", false); tests.put("/a/b/ced/cat", false); tests.put("/a/b/ced/f/cat", false); for (String testPath : tests.keySet()) { assertMatch(gp, testPath, tests.get(testPath)); } }
@Test public void testNotEquals() { GlobPattern pattern = GlobPattern.create("/a/b/c/d", "/*"); assertNotEquals(pattern, GlobPattern.create("/a/b/c", "/*")); assertNotEquals(pattern, GlobPattern.create("/a/b/c/d", "*")); assertNotEquals(pattern, new PrefixPattern(ImmutableSet.of("/a/b/c", "/*"))); }