Class FSTree<V>

  • Type Parameters:
    V - The type of the values attached to the files.

    public class FSTree<V>
    extends java.lang.Object
    Allows to represent a collection of VCSFile instances as a file system tree with a generic value that may be attached to a file.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FSTree.Visitor<E>
      A simple visitor to process FSTree instances.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String EMPTY_DIRECTORY
      This path is used for empty trees.
      static java.lang.String ROOT_DIRECTORY
      This path is used for trees with multiple root nodes.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      FSTree<V> compact()
      Compacts this tree such that each node is either a file, or a directory containing only files or at least two sub directories.
      java.util.List<FSTree<V>> getAllDirectories()
      Returns all (recursively) sub directories of this tree if this tree is a directory.
      java.util.List<FSTree<V>> getAllFiles()
      Returns all (recursively) sub files of this tree if this tree is a directory.
      java.util.List<FSTree<V>> getDirectories()
      Returns the sub directories of this tree if this tree is a directory.
      java.util.Optional<VCSFile> getFile()
      Returns the referenced VCSFile if this tree is a file.
      java.util.List<FSTree<V>> getFiles()
      Returns the sub files of this tree if this tree is a directory.
      java.lang.String getName()
      Returns the name of this file (if getFile() is present) or directory (if getNodes() is present).
      java.util.List<FSTree<V>> getNodes()
      Returns the sub files and directories of this tree if this tree is a directory.
      java.util.Optional<FSTree<V>> getParent()
      Returns the parent of this tree.
      java.lang.String getPath()
      Returns the relative path of this file (if getFile() is present) or directory (if getNodes() is present).
      FSTree<V> getRoot()
      Returns the root of this tree.
      java.util.Optional<V> getValue()
      Either returns the value of this file (if this tree represents a file) or the aggregated values of all (recursively) sub files (if this tree represents a directory).
      boolean isDirectory()
      Returns whether this tree is a directory.
      boolean isFile()
      Returns whether this tree is a file.
      boolean isRoot()
      Returns whether this tree is a root node.
      boolean isVirtualRoot()
      Returns whether this tree is a virtual root directory that has been created to cover multiple root nodes.
      java.util.Optional<FSTree<V>> navigateTo​(java.lang.String path)
      Navigates to the tree located at path.
      static FSTree<java.lang.Void> of​(java.util.Collection<VCSFile> pFiles)
      Creates a tree from the given list of VCSFile instances.
      static <V> FSTree<V> of​(java.util.Collection<VCSFile> pFiles, java.util.function.Function<VCSFile,​V> pValueOf, java.util.function.BinaryOperator<V> pAggregator)
      Creates a tree from the given list of VCSFile instances.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_DIRECTORY

        public static final java.lang.String EMPTY_DIRECTORY
        This path is used for empty trees.
        See Also:
        Constant Field Values
      • ROOT_DIRECTORY

        public static final java.lang.String ROOT_DIRECTORY
        This path is used for trees with multiple root nodes.
        See Also:
        Constant Field Values
    • Method Detail

      • of

        public static <V> FSTree<V> of​(java.util.Collection<VCSFile> pFiles,
                                       java.util.function.Function<VCSFile,​V> pValueOf,
                                       java.util.function.BinaryOperator<V> pAggregator)
                                throws java.lang.NullPointerException
        Creates a tree from the given list of VCSFile instances. null values and duplicates (according to Object.equals(Object)) are filtered.
        Type Parameters:
        V - The type of the values attached to files.
        Parameters:
        pFiles - The files to create the tree from.
        pValueOf - The function that is used to map a file to its value. The function may return null.
        pAggregator - The aggregation function used to calculate the value of a directory. The function must not handle null values.
        Returns:
        A tree representing the list of files.
        Throws:
        java.lang.NullPointerException - If any of the given arguments is null.
      • of

        public static FSTree<java.lang.Void> of​(java.util.Collection<VCSFile> pFiles)
                                         throws java.lang.NullPointerException
        Creates a tree from the given list of VCSFile instances. The created tree has no value (see getValue()). null values and duplicates (according to Object.equals(Object)) are filtered.
        Parameters:
        pFiles - The files to create the tree from.
        Returns:
        A tree representing the list of files.
        Throws:
        java.lang.NullPointerException - If pFile is null.
      • getParent

        public java.util.Optional<FSTree<V>> getParent()
        Returns the parent of this tree.
        Returns:
        The parent of this tree.
      • getPath

        public java.lang.String getPath()
        Returns the relative path of this file (if getFile() is present) or directory (if getNodes() is present).
        Returns:
        The relative path of this file or directory.
      • getName

        public java.lang.String getName()
        Returns the name of this file (if getFile() is present) or directory (if getNodes() is present).
        Returns:
        The name of this file or directory.
      • getFile

        public java.util.Optional<VCSFile> getFile()
        Returns the referenced VCSFile if this tree is a file.
        Returns:
        The referenced VCSFile.
      • getValue

        public java.util.Optional<V> getValue()
        Either returns the value of this file (if this tree represents a file) or the aggregated values of all (recursively) sub files (if this tree represents a directory).
        Returns:
        The value of this file or the aggregated values of all (recursively) sub files. If this file has no value (or this directory contains only files without a value), an empty Optional is returned.
      • getNodes

        public java.util.List<FSTree<V>> getNodes()
        Returns the sub files and directories of this tree if this tree is a directory. If this tree is a file, an empty list is returned.
        Returns:
        The sub files and directories of this tree.
      • getDirectories

        public java.util.List<FSTree<V>> getDirectories()
        Returns the sub directories of this tree if this tree is a directory. If this tree is a file, an empty List is returned.
        Returns:
        The sub directories of this tree.
      • getAllDirectories

        public java.util.List<FSTree<V>> getAllDirectories()
        Returns all (recursively) sub directories of this tree if this tree is a directory. If this tree is a file, an empty list is returned.
        Returns:
        All (recursively) sub directories of this tree.
      • getFiles

        public java.util.List<FSTree<V>> getFiles()
        Returns the sub files of this tree if this tree is a directory. If this tree is a file, an empty list is returned.
        Returns:
        The sub files of this tree.
      • getAllFiles

        public java.util.List<FSTree<V>> getAllFiles()
        Returns all (recursively) sub files of this tree if this tree is a directory. If this tree is a file, an empty list is returned.
        Returns:
        Al (recursively) sub files of this tree.
      • getRoot

        public FSTree<V> getRoot()
        Returns the root of this tree.
        Returns:
        The root of this tree.
      • navigateTo

        public java.util.Optional<FSTree<V>> navigateTo​(java.lang.String path)
        Navigates to the tree located at path. Unlike conventional navigation rules, this method allows to navigate "beyond" a regular file. That is, for instance, a file's parent may be addressed like this: "src/A.java/.." where "A.java" is a regular file and ".." points to its parent. If path is empty, this is returned.
        Parameters:
        path - The relative path of the tree to navigate to.
        Returns:
        The tree located at path, if such a tree exists.
        Throws:
        java.lang.NullPointerException - If path is null.
      • compact

        public FSTree<V> compact()
        Compacts this tree such that each node is either a file, or a directory containing only files or at least two sub directories. If this tree is a sequence of single directories, an "empty" directory is returned. This method does not modify this tree or any of its sub nodes, but creates a flat copy it.
        Returns:
        A Tree consisting of files, and directories containing only files or at least two sub directories. An "empty" directory if this tree is a sequence of single directories.
      • isFile

        public boolean isFile()
        Returns whether this tree is a file.
        Returns:
        true if this tree is a file, false otherwise.
      • isDirectory

        public boolean isDirectory()
        Returns whether this tree is a directory.
        Returns:
        true if this tree is a directory, false otherwise.
      • isRoot

        public boolean isRoot()
        Returns whether this tree is a root node.
        Returns:
        true if this tree is a root node, false otherwise.
      • isVirtualRoot

        public boolean isVirtualRoot()
        Returns whether this tree is a virtual root directory that has been created to cover multiple root nodes.
        Returns:
        true if this tree is a virtual root directory, false otherwise.