java.lang.Object
org.eclipse.xtend.lib.macro.file.Path

@Beta public final class Path extends Object
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 Details

    • SEGMENT_SEPARATOR

      public static final char SEGMENT_SEPARATOR
      the segment separator used.
      See Also:
    • ROOT

      public static final Path ROOT
      the root path
  • Constructor Details

    • Path

      public Path(String pathAsString)
      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

      public List<String> getSegments()
      Returns:
      the segments
    • getLastSegment

      public String getLastSegment()
      Returns:
      the trailing segment, i.e. the simple name of the underlying element.
    • append

      public Path append(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 String getFileExtension()
      Returns:
      the file extension or null if this path's last segment doesn't have a file extension.
    • getAbsolutePath

      public Path getAbsolutePath(String relativePath)
      Parameters:
      relativePath -
      Returns:
      the absolute path
    • getAbsolutePath

      public Path getAbsolutePath(Path relativePath)
      Parameters:
      relativePath -
      Returns:
      the absolute path
    • relativize

      public Path relativize(String other)
      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 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.

      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 and other are not both absolute or relative
    • startsWith

      public boolean startsWith(Path other)
      Returns whether this path starts with the same segments and has the same isAbsolute() 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:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object