Interface PathTree

All Known Subinterfaces:
OpenPathTree
All Known Implementing Classes:
ArchivePathTree, ArchivePathTree.OpenArchivePathTree, DirectoryPathTree, EmptyPathTree, FilteredPathTree, MultiRootPathTree, OpenContainerPathTree, PathTreeWithManifest

public interface PathTree
  • Method Details

    • ofDirectoryOrFile

      static PathTree ofDirectoryOrFile(Path p)
    • ofDirectoryOrFile

      static PathTree ofDirectoryOrFile(Path p, PathFilter filter)
    • ofDirectoryOrArchive

      static PathTree ofDirectoryOrArchive(Path p)
      Creates a new PathTree for a given existing path which is expected to be either a directory or a ZIP-based archive.
      Parameters:
      p - path to a directory or an archive
      Returns:
      an instance of PathTree for a given existing directory or an archive
    • ofDirectoryOrArchive

      static PathTree ofDirectoryOrArchive(Path p, PathFilter filter)
      Creates a new PathTree for a given existing path which is expected to be either a directory or a ZIP-based archive applying a provided PathFilter unless it is null.
      Parameters:
      p - path to a directory or an archive
      filter - path filter to apply, could be null
      Returns:
      an instance of PathTree for a given existing directory or an archive
    • ofArchive

      static PathTree ofArchive(Path archive)
      Creates a new PathTree for an existing path that is expected to be a ZIP-based archive.
      Parameters:
      archive - path to an archive
      Returns:
      an instance of PathTree for a given archive
    • ofArchive

      static PathTree ofArchive(Path archive, PathFilter filter)
      Creates a new PathTree for an existing path that is expected to be a ZIP-based archive applying a provided PathFilter unless it is null.
      Parameters:
      archive - path to an archive
      filter - path filter to apply, could be null
      Returns:
      an instance of PathTree for a given archive
    • getRoots

      Collection<Path> getRoots()
      The roots of the path tree.

      Note that you shouldn't use these roots for browsing except if the PathTree is open.

      Returns:
      roots of the path tree
    • isEmpty

      default boolean isEmpty()
      Checks whether the tree is empty
      Returns:
      true, if the tree is empty, otherwise - false
    • getManifestAttributes

      ManifestAttributes getManifestAttributes()
      If META-INF/MANIFEST.MF found, reads it and returns an instance of ManifestAttributes, a trimmed down version of the Manifest, otherwise returns null.
      Returns:
      parsed META-INF/MANIFEST.MF if it's found, otherwise null
    • walk

      void walk(PathVisitor visitor)
      Walks the tree.
      Parameters:
      visitor - path visitor
    • walkIfContains

      void walkIfContains(String relativePath, PathVisitor visitor)
      Walks a subtree of this tree that begins with a passed in relativePath, if the tree contains relativePath. If the tree does not contain relativePath then the method returns without an error.

      This method does not create a new PathTree with the root at relativePath. It simply applies an inclusion filter to this PathTree instance, keeping the same root.

      Parameters:
      relativePath - relative path from which the walk should begin
      visitor - path visitor
    • apply

      <T> T apply(String relativePath, Function<PathVisit,T> func)
      Applies a function to a given path relative to the root of the tree. If the path isn't found in the tree, the PathVisit argument passed to the function will be null.
      Type Parameters:
      T - resulting type
      Parameters:
      relativePath - relative path to process
      func - processing function
      Returns:
      result of the function
    • accept

      void accept(String relativePath, Consumer<PathVisit> consumer)
      Consumes a given path relative to the root of the tree. If the path isn't found in the tree, the PathVisit argument passed to the consumer will be null.
      Parameters:
      relativePath - relative path to consume
      consumer - path consumer
    • acceptAll

      default void acceptAll(String relativePath, Consumer<PathVisit> consumer)
      Consumes a given path relative to the root of the tree. If the path isn't found in the tree, the PathVisit argument passed to the consumer will be null. If multiple items match then the consumer will be called multiple times.
      Parameters:
      relativePath - relative path to consume
      consumer - path consumer
    • contains

      boolean contains(String relativePath)
      Checks whether the tree contains a relative path.
      Parameters:
      relativePath - path relative to the root of the tree
      Returns:
      true, in case the tree contains the path, otherwise - false
    • open

      OpenPathTree open()
      Returns an OpenPathTree for this tree, which is supposed to be closed at the end of processing. It is meant to be an optimization when processing multiple paths of path trees that represent archives. If a path tree does not represent an archive but a directory, for example, this method is expected to be a no-op, returning the original tree as an instance of OpenPathTree.
      Returns:
      an instance of OpenPathTree for this path tree
    • filter

      default PathTree filter(PathFilter filter)
      Creates a new PathTree instance applying a path filter to this PathTree instance.
      Parameters:
      filter - path filter to apply
      Returns:
      a new PathTree instance applying a path filter to this PathTree instance