code: public static String getAllButLastSegment(final List<PathSegment> segments) {
          if (segments.isEmpty()) {
              return "";
          }
          return segments.subList(0, segments.size() - 1).stream().map(PathSegment::getPath)
                      .collect(joining("/"));
      }
docs: From a list of segments, use all but the last item, joined in a String.
  @param segments the path segments
  @return the path