Constructor and Description |
---|
TreeQuery() |
Modifier and Type | Method and Description |
---|---|
static <T,P> Optional<T> |
findByPath(TreeDef<T> treeDef,
T node,
Function<? super T,?> treeMapper,
List<P> path,
Function<? super P,?> pathMapper)
Finds a child TreeNode based on its path.
|
static <T,P> Optional<T> |
findByPath(TreeDef<T> treeDef,
T node,
List<P> path,
BiPredicate<T,P> equality)
Finds a child TreeNode based on its path.
|
static <T> Optional<T> |
findByPath(TreeDef<T> treeDef,
T node,
List<T> path,
Function<? super T,?> mapper)
Finds a child TreeNode based on its path.
|
static <T> Optional<T> |
lowestCommonAncestor(TreeDef.Parented<T> treeDef,
List<T> nodes)
Returns the common parent of N elements.
|
static <T> Optional<T> |
lowestCommonAncestor(TreeDef.Parented<T> treeDef,
T... nodes)
Returns the common parent of N elements.
|
static <T> String |
path(TreeDef.Parented<T> treeDef,
T node)
Returns the path of the given node, using
/ as the path delimiter and Object.toString() as the mapping function. |
static <T> String |
path(TreeDef.Parented<T> treeDef,
T node,
Function<? super T,String> toString)
Returns the path of the given node, using
/ as the path delimiter. |
static <T> String |
path(TreeDef.Parented<T> treeDef,
T node,
Function<? super T,String> toString,
String delimiter)
Returns the path of the given node.
|
static <T> List<T> |
toParent(TreeDef.Parented<T> treeDef,
T node,
T parent)
Creates a mutable list whose first element is
node , and last element is parent . |
static <T> List<T> |
toRoot(TreeDef.Parented<T> treeDef,
T node)
Creates a mutable list whose first element is
node , and last element is its root parent. |
static <T> String |
toString(TreeDef<T> treeDef,
T root)
Converts the entire tree into a string-based representation.
|
static <T> String |
toString(TreeDef<T> treeDef,
T root,
Function<? super T,String> toString)
Converts the entire tree into a string-based representation.
|
static <T> String |
toString(TreeDef<T> treeDef,
T root,
Function<? super T,String> toString,
String indent)
Converts the entire tree into a string-based representation.
|
public static <T> List<T> toRoot(TreeDef.Parented<T> treeDef, T node)
node
, and last element is its root parent.public static <T> List<T> toParent(TreeDef.Parented<T> treeDef, T node, T parent)
node
, and last element is parent
.IllegalArgumentException
- if parent
is not a parent of node
@SafeVarargs public static <T> Optional<T> lowestCommonAncestor(TreeDef.Parented<T> treeDef, T... nodes)
public static <T> Optional<T> lowestCommonAncestor(TreeDef.Parented<T> treeDef, List<T> nodes)
public static <T> String path(TreeDef.Parented<T> treeDef, T node, Function<? super T,String> toString, String delimiter)
treeDef
- the treeDefnode
- the root of the treetoString
- a function to map each node to a string in the pathdelimiter
- a string to use as a path separatorpublic static <T> String path(TreeDef.Parented<T> treeDef, T node, Function<? super T,String> toString)
/
as the path delimiter.public static <T> String path(TreeDef.Parented<T> treeDef, T node)
/
as the path delimiter and Object.toString()
as the mapping function.public static <T,P> Optional<T> findByPath(TreeDef<T> treeDef, T node, List<P> path, BiPredicate<T,P> equality)
Searches the child nodes for the first element, then that node's children for the second element, etc.
treeDef
- defines a treenode
- starting point for the searchpath
- the path of nodes which we're lookingequality
- a function for determining equality between the tree nodes and the path elementspublic static <T,P> Optional<T> findByPath(TreeDef<T> treeDef, T node, Function<? super T,?> treeMapper, List<P> path, Function<? super P,?> pathMapper)
Searches the child nodes for the first element, then that node's children for the second element, etc.
treeDef
- defines a treenode
- starting point for the searchtreeMapper
- maps elements in the tree to some value for comparison with the path elementspath
- the path of nodes which we're lookingpathMapper
- maps elements in the path to some value for comparison with the tree elementspublic static <T> Optional<T> findByPath(TreeDef<T> treeDef, T node, List<T> path, Function<? super T,?> mapper)
Searches the child nodes for the first element, then that node's children for the second element, etc.
treeDef
- defines a treenode
- starting point for the searchpath
- the path of nodes which we're lookingmapper
- maps elements to some value for comparison between the tree and the pathpublic static <T> String toString(TreeDef<T> treeDef, T root)
public static <T> String toString(TreeDef<T> treeDef, T root, Function<? super T,String> toString)
public static <T> String toString(TreeDef<T> treeDef, T root, Function<? super T,String> toString, String indent)
treeDef
- the treeDefroot
- the root of the treetoString
- the function which generates the name for each node in the treeindent
- the string to use for each level of indentation