Package org.apache.sis.io.wkt
Class StoredTree
java.lang.Object
org.apache.sis.io.wkt.StoredTree
- All Implemented Interfaces:
Serializable
A tree of
Element
s saved for later use. StoredTree
s are created in following situations:
WKTFormat.addFragment(String, String)
for defining shortcuts to be inserted into an arbitrary number of other WKT strings.WKTDictionary.addDefinitions(Stream)
for preparing WKT definitions to be parsed only when first needed. While WKT trees are waiting, they may share references to sameNode
instances for reducing memory usage.
Element
instances directly because Element
s are not easily shareable.
Contrarily to Element
design, StoredTree
needs unmodifiable Element.children
list and
needs to store Element.offset
values in separated arrays. Those changes make possible to have many
StoredTree
instances sharing the same Node
instances in the common case where some WKT elements
are repeated in many trees.- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
A helper class for compressing a tree ofElement
s as a tree ofStoredTree.Node
s.private static final class
A helper class for decompressing a tree ofElement
s from a tree ofStoredTree.Node
s.private static final class
Unmodifiable copy ofElement
without contextual information such asElement.offset
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final short[]
Indices in the WKT string where elements have been found.private final StoredTree.Node
Root of a tree ofElement
snapshots.private static final long
Indirectly forWKTFormat
serialization compatibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final void
forEachValue
(Consumer<Object> addTo) Adds keywords and children to the given supplier.(package private) final String
keyword()
Returns the keyword of the root element.(package private) final void
peekIdentifiers
(Object[] fullId) Stores identifier information in the given array.(package private) final void
toElements
(AbstractParser parser, Collection<? super Element> addTo, int isFragment) RecreatesElement
trees.toString()
Returns the string representation of the first value of the root element, which is usually the element name.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDIndirectly forWKTFormat
serialization compatibility.- See Also:
-
root
Root of a tree ofElement
snapshots.Multi-roots
There is exactly one root in the vast majority of cases. However, there is a situation where we need to allow more roots: when user wants to represent a coordinate system. A WKT 2 coordinate system looks like: While axes are conceptually parts of coordinate system, they are not declared inside theCS[…]
element for historical reasons (for compatibility with WKT 1). For representing such "flattened tree", we need an array of roots. We do that by wrapping that array in a syntheticStoredTree.Node
with nullkeyword()
(an "anonymous node"). -
offsets
private final short[] offsetsIndices in the WKT string where elements have been found. If negative, the actual offset value is~offset
andElement.isFragment
shall be set totrue
. This array shall not be modified because it may be shared by manyStoredTree
s.- See Also:
-
-
Constructor Details
-
StoredTree
Creates a newStoredTree
with a snapshot of given tree of elements.- Parameters:
tree
- root of the tree of WKT elements.sharedValues
- pool to use for sharing unique instances of values.
-
StoredTree
Creates a newStoredTree
with a snapshot of given trees of elements. This is for a corner case only; see "Multi roots" inroot
.- Parameters:
trees
- roots of the trees of WKT elements.sharedValues
- pool to use for sharing unique instances of values.
-
-
Method Details
-
toElements
RecreatesElement
trees. This method is the converse of the constructor. This method usually adds exactly one element to the given list, except for the "multi-roots" corner case documented inroot
.- Parameters:
parser
- the parser which will be used for parsing the tree.addTo
- where to add the elements.isFragment
- non-zero if and only ifElement.isFragment
shall betrue
. In such case, this value must be~Element.offset
.
-
peekIdentifiers
Stores identifier information in the given array. This method locates the last"ID"
(WKT 2) or"AUTHORITY"
(WKT 1) node and optionally the"CITATION"
sub-node. Values are copied in the given array, in that order!- Code space
- Code
- Version if present
- Authority if present (skipped if the array length is less than 4)
null
before to invoke this method.- Parameters:
fullId
- where to store code space, code, version, authority.
-
forEachValue
Adds keywords and children to the given supplier. This is for testing purposes only.- See Also:
-
keyword
Returns the keyword of the root element. -
toString
Returns the string representation of the first value of the root element, 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"}).
-