public String getSegmentOrEmptyString(int i) { return i > 0 && i < size() ? segments.get(i) : ""; }
/** * gives an {@link URLPath}, which contains all elements starting from the * given index. * * @param start of the first element (including) {@link URLPath} * @return the {@link URLPath} with the sub elements */ public URLPath getSubPath(int start) { return getSubPath(start, size()); }
/** * checks, if this {@link URLPath} ends with a slash * * @return {@code true} if it contains a trailing slash, otherwise * {@code false} */ public boolean hasTrailingSlash() { if (isEmpty()) { return false; } return getSegment(size() - 1).isEmpty(); }
/** * 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); }