@Test public void testAppend() { Path path1 = new Path("/a/b/c"); Path path2 = new Path("/d/e/f"); Path path3 = new Path("/a/b/c/d/e/f"); assertEquals(path1.append(path2), path3); }
public Path append(Path tail) { if (tail == null || tail.segmentCount() == 0) { return this; } if (isEmpty()) { return tail.makeRelative(); } if (isRoot()) { return tail.makeAbsolute(); } int myLen = segments.length; int tailLen = tail.segmentCount(); String[] newSegments = new String[myLen + tailLen]; System.arraycopy(segments, 0, newSegments, 0, myLen); for (int i = 0; i < tailLen; i++) { newSegments[myLen + i] = tail.segment(i); } Path result = new Path(newSegments, (separators & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0)); String tailFirstSegment = newSegments[myLen]; if (tailFirstSegment.equals("..") || tailFirstSegment.equals(".")) { result.canonicalize(); } return result; }
Path implements Serializable { public Path append(Path tail) { if (tail == null || tail.segmentCount() == 0) { return this; } if (isEmpty()) { return tail.makeRelative(); } if (isRoot()) { return tail.makeAbsolute(); } int myLen = segments.length; int tailLen = tail.segmentCount(); String[] newSegments = new String[myLen + tailLen]; System.arraycopy(segments, 0, newSegments, 0, myLen); for (int i = 0; i < tailLen; i++) { newSegments[myLen + i] = tail.segment(i); } Path result = new Path(newSegments, (separators & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0)); String tailFirstSegment = newSegments[myLen]; if (tailFirstSegment.equals("..") || tailFirstSegment.equals(".")) { result.canonicalize(); } return result; } }
Path implements Serializable { public Path append(Path tail) { if (tail == null || tail.segmentCount() == 0) { return this; } if (isEmpty()) { return tail.makeRelative(); } if (isRoot()) { return tail.makeAbsolute(); } int myLen = segments.length; int tailLen = tail.segmentCount(); String[] newSegments = new String[myLen + tailLen]; System.arraycopy(segments, 0, newSegments, 0, myLen); for (int i = 0; i < tailLen; i++) { newSegments[myLen + i] = tail.segment(i); } Path result = new Path(newSegments, (separators & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0)); String tailFirstSegment = newSegments[myLen]; if (tailFirstSegment.equals("..") || tailFirstSegment.equals(".")) { result.canonicalize(); } return result; } Path(String fullPath); private  Path(String[] segments, int separators); }
Path implements Serializable { public Path append(Path tail) { if (tail == null || tail.segmentCount() == 0) { return this; } if (isEmpty()) { return tail.makeRelative(); } if (isRoot()) { return tail.makeAbsolute(); } int myLen = segments.length; int tailLen = tail.segmentCount(); String[] newSegments = new String[myLen + tailLen]; System.arraycopy(segments, 0, newSegments, 0, myLen); for (int i = 0; i < tailLen; i++) { newSegments[myLen + i] = tail.segment(i); } Path result = new Path(newSegments, (separators & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0)); String tailFirstSegment = newSegments[myLen]; if (tailFirstSegment.equals("..") || tailFirstSegment.equals(".")) { result.canonicalize(); } return result; } Path(String fullPath); private  Path(String[] segments, int separators); static Path createFromAbsolutePath(String path); static Path createFromSegments(String[] segments); Path addFileExtension(String extension); Path addTrailingSeparator(); Path append(Path tail); Path append(String tail); @Override boolean equals(Object obj); @Override int hashCode(); String getFileExtension(); boolean hasTrailingSeparator(); boolean isAbsolute(); boolean isEmpty(); boolean isPrefixOf(Path anotherPath); boolean isRoot(); static boolean isValidPath(String path); String lastSegment(); Path makeAbsolute(); Path makeRelative(); int matchingFirstSegments(Path anotherPath); Path removeFileExtension(); Path removeFirstSegments(int count); Path removeLastSegments(final int count); Path removeTrailingSeparator(); String segment(int index); int segmentCount(); String[] segments(); @Override String toString(); Path uptoSegment(final int count); static String getFileNameFromPath(String iconPath); }
Path implements Serializable { public Path append(Path tail) { if (tail == null || tail.segmentCount() == 0) { return this; } if (isEmpty()) { return tail.makeRelative(); } if (isRoot()) { return tail.makeAbsolute(); } int myLen = segments.length; int tailLen = tail.segmentCount(); String[] newSegments = new String[myLen + tailLen]; System.arraycopy(segments, 0, newSegments, 0, myLen); for (int i = 0; i < tailLen; i++) { newSegments[myLen + i] = tail.segment(i); } Path result = new Path(newSegments, (separators & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0)); String tailFirstSegment = newSegments[myLen]; if (tailFirstSegment.equals("..") || tailFirstSegment.equals(".")) { result.canonicalize(); } return result; } Path(String fullPath); private  Path(String[] segments, int separators); static Path createFromAbsolutePath(String path); static Path createFromSegments(String[] segments); Path addFileExtension(String extension); Path addTrailingSeparator(); Path append(Path tail); Path append(String tail); @Override boolean equals(Object obj); @Override int hashCode(); String getFileExtension(); boolean hasTrailingSeparator(); boolean isAbsolute(); boolean isEmpty(); boolean isPrefixOf(Path anotherPath); boolean isRoot(); static boolean isValidPath(String path); String lastSegment(); Path makeAbsolute(); Path makeRelative(); int matchingFirstSegments(Path anotherPath); Path removeFileExtension(); Path removeFirstSegments(int count); Path removeLastSegments(final int count); Path removeTrailingSeparator(); String segment(int index); int segmentCount(); String[] segments(); @Override String toString(); Path uptoSegment(final int count); static String getFileNameFromPath(String iconPath);  }