Constructor and Description |
---|
TreeQuery() |
Modifier and Type | Method and Description |
---|---|
static <T,CopyType> |
copyLeavesIn(TreeDef<T> def,
T root,
BiFunction<T,List<CopyType>,CopyType> nodeMapper)
Copies the given tree of T to CopyType, starting at the leaf nodes
of the tree and moving in to the root node, which allows CopyType to
be immutable (but does not require it).
|
static <T,CopyType> |
copyRootOut(TreeDef<T> def,
T root,
BiFunction<T,CopyType,CopyType> mapper)
Copies the given tree of T to CopyType, starting at the root node
of the tree and moving out to the leaf nodes, which generally requires
CopyType to be mutable (if you want CopyType nodes to know who their
children are).
|
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> boolean |
isDescendantOf(TreeDef.Parented<T> treeDef,
T child,
T parent)
Returns true iff child is a descendant of parent.
|
static <T> boolean |
isDescendantOfOrEqualTo(TreeDef.Parented<T> treeDef,
T child,
T parent)
Returns true iff child is a descendant of parent, or if child is equal to parent.
|
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> T |
root(TreeDef.Parented<T> treeDef,
T node)
Returns the root of the given tree.
|
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> boolean isDescendantOf(TreeDef.Parented<T> treeDef, T child, T parent)
public static <T> boolean isDescendantOfOrEqualTo(TreeDef.Parented<T> treeDef, T child, T parent)
public static <T> T root(TreeDef.Parented<T> treeDef, T node)
public static <T> List<T> toRoot(TreeDef.Parented<T> treeDef, T node)
node
, and last element is its root parent.public static <T,CopyType> CopyType copyLeavesIn(TreeDef<T> def, T root, BiFunction<T,List<CopyType>,CopyType> nodeMapper)
def
- defines the structure of the treeroot
- root of the treenodeMapper
- given an unmapped node, and a list of CopyType nodes which have already been mapped, return a mapped node.public static <T,CopyType> CopyType copyRootOut(TreeDef<T> def, T root, BiFunction<T,CopyType,CopyType> mapper)
def
- defines the structure of the treeroot
- root of the treenodeMapper
- given an unmapped node, and a parent CopyType which has already been mapped, return a mapped node.
This function must have the side effect that the returned node should be added as a child of its
parent node.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