@Beta
public final class Path
extends java.lang.Object
FileSystemSupport
and MutableFileSystemSupport
.
A path either starts with a slash which denotes an absolute path or a segment which denotes a relative path.
Note that this is an abstraction over different 'real' file systems and doesn't understand platform specific things like, e.g.
"c:/" on windows.
The path segment separator is '/'.Modifier and Type | Field and Description |
---|---|
static Path |
ROOT
the root path
|
static char |
SEGMENT_SEPARATOR
the segment separator used.
|
Constructor and Description |
---|
Path(java.lang.String pathAsString)
Constructs a new Path object from a given string.
|
Modifier and Type | Method and Description |
---|---|
Path |
append(java.lang.String suffix)
Appends the given suffix to this path.
|
boolean |
equals(java.lang.Object obj) |
Path |
getAbsolutePath(Path relativePath) |
Path |
getAbsolutePath(java.lang.String relativePath) |
java.lang.String |
getFileExtension() |
java.lang.String |
getLastSegment() |
Path |
getParent()
Returns the parent of this path or null if this path is the root path.
|
java.util.List<java.lang.String> |
getSegments() |
int |
hashCode() |
boolean |
isAbsolute() |
Path |
relativize(Path other)
Constructs a relative path between this path and a given path.
|
Path |
relativize(java.lang.String other)
See
relativize(Path) |
boolean |
startsWith(Path other)
Returns whether this path starts with the same segments and
has the same
isAbsolute() value. |
java.lang.String |
toString() |
public static final char SEGMENT_SEPARATOR
public static final Path ROOT
public Path(java.lang.String pathAsString)
pathAsString
- public boolean isAbsolute()
public java.util.List<java.lang.String> getSegments()
public java.lang.String getLastSegment()
public Path append(java.lang.String suffix)
suffix
- the suffix to append to this pathpublic Path getParent()
public java.lang.String getFileExtension()
null
if this path's last segment doesn't have a file extension.public Path getAbsolutePath(java.lang.String relativePath)
relativePath
- public Path getAbsolutePath(Path relativePath)
relativePath
- public Path relativize(java.lang.String other)
relativize(Path)
other
- a string representing a pathpublic Path relativize(Path other)
Relativization is the inverse of resolution
.
This method attempts to construct a relative
path
that when resolved
against this path, yields a
path that locates the same file as the given path. For example, on UNIX,
if this path is "/a/b"
and the given path is "/a/b/c/d"
then the resulting relative path would be "c/d"
.
Both paths must be absolute and and either this path or the given path must be a
prefix
of the other.
other
- the path to relativize against this pathjava.lang.IllegalArgumentException
- if this path and other
are not both absolute or relativepublic boolean startsWith(Path other)
isAbsolute()
value.other
- the path, which might be a prefix of this pathpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object