java.lang.Object
org.eclipse.xtend.lib.macro.file.Path
A path points to some file or folder within a
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 '/'.- Author:
- Sven Efftinge
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Paththe root pathstatic final charthe segment separator used. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the given suffix to this path.booleangetAbsolutePath(String relativePath) getAbsolutePath(Path relativePath) Returns the parent of this path or null if this path is the root path.inthashCode()booleanrelativize(String other) Seerelativize(Path)relativize(Path other) Constructs a relative path between this path and a given path.booleanstartsWith(Path other) Returns whether this path starts with the same segments and has the sameisAbsolute()value.toString()
-
Field Details
-
SEGMENT_SEPARATOR
public static final char SEGMENT_SEPARATORthe segment separator used.- See Also:
-
ROOT
the root path
-
-
Constructor Details
-
Path
Constructs a new Path object from a given string. the used file separator is '/' and a leading one indicates an absolute path.- Parameters:
pathAsString-
-
-
Method Details
-
isAbsolute
public boolean isAbsolute()- Returns:
- whether this is an absolute path
-
getSegments
- Returns:
- the segments
-
getLastSegment
- Returns:
- the trailing segment, i.e. the simple name of the underlying element.
-
append
Appends the given suffix to this path.- Parameters:
suffix- the suffix to append to this path- Returns:
- a new Path with the given suffix appended to this path's segments.
-
getParent
Returns the parent of this path or null if this path is the root path.- Returns:
- the parent of this path or null if this path is the root path.
-
getFileExtension
- Returns:
- the file extension or
nullif this path's last segment doesn't have a file extension.
-
getAbsolutePath
- Parameters:
relativePath-- Returns:
- the absolute path
-
getAbsolutePath
- Parameters:
relativePath-- Returns:
- the absolute path
-
relativize
Seerelativize(Path)- Parameters:
other- a string representing a path- Returns:
- the resulting relative path or null if neither of the given paths is a prefix of the other
-
relativize
Constructs a relative path between this path and a given path.Relativization is the inverse of
resolution. This method attempts to construct arelativepath that whenresolvedagainst 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 aprefixof the other.- Parameters:
other- the path to relativize against this path- Returns:
- the resulting relative path or null if neither of the given paths is a prefix of the other
- Throws:
IllegalArgumentException- if this path andotherare not both absolute or relative
-
startsWith
Returns whether this path starts with the same segments and has the sameisAbsolute()value.- Parameters:
other- the path, which might be a prefix of this path- Returns:
- whether the given path is a prefix of this path
-
hashCode
public int hashCode() -
equals
-
toString
-