= TreePath _(record)_
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Provides an unambiguous way to address nodes by position within a tree-structure. Examples:

* /0 ... the tree root
* /0/1 ... the second child of root
* /0/0/0 ... the first child of first child of root

== API

[source,java]
.TreePath.java
----
record TreePath {
  TreePath(int[] canonicalPath)
  TreePath parse(String treePathStringified, String delimiter)     // <.>
  TreePath of(int... canonicalPath)
  TreePath root()
  int size()     // <.>
  TreePath append(int indexWithinSiblings)     // <.>
  TreePath subPath(int startIndex)     // <.>
  Optional<TreePath> parent()     // <.>
  boolean isRoot()
  boolean startsWith(TreePath other)
  IntStream streamPathElements()
  OptionalInt childIndex()     // <.>
  String stringify(String delimiter)
  Stream<TreePath> streamUpTheHierarchyStartingAtSelf()
  boolean equals(Object obj)
  int hashCode()
  String toString()
}
----

<.> xref:#parse_String_String[parse(String, String)]
+
--
Parses stringified tree path of format _031_ ..., as returned by _TreePath#stringify(String)_ .
--
<.> xref:#size_[size()]
+
--
Number of path-elements.
--
<.> xref:#append_int[append(int)]
<.> xref:#subPath_int[subPath(int)]
+
--
Returns a sub-path containing all the path-elements of this path, skipping startIndex number of path elements at the start.
--
<.> xref:#parent_[parent()]
+
--
Returns a TreePath instance that represents the parent path of this TreePath, if this is not the root.
--
<.> xref:#childIndex_[childIndex()]
+
--
Optionally the 2nd path-element's value, based on presence. It corresponds to the sibling index of the child node this tree-path (either directly references or) includes.
--

== Members

[#parse_String_String]
=== parse(String, String)

Parses stringified tree path of format _031_ ..., as returned by _TreePath#stringify(String)_ .

For null or empty input the root is returned.

[#size_]
=== size()

Number of path-elements.

[#append_int]
=== append(int)

[#subPath_int]
=== subPath(int)

Returns a sub-path containing all the path-elements of this path, skipping startIndex number of path elements at the start.

[#parent_]
=== parent()

Returns a TreePath instance that represents the parent path of this TreePath, if this is not the root.

[#childIndex_]
=== childIndex()

Optionally the 2nd path-element's value, based on presence. It corresponds to the sibling index of the child node this tree-path (either directly references or) includes.
