public class LibraryTree<IDENT,T extends TreeNode<IDENT,T>> extends Object
This tree can have multiple roots and internally its structure is layered. The details are :
| Modifier and Type | Class and Description |
|---|---|
static class |
LibraryTree.SimpleNode<T> |
class |
LibraryTree.TreeNodePair
A TreeNodePair is a scaffolding class which is mainly used when initializing a tree.
|
| Constructor and Description |
|---|
LibraryTree() |
| Modifier and Type | Method and Description |
|---|---|
void |
addNode(IDENT parentKey,
T childNode)
Same than
addNode(TreeNodePair), but the TreeNodePair parameter will be built using the parameter provided here. |
void |
addNode(LibraryTree.TreeNodePair newPair)
Given a TreeNodePair (see documentation of the inner class for details), will add the child node to the tree.
|
void |
addNodes(List<LibraryTree.TreeNodePair> unsortedFlatTree)
Accepts a list of TreeNodePair and will add all the nodes in that list (see TreeNodePair and TreeNode).
|
<X> List<X> |
collect(org.apache.commons.collections.Transformer transformer)
That method will gather arbitrary informations on every single nodes and return the list of the gathered informations.
|
List<IDENT> |
collectKeys()
short hand for
collect(Transformer) with a Transformer returning the data.key for each nodes. |
protected T |
createNewNode(T parent,
int depth,
T newNode) |
void |
cut(IDENT key)
removes a node and its subtree
|
void |
doBottomUp(org.apache.commons.collections.Closure closure)
Accepts a
Closure that will be applied on the nodes using bottom-up exploration. |
void |
doTopDown(org.apache.commons.collections.Closure closure)
Accepts a
Closure that will be applied on the nodes using top-down exploration. |
List<T> |
getAllNodes() |
int |
getDepth()
return the depth of the tree, ie how many layers does the tree count.
|
List<T> |
getLayer(Integer depth)
Given an integer, returns the layer at the corresponding depth in the tree.
|
List<T> |
getLeaves() |
T |
getNode(IDENT key)
Accepts a identifier - aka key - and returns the corresponding node if found.
|
List<T> |
getRootNodes() |
boolean |
mayRemove(IDENT key)
Says whether the given node may be
removed (ie it has no children)
|
void |
merge(List<T> mergeData)
Accepts a list of TreeNodes and use their data to update existing nodes data.
|
LibraryTree.TreeNodePair |
newPair()
Returns a new instance of a TreeNodePair.
|
LibraryTree.TreeNodePair |
newPair(IDENT parentKey,
T child)
An initializing version of
newPair(). |
void |
remove(IDENT key)
Will remove the node having this key if it is childress.
|
public List<T> getLayer(Integer depth)
getDepth().
The layer is returned as a list of nodes.depth - the depth of the layer we want an access to.IndexOutOfBoundsExceptionpublic void addNode(LibraryTree.TreeNodePair newPair)
newPair - a TreeNodePair with informations regarding parent and child node included.NoSuchElementException - if a parent node cannot be found.public void addNode(IDENT parentKey, T childNode)
addNode(TreeNodePair), but the TreeNodePair parameter will be built using the parameter provided here.parentKey - the key designating the parent node.childNode - the child we want eventually to insert.public void addNodes(List<LibraryTree.TreeNodePair> unsortedFlatTree)
unsortedData - the flat representation of the tree.#sortData(List)}, TreeNode, TreeNodePairpublic T getNode(IDENT key)
key - the key identifying a nodeNoSuchElementException - if the node was not found.public void doBottomUp(org.apache.commons.collections.Closure closure)
Accepts a Closure that will be applied on the nodes using bottom-up exploration. The method will walk up the tree :
closure - code to apply on the nodes.public void doTopDown(org.apache.commons.collections.Closure closure)
Accepts a Closure that will be applied on the nodes using top-down exploration. The method will walk down the tree :
closure - code to apply on the nodes.public void merge(List<T> mergeData)
Accepts a list of TreeNodes and use their data to update existing nodes data. The TreeNodes of the input list are merely carrying informations : the key property will identify actual nodes in the tree and the rest of their data will be used to update the found nodes.
The particulars of how data will be merged depends on how the TreeNodes implement TreeNode.updateWith(TreeNode).
NoSuchElementException - if one of the node was not found.public <X> List<X> collect(org.apache.commons.collections.Transformer transformer)
That method will gather arbitrary informations on every single nodes and return the list of the gathered informations. What will be gathered and how it is done is defined in the
Transformer parameter. The tree will be processed top-down, ie, walked down (see doTopDown(Closure)).
X - the type of the data returned by the transformer.transformer - the code to be applied over all the nodes.public List<IDENT> collectKeys()
short hand for collect(Transformer) with a Transformer returning the data.key for each nodes.
public boolean mayRemove(IDENT key)
key - public void remove(IDENT key)
key - public void cut(IDENT key)
key - public int getDepth()
public LibraryTree.TreeNodePair newPair()
public LibraryTree.TreeNodePair newPair(IDENT parentKey, T child)
newPair().parentKey - the identifier of the parent node.child - the child node.Copyright © 2010–2016 Henix, henix.fr. All rights reserved.