private static void copySegments(String[] target, String[] source) { copySegments(target, source, target.length); }
/** * Returns the parent of this path. * * @return The parent of this path, or null if this is the root path. */ public RelativePath getParent() { switch (segments.length) { case 0: return null; case 1: return EMPTY_ROOT; default: String[] parentSegments = new String[segments.length - 1]; copySegments(parentSegments, segments); return new RelativePath(false, parentSegments); } }
/** * <p>Returns a copy of this path, with the last name replaced with the given name.</p> * * @param name The name. * @return The path. */ public RelativePath replaceLastName(String name) { String[] newSegments = new String[segments.length]; copySegments(newSegments, segments, segments.length - 1); newSegments[segments.length - 1] = internPathSegment(name); return new RelativePath(endsWithFile, newSegments); }
private RelativePath(boolean endsWithFile, RelativePath parentPath, String... childSegments) { this.endsWithFile = endsWithFile; int targetOffsetForChildSegments; if (parentPath != null) { String[] sourceSegments = parentPath.getSegments(); segments = new String[sourceSegments.length + childSegments.length]; copySegments(segments, sourceSegments, sourceSegments.length); targetOffsetForChildSegments = sourceSegments.length; } else { segments = new String[childSegments.length]; targetOffsetForChildSegments = 0; } copyAndInternSegments(segments, targetOffsetForChildSegments, childSegments); }