Package uk.ac.starlink.vo
Class Tree<T>
java.lang.Object
uk.ac.starlink.vo.Tree<T>
- Direct Known Subclasses:
Tree.Branch
,Tree.Leaf
Hierarchical data structure suitable for general use.
All instances of this class are either of class
Tree.Leaf
or
Tree.Branch
.
Node might be a better name than Tree, but since it's used with
DOM parsing I want to avoid a name clash with
org.w3c.dom.Node
.
- Since:
- 19 Jan 2023
- Author:
- Mark Taylor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Tree instance that contains a list of children and no referenced item.static class
Tree instance that contains a referenced item and no children. -
Method Summary
Modifier and TypeMethodDescriptionabstract Tree.Branch<T>
asBranch()
Returns this instance as a Branch if it's a branch, or null if it's a leaf.asLeaf()
Returns this instance as a Leaf if it's a leaf, or null if it's a branch.abstract boolean
isLeaf()
Returns true if this instance is a Leaf, false if it's a Branch.abstract <R> Tree<R>
Recursively converts this Tree to one with the same structure, but with the leaf items mapped from their existing values to new values determined by a supplied mapping function.
-
Method Details
-
isLeaf
public abstract boolean isLeaf()Returns true if this instance is a Leaf, false if it's a Branch.- Returns:
- true iff this is a leaf
-
asLeaf
Returns this instance as a Leaf if it's a leaf, or null if it's a branch.- Returns:
- this cast to Leaf, or null
-
asBranch
Returns this instance as a Branch if it's a branch, or null if it's a leaf.- Returns:
- this cast to Branch, or null
-
map
Recursively converts this Tree to one with the same structure, but with the leaf items mapped from their existing values to new values determined by a supplied mapping function.- Parameters:
mapping
- mapping function- Returns:
- tree with mapped values
-