Class PathSet

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.String>

    public class PathSet
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.String>
    Set of file's paths. The class extends functionality of a "normal" set of strings by a process of the paths normalization. All paths are converted to unix form (slashes) and they don't start with starting /.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set<java.lang.String> pathsSet
      Set of normalized paths
      private static java.lang.String SEPARATOR  
      private static char SEPARATOR_CHAR  
    • Constructor Summary

      Constructors 
      Constructor Description
      PathSet()
      Creates an empty paths set
      PathSet​(java.lang.String[] paths)
      Creates paths set and normalizate and adds all 'paths'.
      PathSet​(java.util.Collection<java.lang.String> paths)
      Creates paths set and normalizate and adds all 'paths'.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String path)
      Normalizes and adds given path to the set.
      void addAll​(java.lang.String[] paths)
      Normalizes and adds given paths to the set.
      void addAll​(java.lang.String[] paths, java.lang.String prefix)
      Normalizes and adds given paths to the set.
      void addAll​(java.util.Collection<java.lang.String> paths)
      Normalizes and adds given paths (collection of strings) to the set.
      void addAll​(java.util.Collection<java.lang.String> paths, java.lang.String prefix)
      Normalizes and adds given paths (collection of strings) to the set.
      void addAll​(PathSet paths)
      Adds given paths to the set.
      void addAll​(PathSet paths, java.lang.String prefix)
      Adds given paths to the set.
      void addAllFilesInDirectory​(java.io.File directory, java.lang.String prefix)
      Adds to the set all files in the given directory
      void addPrefix​(java.lang.String prefix)
      Adds given prefix to all paths in the set.
      boolean contains​(java.lang.String path)
      Checks if the set constains given path.
      java.util.Iterator<java.lang.String> iterator()
      Returns iterator of normalized paths (strings)
      (package private) static java.lang.String normalizeSubPath​(java.lang.String path)  
      java.util.Collection<java.lang.String> paths()  
      (package private) boolean remove​(java.lang.String path)
      Removes the specified path if it exists.
      int size()
      Returns count of the paths in the set
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • SEPARATOR_CHAR

        private static final char SEPARATOR_CHAR
      • pathsSet

        private java.util.Set<java.lang.String> pathsSet
        Set of normalized paths
    • Constructor Detail

      • PathSet

        public PathSet()
        Creates an empty paths set
      • PathSet

        public PathSet​(java.util.Collection<java.lang.String> paths)
        Creates paths set and normalizate and adds all 'paths'. The source 'paths' will not be changed
        Parameters:
        paths - to be added
      • PathSet

        public PathSet​(java.lang.String[] paths)
        Creates paths set and normalizate and adds all 'paths'. The source 'paths' will not be changed
        Parameters:
        paths - to be added
    • Method Detail

      • normalizeSubPath

        static java.lang.String normalizeSubPath​(java.lang.String path)
      • add

        public void add​(java.lang.String path)
        Normalizes and adds given path to the set.
        Parameters:
        path - to be added
      • addAll

        public void addAll​(java.util.Collection<java.lang.String> paths,
                           java.lang.String prefix)
        Normalizes and adds given paths (collection of strings) to the set. The source collection will not be changed
        Parameters:
        paths - - collection of strings to be added
        prefix - added to all given paths
      • addAll

        public void addAll​(java.lang.String[] paths,
                           java.lang.String prefix)
        Normalizes and adds given paths to the set. The source collection will not be changed
        Parameters:
        paths - to be added
        prefix - added to all given paths
      • addAll

        public void addAll​(PathSet paths,
                           java.lang.String prefix)
        Adds given paths to the set. The source collection will not be changed
        Parameters:
        paths - to be added
        prefix - added to all given paths
      • addAll

        public void addAll​(java.util.Collection<java.lang.String> paths)
        Normalizes and adds given paths (collection of strings) to the set. The source collection will not be changed
        Parameters:
        paths - - collection of strings to be added
      • addAll

        public void addAll​(java.lang.String[] paths)
        Normalizes and adds given paths to the set. The source collection will not be changed
        Parameters:
        paths - to be added
      • addAll

        public void addAll​(PathSet paths)
        Adds given paths to the set. The source collection will not be changed
        Parameters:
        paths - to be added
      • contains

        public boolean contains​(java.lang.String path)
        Checks if the set constains given path. The path is normalized before check.
        Parameters:
        path - we are looking for in the set.
        Returns:
        information if the set constains the path.
      • remove

        boolean remove​(java.lang.String path)
        Removes the specified path if it exists.
        Parameters:
        path - the path to remove
        Returns:
        true if the path was removed, false if it did not existed
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Returns iterator of normalized paths (strings)
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Returns:
        iterator of normalized paths (strings)
      • paths

        public java.util.Collection<java.lang.String> paths()
        Returns:
        pathsSet
      • addPrefix

        public void addPrefix​(java.lang.String prefix)
        Adds given prefix to all paths in the set. The prefix should be ended by '/'. The generated paths are normalized.
        Parameters:
        prefix - to be added to all items
      • size

        public int size()
        Returns count of the paths in the set
        Returns:
        count of the paths in the set
      • addAllFilesInDirectory

        public void addAllFilesInDirectory​(java.io.File directory,
                                           java.lang.String prefix)
        Adds to the set all files in the given directory
        Parameters:
        directory - that will be searched for file's paths to add
        prefix - to be added to all found files