Class PathTree<P extends Path,​T>

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    TagPathTree, TagStructureTree

    public class PathTree<P extends Path,​T>
    extends java.lang.Object
    implements java.io.Serializable
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  PathTree.TreeNode  
    • Constructor Summary

      Constructors 
      Constructor Description
      PathTree()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<T> browse​(P path)
      Essentially an alias for getChildren(path), though wraps the results in a list.
      void clear()
      Clears the entire tree.
      T computeIfAbsent​(P path, java.util.function.Function<P,​T> supplier)  
      protected PathTree.TreeNode findNode​(P path, boolean create)
      Locates the node at the given path.
      protected PathTree.TreeNode findNode​(P path, boolean create, java.lang.Object[] valueArray)  
      T get​(P path)
      Returns the value at the given path.
      java.util.List<java.lang.String> getBranches​(P path)
      Returns the keys for the branches beneath the given point.
      java.util.List<java.lang.String> getBranches​(P path, boolean foldersOnly)
      Returns the keys for the branches beneath the given point.
      <R extends T>
      java.util.Collection<R>
      getChildren​(P path)
      Returns the children under a given path.
      protected PathTree.TreeNode getRoot()  
      java.lang.Object[] getValuesOfPath​(P path)
      Returns all of the node values from the tree nodes along the specified path.
      protected PathTree.TreeNode instantiateNode​(PathTree.TreeNode parent, P path, int pos)  
      boolean isCaseSensitive()  
      boolean put​(P path, T value)
      Inserts the value at the given path.
      T remove​(P path)
      Removes the given path, and returns the value that was associated with the path, if applicable.
      void setCaseSensitive​(boolean value)
      If set to true (value is false by default), the branches of the tree will be different based on case.
      int size()
      Calculates the size of this tag tree.
      • Methods inherited from class java.lang.Object

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

      • PathTree

        public PathTree()
    • Method Detail

      • isCaseSensitive

        public boolean isCaseSensitive()
      • setCaseSensitive

        public void setCaseSensitive​(boolean value)
        If set to true (value is false by default), the branches of the tree will be different based on case.
      • size

        public int size()
        Calculates the size of this tag tree. Note that this is not thread safe and is not efficient!
      • browse

        public java.util.List<T> browse​(P path)
        Essentially an alias for getChildren(path), though wraps the results in a list.
      • getChildren

        public <R extends T> java.util.Collection<R> getChildren​(P path)
        Returns the children under a given path. Used for browsing. Will never return null, just an empty collection if there are no children or the path doesn't exist.
      • getBranches

        public java.util.List<java.lang.String> getBranches​(P path)
        Returns the keys for the branches beneath the given point. Returns empty list if the point is not found, or there are no branches.
      • getBranches

        public java.util.List<java.lang.String> getBranches​(P path,
                                                            boolean foldersOnly)
        Returns the keys for the branches beneath the given point. Returns empty list if the point is not found, or there are no branches. If foldersOnly is true, will only return children that have null leaf values.
      • put

        public boolean put​(P path,
                           T value)
        Inserts the value at the given path. Returns whether or not the insertion was successful. Intermediary nodes will be created implicitly, and subclasses can customize their values by overriding instantiateNode.
      • get

        public T get​(P path)
        Returns the value at the given path. If the path is null, the root value is returned.
      • computeIfAbsent

        public T computeIfAbsent​(P path,
                                 java.util.function.Function<P,​T> supplier)
      • remove

        public T remove​(P path)
        Removes the given path, and returns the value that was associated with the path, if applicable.
      • clear

        public void clear()
        Clears the entire tree.
      • getValuesOfPath

        public java.lang.Object[] getValuesOfPath​(P path)
        Returns all of the node values from the tree nodes along the specified path. The return length will be the path length + 1 (the root/null value), even if the node doesn't exist. Any tree node that doesn't exist or doesn't have a value will have a null entry.
        Parameters:
        path - the path to locate
        Returns:
        an array whose bounds are equal to path.getPathLength()+1. Index 0 is the null/root value. Each array element represents the value at a given location in the tree, and will be null if the node does not exist.
      • findNode

        protected PathTree.TreeNode findNode​(P path,
                                             boolean create)
        Locates the node at the given path. Will insert nodes as necessary, if create is true. Otherwise will return null if the path doesn't exist.
      • findNode

        protected PathTree.TreeNode findNode​(P path,
                                             boolean create,
                                             java.lang.Object[] valueArray)