public static URLPath fromString(String... parts) { URLPath path = new URLPath(parts); if (path.isRoot()) { return ROOT; } return path; }
/** * Appends the given url path to this path. */ public URLPath append(URLPath toAppend) { if (toAppend == null || toAppend.isEmpty()) { return this; } if (this.isEmpty()) { return toAppend; } if (this.isRoot() && toAppend.isRoot()) { return ROOT; } ArrayList newParts = new ArrayList(removeTrailingSlash().segments); newParts.addAll(toAppend.segments); return new URLPath(newParts); }
/** * gives an {@link URLPath}, which contains all elements in the given range. * * @param start index (including) * @param end index (excluding) * @return the {@link URLPath} with the sub elements */ public URLPath getSubPath(int start, int end) { List<String> parts = getSegments(); List<String> newSegments = parts.subList(start, end); URLPath newPath = new URLPath(newSegments); if (newPath.isEmpty()) { return EMPTY; } if (newPath.isRoot()) { return ROOT; } return newPath; }