Class Path


  • @Beta
    public final class Path
    extends java.lang.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 '/'.
    • 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
    • Constructor Detail

      • Path

        public Path​(java.lang.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 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 null if 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)
        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:
        java.lang.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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object