Package org.apache.sis.io.wkt
Class StoredTree
java.lang.Object
org.apache.sis.io.wkt.StoredTree
- All Implemented Interfaces:
Serializable
A tree of
Elements saved for later use. StoredTrees 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 sameNodeinstances for reducing memory usage.
Element instances directly because Elements 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 classA helper class for compressing a tree ofElements as a tree ofStoredTree.Nodes.private static final classA helper class for decompressing a tree ofElements from a tree ofStoredTree.Nodes.private static final classUnmodifiable copy ofElementwithout 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.NodeRoot of a tree ofElementsnapshots.private static final longIndirectly forWKTFormatserialization compatibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final voidforEachValue(Consumer<Object> addTo) Adds keywords and children to the given supplier.(package private) final Stringkeyword()Returns the keyword of the root element.(package private) final voidpeekIdentifiers(Object[] fullId) Stores identifier information in the given array.(package private) final voidtoElements(AbstractParser parser, Collection<? super Element> addTo, int isFragment) RecreatesElementtrees.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 forWKTFormatserialization compatibility.- See Also:
-
root
Root of a tree ofElementsnapshots.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.Nodewith 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~offsetandElement.isFragmentshall be set totrue. This array shall not be modified because it may be shared by manyStoredTrees.
-
-
Constructor Details
-
StoredTree
Creates a newStoredTreewith 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 newStoredTreewith 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
RecreatesElementtrees. 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.isFragmentshall 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)
nullbefore 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"}).
-