|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.accountingenhancements.treearray.TreeCrawler<E>
public class TreeCrawler<E>
Crawl through all leaves of all branches in tree.
Leaves of the current branch are iterated through first before the branches.
The nextLeaf() method returns all leaves within the current branch before going into the next branch.
Once that branch is fully processed, the next branch is processed until all branches are completed.
When getNextLeaf() returns null the TreeCrawler
will automatically jump to the next branch.
Use getDepth()
to gauge how deep you are.
Use jumpedDeeper()
to determine whether you jumped deeper when jumping from last time
(Useful in combo with justJumpedBranches()
layout a similar structure using simple logic).
Use justJumpedBranches()
to determine whether a getNextLeaf()==null is really a null value
or is because we ran out of leaves and jumped to a new branch (Next access to getNextLeaf() after a jump will set this back to false).
Use endOfTree()
to determine whether the whole tree has been traversed.
Field Summary | |
---|---|
protected BranchNode<E> |
branchNode
|
protected java.util.ArrayList<BranchNode<E>> |
branchPath
|
protected int |
depth
|
protected boolean |
endOfTree
|
protected boolean |
jumpedDeeper
|
protected boolean |
justJumpedBranches
|
protected int |
leafIndex
|
protected java.util.ArrayList<java.lang.Integer> |
path
|
protected int |
prevDepth
|
protected BranchNode<E> |
trunkBranchNode
|
Constructor Summary | |
---|---|
TreeCrawler(BranchNode<E> branchNode)
Creates a new instance of TreeCrawler |
Method Summary | |
---|---|
boolean |
endOfTree()
Determine whether the entire tree has been traversed. |
int |
getDepth()
Returns the depth of the curent BranchNode. The starting branch is 0. |
E |
getNextLeaf()
Get the next leaf from the current branch. If a null is returned, then we may have run out of leaves on the branch and have now jumped to a new branch. Use justJumpedBranches to determine whether the current leaf really was null or whether we just jumped to a new branch. |
java.util.ArrayList<java.lang.Integer> |
getPath()
|
int |
getPrevDepth()
Used in conjunction with getDepth() to determine how far the last jump between branches was.If it is the same as the current depth, then the last jump went back 1 BranchNode then forward again on the next branch.This value only gets updated by nextBranchNode() , not prevBranchNode since
nextBranchNode() may call prevBranchNode() which would, otherwise, make the value meaningless. |
boolean |
jumpedDeeper()
Used to determine whether class is contining down the current set of branches or whether it backtracked. Note: level could stay the same if backing up to the previous branch and then moving forward again on the next branch down. You can use level to determine just how far you moved. |
void |
jumpToBeforeFirstLeaf()
Reset the current BranchNode index so that the first leaf is returned from getNextLeaf() . |
void |
jumptoLastLeaf()
Jump to last leaf so that getNextLeaf() returns null and causes the class to jump to the next branch. |
boolean |
justJumpedBranches()
|
boolean |
nextBranchNode()
Jump to the next available branch. |
protected boolean |
nextBranchNodeInternal()
Mose of nextBranchNode() is here so that prevDepth()
doesn't get overridden by prevBranchNode() when it moves backward, then forward again. |
boolean |
prevBranchNode()
Stop going down the current branch path and continue as if this were the end of a branch. Ususally called because we were at the end of one of a branch. |
void |
reset()
Reset this class to the beginning of the trunk so that we can start over (as if the class were just created). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected transient int depth
protected transient int prevDepth
protected transient java.util.ArrayList<java.lang.Integer> path
protected transient java.util.ArrayList<BranchNode<E>> branchPath
protected transient boolean jumpedDeeper
protected transient boolean justJumpedBranches
protected transient int leafIndex
protected transient BranchNode<E> branchNode
protected transient boolean endOfTree
protected BranchNode<E> trunkBranchNode
Constructor Detail |
---|
public TreeCrawler(BranchNode<E> branchNode)
branchNode
- is the BranchNode
to be processed. Usually is tree.getTrunk()Method Detail |
---|
public int getDepth()
public int getPrevDepth()
getDepth()
to determine how far the last jump between branches was.BranchNode
then forward again on the next branch.nextBranchNode()
, not prevBranchNode
since
nextBranchNode()
may call prevBranchNode()
which would, otherwise, make the value meaningless.
nextBranchNode()
was last executed.public java.util.ArrayList<java.lang.Integer> getPath()
branchNode
[0]=index of branch off of original brachNode.
-1 means that no branches have been processed off of the BranchNode
public void reset()
public void jumpToBeforeFirstLeaf()
BranchNode
index so that the first leaf is returned from getNextLeaf()
.
public void jumptoLastLeaf()
getNextLeaf()
returns null and causes the class to jump to the next branch.
public boolean nextBranchNode()
protected boolean nextBranchNodeInternal()
nextBranchNode()
is here so that prevDepth()
doesn't get overridden by prevBranchNode()
when it moves backward, then forward again.
public boolean prevBranchNode()
public E getNextLeaf()
justJumpedBranches
to determine whether the current leaf really was null or whether we just jumped to a new branch.
Also use endOfTree()
to determine whether you have traversed the entire tree.
public boolean justJumpedBranches()
getNextLeaf()
method caused this class to jump to a new branch.getNextLeaf()
will return the first leaf of the new branch.endOfTree()
. This should return false if at
end of tree unless you arrived there by using nextbranchNode()
or prevBranchNode
instead of getNextLeaf()
(which is responsible for setting justJumpedBranches=false).public boolean jumpedDeeper()
BranchNode
.public boolean endOfTree()
justJumedBranches()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |