Class PathTree<P extends Path,T>
java.lang.Object
com.inductiveautomation.ignition.common.PathTree<P,T>
- Type Parameters:
P
- The path type to use.T
- The value type to store.
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
HistoricalNodeTree
,TagPathTree
,TagStructureTree
A tree structure that uses a path to locate values. Paths are represented by a Path object, which is a list of
strings. The tree is not thread safe, and is not designed to be used in a multi-threaded environment (or it should be
synchronized externally). The tree is
case-insensitive by default, but can be set to be case-sensitive. The tree is designed to be used with a Path object
that is immutable.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEssentially an alias for getChildren(path), though wraps the results in a list.void
clear()
Clears the entire tree.computeIfAbsent
(P path, Function<P, T> supplier) Locates the node at the given path.Returns the value at the given path.<R extends T>
Collection<R>getAllNestedChildren
(P path) Returns all nested children under a given path using breadth-first search.getBranches
(P path) Returns the keys for the branches beneath the given point.getBranches
(P path, boolean foldersOnly) Returns the keys for the branches beneath the given point.<R extends T>
Collection<R>getChildren
(P path) Returns the children under a given path.getRoot()
Object[]
getValuesOfPath
(P path) Returns all of the node values from the tree nodes along the specified path.protected void
Instantiates a TreeNode under the parent, for the given path position of the path.boolean
boolean
Inserts the value at the given path.Removes the given path, and returns the value that was associated with the path, if applicable.removeIfEmpty
(P path) Removes and returns the value, and if there are no children, removes the node from the tree.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.
-
Constructor Details
-
PathTree
public PathTree()
-
-
Method Details
-
initializeRoot
protected void initializeRoot() -
getRoot
-
instantiateNode
Instantiates a TreeNode under the parent, for the given path position of the path. Subclasses can override this method to provide custom node types, and to create default values for implicit nodes.- Parameters:
parent
- the parent nodepath
- the complete path of the ultimate node being createdpos
- the position in the path that the node is being created for- Returns:
- the new node
-
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
Essentially an alias for getChildren(path), though wraps the results in a list. -
getChildren
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. Does not return nested children. -
getAllNestedChildren
Returns all nested children under a given path using breadth-first search. -
getBranches
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
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
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
Returns the value at the given path. If the path is null, the root value is returned. -
computeIfAbsent
-
remove
Removes the given path, and returns the value that was associated with the path, if applicable. -
removeIfEmpty
Removes and returns the value, and if there are no children, removes the node from the tree. -
clear
public void clear()Clears the entire tree. -
getValuesOfPath
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
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
-