@Test public void match() { String[] paths = new String[]{ "/a", "/a/b/", "/a/b/c", "/a/bc", }; Set<String> pathSet = new HashSet<>(); Collections.addAll(pathSet, paths); PrefixPathMatcher matcher = new PrefixPathMatcher(pathSet); checkNoMatch(matcher, "/"); checkNoMatch(matcher, "/ab"); checkNoMatch(matcher, "/b"); checkMatch(matcher, "/a", "/a"); checkMatch(matcher, "/a/", "/a"); checkMatch(matcher, "/a/bd", "/a"); checkMatch(matcher, "/a/b", "/a/b/", "/a"); checkMatch(matcher, "/a/b/", "/a/b/", "/a"); checkMatch(matcher, "/a/b/d", "/a/b/", "/a"); checkMatch(matcher, "/a/b/cd", "/a/b/", "/a"); checkMatch(matcher, "/a/b/c", "/a/b/c", "/a/b/", "/a"); checkMatch(matcher, "/a/b/c/d", "/a/b/c", "/a/b/", "/a"); checkMatch(matcher, "/a/bc", "/a/bc", "/a"); checkMatch(matcher, "/a/bc/d", "/a/bc", "/a"); }
@Override public Optional<List<String>> match(AlluxioURI path) { List<TrieNode> nodes = mTrie.search(path.getPath()); if (nodes.isEmpty()) { return Optional.empty(); } List<String> matchedPaths = new ArrayList<>(); for (int i = nodes.size() - 1; i >= 0; i--) { TrieNode node = nodes.get(i); if (mPaths.containsKey(node)) { matchedPaths.add(mPaths.get(node)); } } return Optional.of(matchedPaths); }
PrefixPathMatcher implements PathMatcher { @Override public Optional<List<String>> match(AlluxioURI path) { List<TrieNode> nodes = mTrie.search(path.getPath()); if (nodes.isEmpty()) { return Optional.empty(); } List<String> matchedPaths = new ArrayList<>(); for (int i = nodes.size() - 1; i >= 0; i--) { TrieNode node = nodes.get(i); if (mPaths.containsKey(node)) { matchedPaths.add(mPaths.get(node)); } } return Optional.of(matchedPaths); } }
PrefixPathMatcher implements PathMatcher { @Override public Optional<List<String>> match(AlluxioURI path) { List<TrieNode> nodes = mTrie.search(path.getPath()); if (nodes.isEmpty()) { return Optional.empty(); } List<String> matchedPaths = new ArrayList<>(); for (int i = nodes.size() - 1; i >= 0; i--) { TrieNode node = nodes.get(i); if (mPaths.containsKey(node)) { matchedPaths.add(mPaths.get(node)); } } return Optional.of(matchedPaths); } PrefixPathMatcher(Set<String> paths); }
PrefixPathMatcher implements PathMatcher { @Override public Optional<List<String>> match(AlluxioURI path) { List<TrieNode> nodes = mTrie.search(path.getPath()); if (nodes.isEmpty()) { return Optional.empty(); } List<String> matchedPaths = new ArrayList<>(); for (int i = nodes.size() - 1; i >= 0; i--) { TrieNode node = nodes.get(i); if (mPaths.containsKey(node)) { matchedPaths.add(mPaths.get(node)); } } return Optional.of(matchedPaths); } PrefixPathMatcher(Set<String> paths); @Override Optional<List<String>> match(AlluxioURI path); }
PrefixPathMatcher implements PathMatcher { @Override public Optional<List<String>> match(AlluxioURI path) { List<TrieNode> nodes = mTrie.search(path.getPath()); if (nodes.isEmpty()) { return Optional.empty(); } List<String> matchedPaths = new ArrayList<>(); for (int i = nodes.size() - 1; i >= 0; i--) { TrieNode node = nodes.get(i); if (mPaths.containsKey(node)) { matchedPaths.add(mPaths.get(node)); } } return Optional.of(matchedPaths); } PrefixPathMatcher(Set<String> paths); @Override Optional<List<String>> match(AlluxioURI path);  }