@Test public void testGetPathElements() { List<String> as2 = HMSPaths.getPathElements(new String("/a/b")); List<String> as1 = HMSPaths.getPathElements(new String("/a/b")); Assert.assertEquals(as1, as2); List<String> as = HMSPaths.getPathElements(new String("/a/b")); Assert.assertEquals(Lists.newArrayList("a", "b"), as); as = HMSPaths.getPathElements(new String(" Assert.assertEquals(Lists.newArrayList("a", "b"), as); as = HMSPaths.getPathElements(new String("/a Assert.assertEquals(Lists.newArrayList("a", "b"), as); as = HMSPaths.getPathElements(new String("/a/b/")); Assert.assertEquals(Lists.newArrayList("a", "b"), as); as = HMSPaths.getPathElements(new String(" Assert.assertEquals(Lists.newArrayList("a", "b"), as); }
@VisibleForTesting static List<String> getPathElements(String path) { path = path.trim(); if (path.charAt(0) != Path.SEPARATOR_CHAR) { throw new IllegalArgumentException("It must be an absolute path: " + path); } List<String> list = new ArrayList<String>(32); int idx = 0; int found = path.indexOf(Path.SEPARATOR_CHAR, idx); while (found > -1) { if (found > idx) { list.add(path.substring(idx, found)); } idx = found + 1; found = path.indexOf(Path.SEPARATOR_CHAR, idx); } if (idx < path.length()) { list.add(path.substring(idx)); } return list; }
HMSPaths implements AuthzPaths { @VisibleForTesting static List<String> getPathElements(String path) { path = path.trim(); if (path.charAt(0) != Path.SEPARATOR_CHAR) { throw new IllegalArgumentException("It must be an absolute path: " + path); } List<String> list = new ArrayList<String>(32); int idx = 0; int found = path.indexOf(Path.SEPARATOR_CHAR, idx); while (found > -1) { if (found > idx) { list.add(path.substring(idx, found)); } idx = found + 1; found = path.indexOf(Path.SEPARATOR_CHAR, idx); } if (idx < path.length()) { list.add(path.substring(idx)); } return list; } }
HMSPaths implements AuthzPaths { @VisibleForTesting static List<String> getPathElements(String path) { path = path.trim(); if (path.charAt(0) != Path.SEPARATOR_CHAR) { throw new IllegalArgumentException("It must be an absolute path: " + path); } List<String> list = new ArrayList<String>(32); int idx = 0; int found = path.indexOf(Path.SEPARATOR_CHAR, idx); while (found > -1) { if (found > idx) { list.add(path.substring(idx, found)); } idx = found + 1; found = path.indexOf(Path.SEPARATOR_CHAR, idx); } if (idx < path.length()) { list.add(path.substring(idx)); } return list; } HMSPaths(String[] pathPrefixes); }
HMSPaths implements AuthzPaths { @VisibleForTesting static List<String> getPathElements(String path) { path = path.trim(); if (path.charAt(0) != Path.SEPARATOR_CHAR) { throw new IllegalArgumentException("It must be an absolute path: " + path); } List<String> list = new ArrayList<String>(32); int idx = 0; int found = path.indexOf(Path.SEPARATOR_CHAR, idx); while (found > -1) { if (found > idx) { list.add(path.substring(idx, found)); } idx = found + 1; found = path.indexOf(Path.SEPARATOR_CHAR, idx); } if (idx < path.length()) { list.add(path.substring(idx)); } return list; } HMSPaths(String[] pathPrefixes); @Override Set<String> findAuthzObject(String[] pathElements); @Override Set<String> findAuthzObjectExactMatches(String[] pathElements); Set<String> findAuthzObject(String[] pathElements, boolean isPartialOk); @Override boolean isUnderPrefix(String[] pathElements); @Override HMSPathsDumper getPathsDump(); }
HMSPaths implements AuthzPaths { @VisibleForTesting static List<String> getPathElements(String path) { path = path.trim(); if (path.charAt(0) != Path.SEPARATOR_CHAR) { throw new IllegalArgumentException("It must be an absolute path: " + path); } List<String> list = new ArrayList<String>(32); int idx = 0; int found = path.indexOf(Path.SEPARATOR_CHAR, idx); while (found > -1) { if (found > idx) { list.add(path.substring(idx, found)); } idx = found + 1; found = path.indexOf(Path.SEPARATOR_CHAR, idx); } if (idx < path.length()) { list.add(path.substring(idx)); } return list; } HMSPaths(String[] pathPrefixes); @Override Set<String> findAuthzObject(String[] pathElements); @Override Set<String> findAuthzObjectExactMatches(String[] pathElements); Set<String> findAuthzObject(String[] pathElements, boolean isPartialOk); @Override boolean isUnderPrefix(String[] pathElements); @Override HMSPathsDumper getPathsDump();  }