/** * gives a {@link URLPath} with a trailing slash * * @return a new created {@link URLPath}, which have all elements, with a * trailing slash */ public URLPath appendTrailingSlash() { if (hasTrailingSlash()) { return this; } return append(ROOT); }
/** * gives a {@link URLPath} without a trailing slash * * @return a new created {@link URLPath}, which have all elements, without a * trailing slash */ public URLPath removeTrailingSlash() { if (!hasTrailingSlash()) { return this; } return getSubPath(0, size() - 1); }
/** * constructs the string representation of the path. * * @return a string. */ public String asString() { if (size() == 1 && hasTrailingSlash()) { // special case if only one part, then join will not append the delimter. return PATH_DELIMITER; } return StringUtils.join(segments, PATH_DELIMITER); }