Class FsFile

  • All Implemented Interfaces:
    java.lang.Comparable<FsFile>

    public class FsFile
    extends java.lang.Object
    implements java.lang.Comparable<FsFile>
    An analog of File representing an FS repository file-path. The file-path is relative to the root of the repository. As with File, instances of this class are immutable.
    Since:
    5.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static FsFile emptyPath
      the FsFile that has no path components
      static char separatorChar
      the separator character for delimiting repository path components
    • Constructor Summary

      Constructors 
      Constructor Description
      FsFile​(java.io.File file)
      Construct an instance.
      FsFile​(java.lang.String path)
      Construct an instance.
      FsFile​(java.lang.String... components)
      Construct an instance.
      FsFile​(java.nio.file.Path path)
      Construct an instance.
      FsFile​(java.util.Collection<java.lang.String> components)
      Construct an instance.
      FsFile​(FsFile file, int maxComponentCount)
      Construct an instance by trimming parent directories from an existing instance such that the depth does not exceed the given maximum.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(FsFile other)  
      static FsFile concatenate​(FsFile... files)
      Concatenate paths.
      boolean equals​(java.lang.Object object)
      Instances are equal if their string representations match.
      java.util.List<java.lang.String> getComponents()
      Get the path components of this instance.
      FsFile getPathFrom​(FsFile file)
      Find the relative path of this path from a given parent.
      int hashCode()
      java.io.File toFile​(java.io.File file)
      Convert this instance to a File relative to the given File.
      java.nio.file.Path toPath​(java.nio.file.Path path)
      Convert this instance to a Path relative to the given Path.
      java.lang.String toString()
      Provides repository path with components separated by separatorChar.
      FsFile transform​(java.util.function.Function<java.lang.String,​java.lang.String> componentTransformer)
      Transform each path component with the given transformer.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • separatorChar

        public static char separatorChar
        the separator character for delimiting repository path components
      • emptyPath

        public static FsFile emptyPath
        the FsFile that has no path components
    • Constructor Detail

      • FsFile

        public FsFile​(java.util.Collection<java.lang.String> components)
        Construct an instance.
        Parameters:
        components - the components of the path to which this instance corresponds, may be null
      • FsFile

        public FsFile​(java.lang.String... components)
        Construct an instance.
        Parameters:
        components - the components of the path to which this instance corresponds
      • FsFile

        public FsFile​(FsFile file,
                      int maxComponentCount)
        Construct an instance by trimming parent directories from an existing instance such that the depth does not exceed the given maximum. Allows ignoring of client-side parent directories beyond those specified by the user.
        Parameters:
        file - an existing instance
        maxComponentCount - the number of child components of the instance, including filename, above which parents should be ignored
      • FsFile

        public FsFile​(java.io.File file)
        Construct an instance.
        Parameters:
        file - the file to whose absolute path this instance corresponds
      • FsFile

        public FsFile​(java.nio.file.Path path)
        Construct an instance.
        Parameters:
        path - the path to whose absolute path this instance corresponds
      • FsFile

        public FsFile​(java.lang.String path)
        Construct an instance.
        Parameters:
        path - the path that this instance's string representation must match
    • Method Detail

      • transform

        public FsFile transform​(java.util.function.Function<java.lang.String,​java.lang.String> componentTransformer)
        Transform each path component with the given transformer.
        Parameters:
        componentTransformer - a transformer
        Returns:
        the transformed path
      • getPathFrom

        public FsFile getPathFrom​(FsFile file)
        Find the relative path of this path from a given parent. Allows adjustment of absolute paths to the repository's root directory. Matches path component names case-sensitively.
        Parameters:
        file - a parent path (may be the same as this one)
        Returns:
        the relative path, or null if none exists
      • concatenate

        public static FsFile concatenate​(FsFile... files)
        Concatenate paths.
        Parameters:
        files - the paths to concatenate
        Returns:
        the concatenated path
      • getComponents

        public java.util.List<java.lang.String> getComponents()
        Get the path components of this instance.
        Returns:
        the path components, never null
      • toFile

        public java.io.File toFile​(java.io.File file)
        Convert this instance to a File relative to the given File.
        Parameters:
        file - parent directory, may be null for a relative return value, but actually expected to be the repository's root directory
        Returns:
        where this instance should be located in the server-side filesystem
      • toPath

        public java.nio.file.Path toPath​(java.nio.file.Path path)
        Convert this instance to a Path relative to the given Path.
        Parameters:
        path - parent directory, may be null for a relative return value, but actually expected to be the repository's root directory
        Returns:
        where this instance should be located in the server-side filesystem
      • toString

        public java.lang.String toString()
        Provides repository path with components separated by separatorChar. Suitable for displaying to the user and for constructing a new instance.
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)
        Instances are equal if their string representations match.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(FsFile other)
        Specified by:
        compareTo in interface java.lang.Comparable<FsFile>