com.accountingenhancements.treearray
Class BranchNode<F>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<BranchNode<F>>
              extended by com.accountingenhancements.treearray.BranchNode<F>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<BranchNode<F>>, java.util.Collection<BranchNode<F>>, java.util.List<BranchNode<F>>, java.util.RandomAccess

public class BranchNode<F>
extends java.util.ArrayList<BranchNode<F>>

This class implements a tree branch and leaf structure.
It contains other BranchNodes and a LeafNode object.
It is implemented using ArrayList

See Also:
Serialized Form

Field Summary
protected  java.util.HashMap<java.lang.String,java.lang.Object> attributes
           
protected  int depth
           
protected  LeafNode<F> leafNode
           
protected  BranchNode<F> parent
           
protected  Tree<F> tree
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
BranchNode(BranchNode<F> parent)
          Creates a BranchNode Array of other BranchNode as well as a LeafNode array.
Constructs an empty list with an initial capacity of ten and an empty LeafNode list with an initial capacity of 10.
BranchNode(int initialCapacity, int initialLeafCapacity, BranchNode<F> parent)
          Constructs an empty BranchNode with the specified initial capacity.
 
Method Summary
 BranchNode<F> addLeaf(F leaf)
          Appends the specified Element to the end the LeafNode list.
Same as leafAdd(F leaf)
 BranchNode<F> addLeaf(int index, F leaf)
          Inserts the specified Element at the specified position in the LeafNode list.
 BranchNode<F> addLeaf(Leaf<F> leaf)
          Appends the specified Leaf to the end the LeafNode list.
Use this if you want to create the leaf itself.
Note: if you want set attributes on the Leaf you can chain the attributes to the new Leaf<>() constructor because Leaf<>().setAttribute returns the Leaf<> again.
branchNode.addLead(new Leaf(component).setAttribute("horizontalPref",20).setAttribute("verticalPref",7));
Same as leafAdd(Leaf leaf)
 void clearLeafNode()
          Removes all of the elements from the LeafNode list.
 BranchNode<F> createNewBranchNode()
          Create as new BranchNode entry and return it.
The new class will be cast to the correct class.
 BranchNode<F> createNewBranchNode(java.lang.String branchName)
          Create as new BranchNode entry and return it.
The new class will be cast to the correct class.
 java.lang.Object getAttribute(java.lang.String attribute)
          Get previously set attributes
 java.util.HashMap<java.lang.String,java.lang.Object> getAttributeHashMap()
          Get the entire attribute HashMap so that the rest of the methods are accessable.
 int getDepth()
           
 F getLeaf(int index)
          Returns the element at the specified position in the LeafNode list.
Same as leafGet(int index)
 java.lang.Object getLeafAttribute(int index, java.lang.String attribute)
          Retrieves a previously set attribute for the specified leaf
 LeafNode<F> getLeafNode()
          Get the Underlying LeafNode list
 BranchNode<F> getParent()
          Get the parent BranchNode.
 Tree<F> getTree()
           
 BranchNode<F> leafAdd(F leaf)
          Appends the specified Element to the end the LeafNode list.
Same as getLeaf(int index)
 BranchNode<F> leafAdd(int index, F leaf)
          Inserts the specified Element at the specified position in the LeafNode list.
 BranchNode<F> leafAdd(Leaf<F> leaf)
          Appends the specified leaf to the end the LeafNode list.
Note: if you want set attributes on the Leaf you can chain the attributes to the new Leaf<>() constructor because Leaf<>().setAttribute returns the Leaf<> again.
branchNode.addLead(new Leaf(component).setAttribute("horizontalPref",20).setAttribute("verticalPref",7));
Same as addLleaf(Leaf leaf)
 F leafGet(int index)
          Returns the element at the specified position in the LeafNode list.
