Path implements Comparable, Serializable, ObjectInputValidation { public Path getParent() { String path = uri.getPath(); int lastSlash = path.lastIndexOf('/'); int start = startPositionWithoutWindowsDrive(path); if ((path.length() == start) || (lastSlash == start && path.length() == start+1)) { return null; } String parent; if (lastSlash==-1) { parent = CUR_DIR; } else { parent = path.substring(0, lastSlash==start?start+1:lastSlash); } return new Path(uri.getScheme(), uri.getAuthority(), parent); } Path(String parent, String child);  Path(Path parent, String child);  Path(String parent, Path child);  Path(Path parent, Path child);  Path(String pathString);  Path(URI aUri);  Path(String scheme, String authority, String path); static Path getPathWithoutSchemeAndAuthority(Path path); static Path mergePaths(Path path1, Path path2); static boolean isWindowsAbsolutePath(final String pathString,
                                              final boolean slashed); URI toUri(); FileSystem getFileSystem(Configuration conf); boolean isAbsoluteAndSchemeAuthorityNull(); boolean isUriPathAbsolute(); boolean isAbsolute(); boolean isRoot(); String getName(); Path getParent(); Path suffix(String suffix); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(Object o); int depth(); @Deprecated Path makeQualified(FileSystem fs); @InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"}) Path makeQualified(URI defaultUri, Path workingDir ); @Override void validateObject(); void setScheme(String scheme); static final String SEPARATOR; static final char SEPARATOR_CHAR; static final String CUR_DIR; static final boolean WINDOWS; }
@Test (timeout = 30000) public void testParent() { assertEquals(new Path("/foo"), new Path("/foo/bar").getParent()); assertEquals(new Path("foo"), new Path("foo/bar").getParent()); assertEquals(new Path("/"), new Path("/foo").getParent()); assertEquals(null, new Path("/").getParent()); if (Path.WINDOWS) { assertEquals(new Path("c:/"), new Path("c:/foo").getParent()); } }