@Test public void failWhenIdenticalPathsConfiguredInRootWithStar() { PathTrie<Integer> pathTrie = new PathTrie<>(); pathTrie.put("/", 1); assertThrows(DuplicatePathException.class, () -> pathTrie.put("/*", 2)); }
public void put(String path, T value) { checkNotEmpty(path); requireNonNull(value); List<String> components = pathToComponents(Paths.get(removeAsterisk(path))); if (path.endsWith("/") || path.endsWith("/*")) { components.add("/"); } T existing = tree.getExactMatch(components); if (existing != null) { String message = format("Path '%s' has already been configured with a ID of [%s]", path, existing.toString()); throw new DuplicatePathException(message); } tree.addValueWithParents(components, value); }
PathTrie { public void put(String path, T value) { checkNotEmpty(path); requireNonNull(value); List<String> components = pathToComponents(Paths.get(removeAsterisk(path))); if (path.endsWith("/") || path.endsWith("/*")) { components.add("/"); } T existing = tree.getExactMatch(components); if (existing != null) { String message = format("Path '%s' has already been configured with a ID of [%s]", path, existing.toString()); throw new DuplicatePathException(message); } tree.addValueWithParents(components, value); } }
PathTrie { public void put(String path, T value) { checkNotEmpty(path); requireNonNull(value); List<String> components = pathToComponents(Paths.get(removeAsterisk(path))); if (path.endsWith("/") || path.endsWith("/*")) { components.add("/"); } T existing = tree.getExactMatch(components); if (existing != null) { String message = format("Path '%s' has already been configured with a ID of [%s]", path, existing.toString()); throw new DuplicatePathException(message); } tree.addValueWithParents(components, value); } PathTrie(); }
PathTrie { public void put(String path, T value) { checkNotEmpty(path); requireNonNull(value); List<String> components = pathToComponents(Paths.get(removeAsterisk(path))); if (path.endsWith("/") || path.endsWith("/*")) { components.add("/"); } T existing = tree.getExactMatch(components); if (existing != null) { String message = format("Path '%s' has already been configured with a ID of [%s]", path, existing.toString()); throw new DuplicatePathException(message); } tree.addValueWithParents(components, value); } PathTrie(); void put(String path, T value); Optional<T> get(String path); T remove(String path); void printContent(); }
PathTrie { public void put(String path, T value) { checkNotEmpty(path); requireNonNull(value); List<String> components = pathToComponents(Paths.get(removeAsterisk(path))); if (path.endsWith("/") || path.endsWith("/*")) { components.add("/"); } T existing = tree.getExactMatch(components); if (existing != null) { String message = format("Path '%s' has already been configured with a ID of [%s]", path, existing.toString()); throw new DuplicatePathException(message); } tree.addValueWithParents(components, value); } PathTrie(); void put(String path, T value); Optional<T> get(String path); T remove(String path); void printContent();  }