Package org.eclipse.xtend.lib.macro.file
Class Path
- java.lang.Object
-
- org.eclipse.xtend.lib.macro.file.Path
-
@Beta public final class Path extends java.lang.ObjectA path points to some file or folder within aFileSystemSupportandMutableFileSystemSupport. 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 '/'.
-
-
Field Summary
Fields Modifier and Type Field Description static PathROOTthe root pathstatic charSEGMENT_SEPARATORthe segment separator used.
-
Constructor Summary
Constructors Constructor Description Path(java.lang.String pathAsString)Constructs a new Path object from a given string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pathappend(java.lang.String suffix)Appends the given suffix to this path.booleanequals(java.lang.Object obj)PathgetAbsolutePath(java.lang.String relativePath)PathgetAbsolutePath(Path relativePath)java.lang.StringgetFileExtension()java.lang.StringgetLastSegment()PathgetParent()Returns the parent of this path or null if this path is the root path.java.util.List<java.lang.String>getSegments()inthashCode()booleanisAbsolute()Pathrelativize(java.lang.String other)Seerelativize(Path)Pathrelativize(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.java.lang.StringtoString()
-
-
-
Field Detail
-
SEGMENT_SEPARATOR
public static final char SEGMENT_SEPARATOR
the segment separator used.- See Also:
- Constant Field Values
-
ROOT
public static final Path ROOT
the root path
-
-
Method Detail
-
isAbsolute
public boolean isAbsolute()
- Returns:
- whether this is an absolute path
-
getSegments
public java.util.List<java.lang.String> getSegments()
- Returns:
- the segments
-
getLastSegment
public java.lang.String getLastSegment()
- Returns:
- the trailing segment, i.e. the simple name of the underlying element.
-
append
public Path append(java.lang.String suffix)
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
public Path 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
public java.lang.String getFileExtension()
- Returns:
- the file extension or
nullif this path's last segment doesn't have a file extension.
-
getAbsolutePath
public Path getAbsolutePath(java.lang.String relativePath)
- Parameters:
relativePath-- Returns:
- the absolute path
-
getAbsolutePath
public Path getAbsolutePath(Path relativePath)
- Parameters:
relativePath-- Returns:
- the absolute path
-
relativize
public Path relativize(java.lang.String other)
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
public Path relativize(Path other)
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:
java.lang.IllegalArgumentException- if this path andotherare not both absolute or relative
-
startsWith
public boolean startsWith(Path other)
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()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-