same as getLeaf(int index)
 int leafIndexOf(F elem)
          Searches for the first occurence of the given argument in the LeafNode list, testing for equality using the equals method.
 int leafLastIndexOf(F elem)
          Returns the index of the last occurrence of the specified object in the LeafNode list.
 void leafNodeClear()
          Removes all of the elements from the LeafNode list.
 boolean leafNodeContains(F elem)
          Returns true if the LeafNode contains the specified element.
 void leafNodeEnsureCapacity(int minCapacity)
          Increases the capacity of the LeafNode list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 boolean leafNodeIsEmpty()
          Tests if The LeafNode list has no Objects.
 int leafNodeSize()
          Returns the number of JComponents in the LeafNode list.
 java.lang.Object[] leafNodeToArray()
          Returns an array containing all of the elements in the LeafNode list in the correct order.
 F[] leafNodeToArray(F[] a)
          Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
 boolean leafRemove(F o)
          Removes a single instance of the specified element from the LeafNode list, if it is present (optional operation).
 F leafRemove(int index)
          Removes the element at the specified position in the LeafNode list.
 boolean leafRemove(Leaf<F> o)
          Removes a single instance of the specified leaf from the LeafNode list, if it is present (optional operation).
 F leafSet(int index, F element)
          Replaces the element at the specified position in the LeafNode list with the specified element.
Same as setLeaf(int index, F element)
 boolean removeLeaf(F o)
          Removes a single instance of the specified element from the LeafNode list, if it is present (optional operation).
 F removeLeaf(int index)
          Removes the element at the specified position in the LeafNode list.
 boolean removeLeaf(Leaf<F> o)
          Removes a single instance of the specified leaf from the LeafNode list, if it is present (optional operation).
 BranchNode<F> setAttribute(java.lang.String attribute, java.lang.Object value)
          Set attributes relating to this branch.
 F setLeaf(int index, F element)
          Replaces the element at the specified position in the LeafNode list with the specified element.
Same as leafSet(int index, F element)
 void setLeafAttribute(int index, java.lang.String attribute, java.lang.Object value)
          Adds or overwrites an attribute for the specified leat at the specified position in this list.
 void setLeafNode(LeafNode<F> leafNode)
          Replace the LeafNode list
 void setTree(Tree<F> tree)
          Tree to which this Branch Node belongs.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

attributes

protected transient java.util.HashMap<java.lang.String,java.lang.Object> attributes

leafNode

protected transient LeafNode<F> leafNode

parent

protected BranchNode<F> parent

tree

protected Tree<F> tree

depth

protected int depth
Constructor Detail

BranchNode

public BranchNode(int initialCapacity,
                  int initialLeafCapacity,
                  BranchNode<F> parent)
Constructs an empty BranchNode with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
initialLeafCapacity - the initial capacity of the LeafNode list
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

BranchNode

public BranchNode(BranchNode<F> parent)
Creates a BranchNode Array of other BranchNode as well as a LeafNode array.
Constructs an empty list with an initial capacity of ten and an empty LeafNode list with an initial capacity of 10.

Method Detail

setTree

public void setTree(Tree<F> tree)
Tree to which this Branch Node belongs. This shouldn't be used except for the creation of the first branch by the tree itself.

Parameters:
tree - the tree to which this BranchNode belongs

getTree

public Tree<F> getTree()
Returns:
the tree to which this BranchNode belongs.

getParent

public BranchNode<F> getParent()
Get the parent BranchNode. null means that this is the trunk.


getDepth

public int getDepth()
Returns:
the depth from the trunk of the tree. 0 means that we are at the trunk.

setAttribute

public BranchNode<F> setAttribute(java.lang.String attribute,
                                  java.lang.Object value)
Set attributes relating to this branch. Attributes are stored in a HashMap

Parameters:
attribute - name
value - of attribute
Returns:
the BranchNode object so setAttributes() can be chained together.

getAttribute

public java.lang.Object getAttribute(java.lang.String attribute)
Get previously set attributes

Parameters:
attribute - name
Returns:
Object the attribute value

getAttributeHashMap

public java.util.HashMap<java.lang.String,java.lang.Object> getAttributeHashMap()
Get the entire attribute HashMap so that the rest of the methods are accessable.

Returns:
the attributes HashMap

leafNodeEnsureCapacity

