PathNodeParent { @Nullable final PathNode addChild(@NotNull List<String> segments, int index, char pathSeparator) { if (index < segments.size()) { String pathSegment = segments.get(index); String path = Joiner.on(pathSeparator).join(segments.subList(0, index + 1)); PathNode child = myChildrenByPathSegment.computeIfAbsent(pathSegment, s -> new PathNode(s, path, this)); child.addChild(segments, index + 1, pathSeparator); return child; } return null; }  @NotNull final Collection<PathNode> getChildren();  }
@Test public void addChild() { List<String> segments = Arrays.asList("one", "two", "three"); PathNode newChild = myParent.addChild(segments, 0, '/'); List<PathNode> children = new ArrayList<>(myParent.getChildren()); assertThat(children).hasSize(1); PathNode child = children.get(0); assertSame(child, newChild); assertEquals("one", child.getPathSegment()); assertEquals("one", child.getPath()); assertSame(myParent, child.getParent()); children = new ArrayList<>(child.getChildren()); assertThat(children).hasSize(1); child = children.get(0); assertEquals("two", child.getPathSegment()); assertEquals("one/two", child.getPath()); children = new ArrayList<>(child.getChildren()); assertThat(children).hasSize(1); child = children.get(0); assertEquals("three", child.getPathSegment()); assertEquals("one/two/three", child.getPath()); }