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 StoredTree
s. 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.children
list.(package private) final String
Copy ofElement.keyword
reference, ornull
if this node is anonymous.private static final long
For 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 TypeMethodDescriptionboolean
Returns whether the given object is equal to thisNode
, comparing keyword and children.(package private) final void
forEachValue
(Consumer<Object> addTo) Adds keyword and children to the given supplier.int
hashCode()
Returns a hash code value for this node.(package private) final StoredTree.Node
peekLastElement
(String... keys) Returns the last element of the given names.(package private) final void
peekValues
(Object[] addTo, int index) Returns the next values (not child elements).private Element
toElement
(StoredTree.Inflater inflater) Copies this node in a modifiableElement
.(package private) final void
toElements
(StoredTree.Inflater inflater, Collection<? super Element> addTo) Copies this node in modifiableElement
s 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.keyword
reference, ornull
if 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.children
list. Array content shall not be modified. This array isnull
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
-
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.root
javadoc.- 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 newNode
butElement.offset
s are copied in a separated array for making possible to shareNode
instances.- See Also:
-
-
Method Details
-
toElements
Copies this node in modifiableElement
s 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.Node
of the given names found in the children, ornull
if 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.Node
for which identity hash codes are used. We avoid requesting "normal" hash code of childStoredTree.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 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.Node
s are compared by identity comparisons; seehashCode()
for rational.
-