Class Tree<T>

java.lang.Object
uk.ac.starlink.vo.Tree<T>
Direct Known Subclasses:
Tree.Branch, Tree.Leaf

public abstract class Tree<T> extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static 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 Type
    Method
    Description
    abstract Tree.Branch<T>
    Returns this instance as a Branch if it's a branch, or null if it's a leaf.
    abstract Tree.Leaf<T>
    Returns this instance as a Leaf if it's a leaf, or null if it's a branch.
    abstract boolean
    Returns true if this instance is a Leaf, false if it's a Branch.
    abstract <R> Tree<R>
    map(Function<T,R> mapping)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public abstract Tree.Leaf<T> 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

      public abstract Tree.Branch<T> 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

      public abstract <R> Tree<R> map(Function<T,R> mapping)
      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