class 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;
  }

}