public void leafNodeEnsureCapacity(int minCapacity)
Increases the capacity of the LeafNode list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

leafNodeSize

public int leafNodeSize()
Returns the number of JComponents in the LeafNode list.

Returns:
the number of JComponents in this list.

leafNodeIsEmpty

public boolean leafNodeIsEmpty()
Tests if The LeafNode list has no Objects.

Returns:
true if this list has no elements; false otherwise.

leafNodeContains

public boolean leafNodeContains(F elem)
Returns true if the LeafNode contains the specified element.

Parameters:
elem - element whose presence in this List is to be tested.
Returns:
true if the specified element is present; false otherwise.

leafIndexOf

public int leafIndexOf(F elem)
Searches for the first occurence of the given argument in the LeafNode list, testing for equality using the equals method.

Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
See Also:
Object.equals(Object)

leafLastIndexOf

public int leafLastIndexOf(F elem)
Returns the index of the last occurrence of the specified object in the LeafNode list.

Parameters:
elem - the desired element.
Returns:
the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.

leafNodeToArray

public java.lang.Object[] leafNodeToArray()
Returns an array containing all of the elements in the LeafNode list in the correct order.

Returns:
an array containing all of the elements in this list in the correct order.

leafNodeToArray

public F[] leafNodeToArray(F[] a)
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.

Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the list.
Throws:
java.lang.ArrayStoreException - if the runtime type of a is not a supertype of the runtime type of every element in this list.

leafGet

public F leafGet(int index)
Returns the element at the specified position in the LeafNode list.
same as getLeaf(int index)

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

getLeaf

public F getLeaf(int index)
Returns the element at the specified position in the LeafNode list.
Same as leafGet(int index)

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

leafSet

public F leafSet(int index,
                 F element)
Replaces the element at the specified position in the LeafNode list with the specified element.
Same as setLeaf(int index, F element)

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

setLeaf

public F setLeaf(int index,
                 F element)
Replaces the element at the specified position in the LeafNode list with the specified element.
Same as leafSet(int index, F element)

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

leafAdd

public BranchNode<F> leafAdd(F leaf)
Appends the specified Element to the end the LeafNode list.
Same as getLeaf(int index)

Parameters:
leaf - element to be appended to this list.
Returns:
this BranchNode so that you can chain the adds together

addLeaf

public BranchNode<F> addLeaf(F leaf)
Appends the specified Element to the end the LeafNode list.
Same as leafAdd(F leaf)

Parameters:
leaf - element to be appended to this list.
Returns:
this BranchNode so that you can chain the adds together

addLeaf

public BranchNode<F> addLeaf(Leaf<F> leaf)
Appends the specified Leaf to the end the LeafNode list.
Use this if you want to create the leaf itself.
Note: if you want set attributes on the Leaf you can chain the attributes to the new Leaf<>() constructor because Leaf<>().setAttribute returns the Leaf<> again.
branchNode.addLead(new Leaf(component).setAttribute("horizontalPref",20).setAttribute("verticalPref",7));
Same as leafAdd(Leaf leaf)

Parameters:
leaf - element to be appended to this list.
Returns:
this BranchNode so that you can chain the adds together

leafAdd

public BranchNode<F> leafAdd(Leaf<F> leaf)
Appends the specified leaf to the end the LeafNode list.
Note: if you want set attributes on the Leaf you can chain the attributes to the new Leaf<>() constructor because Leaf<>().setAttribute returns the Leaf<> again.
branchNode.addLead(new Leaf(component).setAttribute("horizontalPref",20).setAttribute("verticalPref",7));
Same as addLleaf(Leaf leaf)

Parameters:
leaf - element to be appended to this list.
Returns:
this BranchNode so that you can chain the adds together

leafAdd

public BranchNode<F> leafAdd(int index,
                             F leaf)
Inserts the specified Element at the specified position in the LeafNode list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
Same as addLeaf(int index, F leaf)

Parameters:
index - index at which the specified element is to be inserted.
leaf - leaf to be inserted.
Returns:
this BranchNode so that you can chain the adds together
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).

