Class StoredTree.Node

java.lang.Object
org.apache.sis.io.wkt.StoredTree.Node
All Implemented Interfaces:
Serializable
Enclosing class:
StoredTree

private static final class StoredTree.Node extends Object implements Serializable
Unmodifiable copy of Element without contextual information such as Element.offset. The removal of contextual information increase greatly the possibility to reuse the same Node instances in many StoredTrees. For example, the UNIT["degrees", 0.0174532925199433] node is repeated a lot, so we want to share only one Node instance for every places in the WKT tree where degrees unit is declared, even if they appear at different offsets in the WKT string.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • keyword

      final String keyword
      Copy of Element.keyword reference, or null if this node is anonymous. Anonymous nodes are used only as wrappers for array of roots in the corner cases documented by StoredTree.root.
      See Also:
    • children

      private final Object[] children
      Snapshot of Element.children list. Array content shall not be modified. This array is null if the keyword was not followed by a pair of brackets (e.g. "north"). A null value is not equivalent to an empty list. For example, the list is null when parsing "FOO" but is empty when parsing "FOO[]".
  • Constructor Details

  • Method Details

    • toElements

      final void toElements(StoredTree.Inflater inflater, Collection<? super Element> addTo)
      Copies this node in modifiable Elements and add them to the given list. This is the converse of the Node(Deflater, List) constructor. This method usually adds exactly one element to the given list, except for the "multi-roots" corner case documented in StoredTree.root.
      See Also:
    • toElement

      private Element toElement(StoredTree.Inflater inflater)
      Copies this node in a modifiable Element. This is the converse of the Node(Deflater, Element) constructor.
    • peekLastElement

      final StoredTree.Node peekLastElement(String... keys)
      Returns the last element of the given names. This method searches only in children of this node. It does not search recursively in children of children.
      Parameters:
      keys - the element names (e.g. "ID").
      Returns:
      the last StoredTree.Node of the given names found in the children, or null if none.
    • peekValues

      final void peekValues(Object[] addTo, int index)
      Returns the next values (not child elements). The maximum number of values fetched is the length of the given array. If there is less WKT elements, remaining array elements are unchanged.
      Parameters:
      addTo - non-empty array where to store the values.
      index - index where to store the first element in given array.
    • forEachValue

      final void forEachValue(Consumer<Object> addTo)
      Adds keyword and children to the given supplier. Children of children are added recursively. This method is for testing purposes only.
      See Also:
    • toString

      public String toString()
      Returns the string representation of the first value, which is usually the element name. For example, in DATUM["WGS 84", …] this is "WGS 84". If there are no children then this method returns the keyword, which is usually an enumeration value (for example "NORTH"}).
      Overrides:
      toString in class Object
      See Also:
    • hashCode

      public int hashCode()
      Returns a hash code value for this node. It uses hash codes of child elements, except for children that are instances of StoredTree.Node for which identity hash codes are used. We avoid requesting "normal" hash code of child StoredTree.Node because the tree structure may cause the same hash codes to be computed many times. The use of identity hash codes is sufficient if children have been replaced by unique instances before to compute the hash code of this StoredTree.Node. This replacement is done by StoredTree.Deflater.unique(Node).
      Overrides:
      hashCode in class Object
      See Also:
    • equals

      public boolean equals(Object other)
      Returns whether the given object is equal to this Node, comparing keyword and children. Nested StoredTree.Nodes are compared by identity comparisons; see hashCode() for rational.
      Overrides:
      equals in class Object
      See Also: