Class ArrayNode<V,S extends ArrayNode<V,S>>

java.lang.Object
esa.opensf.osfi.ArrayNode<V,S>
Type Parameters:
V - Type used to store values. May be an array for parsed nodes, or a String for unparsed.
S - CRTP parameter, used so that getSubNodes() and similar return the same type.
Direct Known Subclasses:
ArrayNode.Parsed, ArrayNode.Raw

public abstract sealed class ArrayNode<V,S extends ArrayNode<V,S>> extends Object permits ArrayNode.Raw, ArrayNode.Parsed<A>
Class that represents a tree with data (leaf) nodes and internal nodes. The data may be raw (a String with the unparsed values) or fully parsed.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A parsed tree that represents the values of (part of) an ARRAY-valued parameter.
    static final class 
    An unparsed tree that represents (part of) an ARRAY-valued parameter.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final V
    Elements for a data node.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ArrayNode(List<? extends S> subNodes)
    Create an internal node with the given subnodes.
    protected
    ArrayNode(V values)
    Create a data node with the given contents.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract String
     
     
    final V
    getDataAtSub(int... indices)
    Equivalent to getSubNodeAt(indices).getData(), except that if indices is empty, this this method returns the result of calling getData() on this instead of throwing.
    protected abstract int
     
    final int
     
    final List<Integer>
    Compute the rectangular envelope for the dimensions of this array node, considering all nodes below it in the tree.
    final S
    getSubNodeAt(int... indices)
    Equivalent to calling s = s.getSubNodes().get(i) for each index given, starting with this object.
    final List<S>
     
    protected boolean
    Helper for subclasses to implement Object.equals(Object) for internal nodes.
    protected int
    Helper for subclasses to implement Object.hashCode() in internal nodes
    final boolean
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • elems

      protected final V elems
      Elements for a data node. If null, this is an internal node.
  • Constructor Details

    • ArrayNode

      protected ArrayNode(V values)
      Create a data node with the given contents.
      Parameters:
      values - Data to store in the leaf node.
    • ArrayNode

      protected ArrayNode(List<? extends S> subNodes)
      Create an internal node with the given subnodes.
      Parameters:
      subNodes - Child nodes. The list is used as-is, not copied.
  • Method Details

    • isDataNode

      public final boolean isDataNode()
      Returns:
      true if this node was built with data elements, false if it was built with subnodes.
    • getData

      public V getData()
      Returns:
      the raw data elements, or null if this is an internal node without data.
    • getSubNodes

      public final List<S> getSubNodes()
      Returns:
      the list of subnodes, or the empty list if this is a data node without subnodes.
    • getSubNodeAt

      public final S getSubNodeAt(int... indices)
      Equivalent to calling s = s.getSubNodes().get(i) for each index given, starting with this object. The final value of s is returned.
      Parameters:
      indices - Index values for each dimension.
      Returns:
      the subnode at the given index position in the tree.
      Throws:
      IllegalArgumentException - if s is empty.
      IndexOutOfBoundsException - if one of the indices is invalid.
    • getDataAtSub

      public final V getDataAtSub(int... indices)
      Equivalent to getSubNodeAt(indices).getData(), except that if indices is empty, this this method returns the result of calling getData() on this instead of throwing.
      Parameters:
      indices - Index values for each dimension.
      Returns:
      the data at the given index position in the tree.
      Throws:
      IndexOutOfBoundsException - if one of the indices is invalid.
      See Also:
    • getDim

      public final int getDim()
      Returns:
      the size of this array node (i.e. of this dimension level).
    • getDataDim

      protected abstract int getDataDim()
      Returns:
      the size of the data elements (for a data node).
    • getDimsEnvelope

      public final List<Integer> getDimsEnvelope()
      Compute the rectangular envelope for the dimensions of this array node, considering all nodes below it in the tree.
      Returns:
      Size of the rectangular multi-dimensional array that can contain this subtree.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a representation of the tree from this node, useful for debugging.
    • innerEquals

      protected boolean innerEquals(ArrayNode<?,?> o)
      Helper for subclasses to implement Object.equals(Object) for internal nodes.
    • innerHashCode

      protected int innerHashCode()
      Helper for subclasses to implement Object.hashCode() in internal nodes
    • dataToStr

      protected abstract String dataToStr()
      Returns:
      String version of the data elements.