addLeaf

public BranchNode<F> addLeaf(int index,
                             F leaf)
Inserts the specified Element at the specified position in the LeafNode list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
Same as leafAdd(int index, F leaf)

Parameters:
index - index at which the specified element is to be inserted.
leaf - leaf to be inserted.
Returns:
this BranchNode so that you can chain adds together
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).

leafRemove

public F leafRemove(int index)
Removes the element at the specified position in the LeafNode list. Shifts any subsequent elements to the left (subtracts one from their indices).
Same as removeLeaf(int index)

Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

removeLeaf

public F removeLeaf(int index)
Removes the element at the specified position in the LeafNode list. Shifts any subsequent elements to the left (subtracts one from their indices).
Same as leafRemove(int index)

Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
java.lang.IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

leafRemove

public boolean leafRemove(F o)
Removes a single instance of the specified element from the LeafNode list, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the list contains one or more such elements. Returns true if the list contained the specified element (or equivalently, if the list changed as a result of the call).

Sames as removeLeaf(F o)

Parameters:
o - element to be removed from this list, if present.
Returns:
true if the list contained the specified element.

removeLeaf

public boolean removeLeaf(F o)
Removes a single instance of the specified element from the LeafNode list, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the list contains one or more such elements. Returns true if the list contained the specified element (or equivalently, if the list changed as a result of the call).

Same as leafRemove(F o)

Parameters:
o - element to be removed from this list, if present.
Returns:
true if the list contained the specified element.

leafRemove

public boolean leafRemove(Leaf<F> o)
Removes a single instance of the specified leaf from the LeafNode list, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the list contains one or more such elements. Returns true if the list contained the specified element (or equivalently, if the list changed as a result of the call).

Sames as removeLeaf(Leaf o)

Parameters:
o - leaf to be removed from this list, if present.
Returns:
true if the list contained the specified element.

removeLeaf

public boolean removeLeaf(Leaf<F> o)
Removes a single instance of the specified leaf from the LeafNode list, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the list contains one or more such elements. Returns true if the list contained the specified element (or equivalently, if the list changed as a result of the call).

Same as leafRemove(Leaf o)

Parameters:
o - leaf to be removed from this list, if present.
Returns:
true if the list contained the specified element.

leafNodeClear

public void leafNodeClear()
Removes all of the elements from the LeafNode list. The list will be empty after this call returns.
Same as clearLeafNode


clearLeafNode

public void clearLeafNode()
Removes all of the elements from the LeafNode list. The list will be empty after this call returns.
Same as leafNodeClear()


getLeafNode

public LeafNode<F> getLeafNode()
Get the Underlying LeafNode list

Returns:
theLeafNodes list (Extends ArrayList)

setLeafNode

public void setLeafNode(LeafNode<F> leafNode)
Replace the LeafNode list

Parameters:
leafNode - the newLeafNodes list

createNewBranchNode

public BranchNode<F> createNewBranchNode(java.lang.String branchName)
Create as new BranchNode entry and return it.
The new class will be cast to the correct class. This way code that handles the BranchNode doesn't need to know what the Generic was cast.
Note: The branch node is automatically added to this branch node.

Parameters:
branchName - a branch name to help rapidly identify this branch again from the Tree class.
Returns:
the branch node that was created

createNewBranchNode

public BranchNode<F> createNewBranchNode()
Create as new BranchNode entry and return it.
The new class will be cast to the correct class. This way code that handles the BranchNode doesn't need to know what the Generic was cast.
Note: The branch node is automatically added to this branch node.

Returns:
the branch node that was created

setLeafAttribute

public void setLeafAttribute(int index,
                             java.lang.String attribute,
                             java.lang.Object value)
Adds or overwrites an attribute for the specified leat at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
attribute - attribute name
value - attribute value to be added
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).

getLeafAttribute

public java.lang.Object getLeafAttribute(int index,
                                         java.lang.String attribute)
Retrieves a previously set attribute for the specified leaf

Parameters:
index - index at which the specified attribute is to be retrieved.
attribute - attribute name
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).