Package org.apache.sis.io.wkt
Class StoredTree.Node
java.lang.Object
org.apache.sis.io.wkt.StoredTree.Node
- All Implemented Interfaces:
Serializable
- Enclosing class:
- StoredTree
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]Snapshot ofElement.childrenlist.(package private) final StringCopy ofElement.keywordreference, ornullif this node is anonymous.private static final longFor cross-version compatibility. -
Constructor Summary
ConstructorsConstructorDescriptionNode(StoredTree.Deflater deflater, List<Element> elements) Creates an anonymous node for an array of roots.Node(StoredTree.Deflater deflater, Element element) Creates an immutable copy of the given element. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the given object is equal to thisNode, comparing keyword and children.(package private) final voidforEachValue(Consumer<Object> addTo) Adds keyword and children to the given supplier.inthashCode()Returns a hash code value for this node.(package private) final StoredTree.NodepeekLastElement(String... keys) Returns the last element of the given names.(package private) final voidpeekValues(Object[] addTo, int index) Returns the next values (not child elements).private ElementtoElement(StoredTree.Inflater inflater) Copies this node in a modifiableElement.(package private) final voidtoElements(StoredTree.Inflater inflater, Collection<? super Element> addTo) Copies this node in modifiableElements and add them to the given list.toString()Returns the string representation of the first value, which is usually the element name.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
keyword
Copy ofElement.keywordreference, ornullif this node is anonymous. Anonymous nodes are used only as wrappers for array of roots in the corner cases documented byStoredTree.root.- See Also:
-
children
Snapshot ofElement.childrenlist. Array content shall not be modified. This array isnullif 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
-
Node
Node(StoredTree.Deflater deflater, List<Element> elements) Creates an anonymous node for an array of roots. This constructor is only for the corner case documented in "Multi roots" section ofStoredTree.rootjavadoc.- See Also:
-
Node
Node(StoredTree.Deflater deflater, Element element) Creates an immutable copy of the given element. Keywords and children references are copied in this newNodebutElement.offsets are copied in a separated array for making possible to shareNodeinstances.- See Also:
-
-
Method Details
-
toElements
Copies this node in modifiableElements and add them to the given list. This is the converse of theNode(Deflater, List)constructor. This method usually adds exactly one element to the given list, except for the "multi-roots" corner case documented inStoredTree.root. -
toElement
Copies this node in a modifiableElement. This is the converse of theNode(Deflater, Element)constructor. -
peekLastElement
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.Nodeof the given names found in the children, ornullif none.
-
peekValues
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
Adds keyword and children to the given supplier. Children of children are added recursively. This method is for testing purposes only.- See Also:
-
toString
Returns the string representation of the first value, which is usually the element name. For example, inDATUM["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"}). -
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 ofStoredTree.Nodefor which identity hash codes are used. We avoid requesting "normal" hash code of childStoredTree.Nodebecause 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 thisStoredTree.Node. This replacement is done byStoredTree.Deflater.unique(Node). -
equals
Returns whether the given object is equal to thisNode, comparing keyword and children. NestedStoredTree.Nodes are compared by identity comparisons; seehashCode()for rational.
-