org.niffty
Class HeirarchyNode

java.lang.Object
  |
  +--org.niffty.HeirarchyNode
Direct Known Subclasses:
MeasureStartTimeSlice, MusicSymbol, Page, ScoreData, Staff, StaffSystem, TimeSlice

public class HeirarchyNode
extends java.lang.Object

A HeirarchyNode is used to manage the relationship between a parent and its child nodes in a heirarchy tree. Strict relationships are enforced. For example, you can't add an object as a child to a parent node if it already has a parent. All the methods are protected because it is expected that a class will extend this and proved access methods which deal with the correct type.


Constructor Summary
HeirarchyNode()
          Creates new HeirarchyNode with a null parent.
 
Method Summary
protected  void addChild(HeirarchyNode child)
          Add the child to the end of the child node list and set its parent to this node.
protected  HeirarchyNode getChild(int index)
          Return the child node at the given index in the child node list.
protected  int getChildCount()
          Return the number of nodes in the child node list.
protected  int getIndex()
          Return the index if this node in the parent node list, or throws a HeirarchyException if there is no parent.
protected  HeirarchyNode getParentNode()
          Return the parent in the heirarchy, or null if this is the top node.
protected  HeirarchyNode nextInHeirarchy()
          Return the next HeirarchyNode after this one at the same level in the entire heirarchy.
protected  HeirarchyNode previousInHeirarchy()
          Return the previous HeirarchyNode before this one at the same level in the entire heirarchy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HeirarchyNode

public HeirarchyNode()
Creates new HeirarchyNode with a null parent. The parent is assigned when this node is added as the child to another node.

See Also:
addChild(org.niffty.HeirarchyNode)
Method Detail

addChild

protected void addChild(HeirarchyNode child)
Add the child to the end of the child node list and set its parent to this node. It is expected that the subclass will define an add function which takes a child of the correct type.

Parameters:
child - the node to add as a child to this node. The child's parent must be null.
Throws:
HeirarchyException - if the child's parent is not null. This ensures that the child does not have two parents.

getChildCount

protected int getChildCount()
Return the number of nodes in the child node list. It is expected that a subclass will define a method with the correct method name for the child type.


getChild

protected HeirarchyNode getChild(int index)
Return the child node at the given index in the child node list. It is expected that a subclass will define a "getter" method which returns the correct class for the child.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is negative or not less than the number of nodes in the child node list.

getIndex

protected int getIndex()
Return the index if this node in the parent node list, or throws a HeirarchyException if there is no parent. To avoid the exception, you can check the parent first.

Throws:
HeirarchyException - if there is no parent

getParentNode

protected HeirarchyNode getParentNode()
Return the parent in the heirarchy, or null if this is the top node. This is called getParentNode so that a subclass can define a method called getParentClass() which returns the correct type for the class.


previousInHeirarchy

protected HeirarchyNode previousInHeirarchy()
Return the previous HeirarchyNode before this one at the same level in the entire heirarchy. Return null if this is the first one (or if there is no parent). This proceeds as follows: If there is no parent, return null. If there is a child before this one in the parent, return it, otherwise ask the parent for the previousInHeirarchy at its level. If there is none, return null. If the previous parent has children, return return its last child. Otherwise, keep asking the parent for its previousInHeirarchy until one is found with children. If none, return null.


nextInHeirarchy

protected HeirarchyNode nextInHeirarchy()
Return the next HeirarchyNode after this one at the same level in the entire heirarchy. Return null if this is the last one (or if there is no parent). This proceeds as follows: If there is no parent, return null. If there is a child after this one in the parent, return it, otherwise ask the parent for the nextInHeirarchy at its level. If there is none, return null. If the next parent has children, return return its first child. Otherwise, keep asking the parent for its nextInHeirarchy until one is found with children. If none, return null.