com.accountingenhancements.treearray
Class Tree<E>
java.lang.Object
com.accountingenhancements.treearray.Tree<E>
public class Tree<E>
- extends java.lang.Object
This is a tree implemented using ArrayList.
It contains BranchNode, LeafNode, and Leaf classes.
Each BranchNode contains an ArrayList of other BranchNodes and a LeafNode that contains Leaf entries.
The First BranchNode(Trunk) is automatically created when the tree is created.
Each BranchNode and Leaf can have attributes assigned. These attributes are stored in HashMap
s
Tree----------->(trunk)BranchNode(0)
|
|--------------------------------------|
BranchNode(0) BranchNode(1)
| |
|---------|------------| |---------------|
Leaf(0) Leaf(1) BranchNode(0) BranchNode(0) BranchNode(1)
Field Summary |
protected java.util.HashMap<java.lang.String,BranchNode<E>> |
groupName
A HashMap of names to attach names to BranchNode |
Constructor Summary |
Tree()
|
Method Summary |
TreeCrawler<E> |
createTreeCrawler()
Get a new instance of TreeCrawler that is pointing to this
trunk and is defined with the correct Generic override.
The TreeCrawler returns the Leaf objects throughout the tree. |
BranchNode<E> |
getBranchByName(java.lang.String branchName)
If a branch has been assigned a name, you can retrieve it through here. |
BranchNode<E> |
getTrunk()
|
void |
setBranchName(java.lang.String branchName,
BranchNode<E> branchNode)
Assign a name to a BranchNode for later retrieval. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
groupName
protected java.util.HashMap<java.lang.String,BranchNode<E>> groupName
- A HashMap of names to attach names to
BranchNode
Tree
public Tree()
createTreeCrawler
public TreeCrawler<E> createTreeCrawler()
- Get a new instance of
TreeCrawler
that is pointing to this
trunk and is defined with the correct Generic override.
The TreeCrawler
returns the Leaf
objects throughout the tree.
- Returns:
- a new instance of
TreeCrawler
getTrunk
public BranchNode<E> getTrunk()
- Returns:
- the first
BranchNode
class that was created when Tree
was created.
getBranchByName
public BranchNode<E> getBranchByName(java.lang.String branchName)
- If a branch has been assigned a name, you can retrieve it through here.
It is up to you to make sure no two branches have the same name when setting the names.
If the name is set to two different branches, the newest assignation will be returned.
- Returns:
- a
BranchNode
setBranchName
public void setBranchName(java.lang.String branchName,
BranchNode<E> branchNode)
- Assign a name to a BranchNode for later retrieval. Warning, Iif two
BranchNode
s have the same name,
the name will only apply to the newest assignation.
- Parameters:
branchName
- The name to assign to a branch node.branchNode
- the node to which a name is to be assigned.