gps.core
Class HierarchyNode

java.lang.Object
  extended by gps.core.GPSNode
      extended by gps.core.HierarchyNode
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class HierarchyNode
extends GPSNode
implements java.lang.Cloneable, java.io.Serializable

A HierarchyNode is a general-purpose node in a tree data structure.

A tree node may have at most one parent and 0 or more children. HierarchyNode provides operations for examining and modifying a node's parent and children and also operations for examining the tree that the node is a part of. A node's tree is the set of all nodes that can be reached by starting at the node and following all the possible links to parents and children. A node with no parent is the root of its tree; a node with no children is a leaf. A tree may consist of many subtrees, each node acting as the root for its own subtree.

This class provides enumerations for efficiently traversing a tree or subtree in various orders or for following the path between two nodes. A HierarchyNode may also hold a reference to a user object, the use of which is left to the user. Asking a HierarchyNode for its string representation with toString() returns the string representation of its user object.

This is not a thread safe class.If you intend to use a HierarchyNode (or a tree of TreeNodes) in more than one thread, you need to do your own synchronizing. A good convention to adopt is synchronizing on the root node of a tree.

While HierarchyNode implements the HierarchyNode interface and will allow you to add in any implementation of HierarchyNode not all of the methods in HierarchyNode will be applicable to all MutableTreeNodes implementations. Especially with some of the enumerations that are provided, using some of these methods assumes the HierarchyNode contains only DefaultMutableNode instances. All of the HierarchyNode/HierarchyNode methods will behave as defined no matter what implementations are added.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.

Version:
1.00 4th July 2001
Author:
Rajgopal Ramani
See Also:
Serialized Form

Field Summary
static int NODE_COLLAPSE
           
static int NODE_EXPAND
           
static int NODE_NORMAL
          variable which represent what kind of view mode a node can have
static int RELATION_CHILD
           
static int RELATION_PARENT
          variables which represent what kind of relation a node can have values are given based on Model Architect
 
Fields inherited from class gps.core.GPSNode
ACD_FLAG_ADD, ACD_FLAG_CHANGE, ACD_FLAG_DELETE, ACD_FLAG_NOCHANGE, ALTERNATE_AND_PARENT, ALTERNATE_ONLY, CHILD_AND_ALTERNATE, CHILD_AND_ALTERNATE_AND_PARENT, CHILD_AND_PARENT, CHILD_ONLY, COMPLETE_DATA, CREATED_BY_ERP, CREATED_BY_USER, createdBy, EMPTY_ENUMERATION, HIERARCHY_NODE, NEXT_ONLY, NONE, PARENT_ONLY, PARTIAL_DATA, PREVIOUS_AND_NEXT, PREVIOUS_ONLY, PROCESS_NODE
 
Constructor Summary
HierarchyNode()
          Creates a tree node that has no parent and no children, but which allows children.
HierarchyNode(java.lang.Object userObject)
          Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.
HierarchyNode(java.lang.Object userObject, boolean allowsChildren)
          Creates a tree node with no parent, no children, initialized with the specified user object, and that allows children only if specified.
HierarchyNode(java.lang.String name)
           
 
Method Summary
 void addAlternate(HierarchyNode newAlternate)
           
 void addAlternateAt(HierarchyNode newAlternate, int index)
          method added by lavanya kumar chinta on 01202002 adds alternate at specified position
 void addChild(HierarchyNode newChild)
          Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.
 void addChildAt(HierarchyNode newChild, int index)
          method added by lavanya kumar chinta on 01202002 adds child at specified position
 void addToParentNodesVector(HierarchyNode parentNode)
           
 java.lang.Object clone()
           
 boolean getAllowsChildren()
          Returns true if this node is allowed to have children.
 HierarchyNode getAlternateAt(int index)
           
 int getAlternateIndex(HierarchyNode alternateNode)
           
 java.util.Enumeration getAlternates()
           
 int getAlternatesCount()
           
 java.util.Vector getAlternateVector()
          gets alternate vector
 boolean getAvailableInPath()
          gets available in path flag for this node
 HierarchyNode getChildAt(int index)
          Returns the child at the specified index in this node's child array.
 int getChildCount()
          Returns the number of children of this node.
 int getChildIndex(HierarchyNode aChild)
          Returns the index of the specified child in this node's child array.
 java.util.Enumeration getChildrens()
          Creates and returns a forward-order enumeration of this node's children.
 java.util.Vector getChildVector()
          gets child nodes
 int getCreatedBy()
          gets who created the node
 boolean getLegIncrementedFlag()
           
 int getLegIndex()
           
 int getLevelIndex()
           
 int getMode()
           
 int getNodeNumber()
           
 GPSNode getParent()
          Returns this node's parent or null if this node has no parent.
 java.util.Vector getParentNodesVector()
           
 int getPathKey()
          Returns path key
 int getPosition()
          code added by lavanya on 02182002 gets position in the list of nodes to its parent/primary/child
 GPSNode getPrimaryNode()
          written by lavanya gets the primary node reference, if the node is alternate node
 boolean getRelationalORType()
          gets relational OR type flag, whether the node having OR Type relation with it's sibblings or not
 java.lang.String getRelationName()
           
 int getRelationTypeID()
           
 HierarchyNode getSecondaryParentAt(int index)
          method added by lavanya on 01242002
 int getSecondaryParentCount()
          method added by lavanya on 01242002 gets secondary parent nodes count
 boolean getSecondaryParentFlag()
           
 void insertAlternate(HierarchyNode newAlternate, int alternateIndex)
           
 void insertChild(HierarchyNode newChild, int childIndex)
          method modified by lavanya on 03142002 Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex.
 boolean isAlternate()
           
 void remove(HierarchyNode aChild)
          Removes aChild from this node's child array, giving it a null parent.
 void removeAllAlternates()
           
 void removeAllChildren()
          Removes all of this node's children, setting their parents to null.
 void removeAlternate(int alternateIndex)
           
 void removeChild(int childIndex)
          Removes the child at the specified index from this node's children and sets that node's parent to null.
 void removeFromParent()
          Removes the subtree rooted at this node from the tree, giving this node a null parent.
 void setAllowsChildren(boolean allows)
          Determines whether or not this node is allowed to have children.
 void setAlternateFlag(boolean alternateFlag)
           
 void setAlternates(java.util.Vector alternates)
           
 void setAvailableInPath(boolean availableInPath)
          sets available in path flag for this node
 void setChildrens(java.util.Vector children)
           
 void setCreatedBy(int createdBy)
          sets who created the node
 void setLegIncrementedFlag(boolean legIncrementedFlag)
           
 void setLegIndex(int index)
           
 void setLevelIndex(int index)
           
 void setMode(int mode)
           
 void setNodeNumber(int nodeNumber)
           
 void setParent(HierarchyNode newParent)
          Sets this node's parent to newParent but does not change the parent's child array.
 void setParentNodesVector(java.util.Vector parentNodesVector)
           
 void setPathKey(int pathKey)
          Sets path key
 void setPosition(int position)
          code added by lavanya on 02182002 sets position in the list of nodes to its parent/primary/child
 void setPrimaryNode(GPSNode primaryNode)
          written by lavanya sets the primary node reference, if the node is alternate node
 void setRelationalORType(boolean relationalORType)
          sets relational OR type flag, whether the node having OR Type relation with it's sibblings or not
 void setRelationName(java.lang.String relationName)
           
 void setRelationTypeID(int relationTypeID)
           
 void setSecondaryParentAt(HierarchyNode secondaryParentNode, int position)
          method added by lavanya on 02182002 sets secondary parent node at the specified position
 void setSecondaryParentFlag(boolean secondaryParentFlag)
           
 java.lang.String toString()
          toString method
 
Methods inherited from class gps.core.GPSNode
getACDFlag, getCustomPanelFile, getCustomPanelObject, getDataFlag, getDrillDownFlag, getExplosionStopFlag, getImageName, getKey, getModel, getName, getNodeID, getNodeType, getNodeTypeID, getNotes, getOrigin, getType, getUserObject, setACDFlag, setCustomPanelFile, setCustomPanelObject, setDataFlag, setExplosionStopFlag, setImageFile, setImageName, setKey, setModel, setName, setNodeID, setNodeType, setNodeTypeID, setNotes, setOrigin, setOrigin, setType, setUserObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RELATION_PARENT

public static int RELATION_PARENT
variables which represent what kind of relation a node can have values are given based on Model Architect


RELATION_CHILD

public static int RELATION_CHILD

NODE_NORMAL

public static int NODE_NORMAL
variable which represent what kind of view mode a node can have


NODE_COLLAPSE

public static int NODE_COLLAPSE

NODE_EXPAND

public static int NODE_EXPAND
Constructor Detail

HierarchyNode

public HierarchyNode()
Creates a tree node that has no parent and no children, but which allows children.


HierarchyNode

public HierarchyNode(java.lang.String name)

HierarchyNode

public HierarchyNode(java.lang.Object userObject)
Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Parameters:
userObject - an Object provided by the user that constitutes the node's data

HierarchyNode

public HierarchyNode(java.lang.Object userObject,
                     boolean allowsChildren)
Creates a tree node with no parent, no children, initialized with the specified user object, and that allows children only if specified.

Parameters:
userObject - an Object provided by the user that constitutes the node's data
allowsChildren - if true, the node is allowed to have child nodes -- otherwise, it is always a leaf node
Method Detail

insertChild

public void insertChild(HierarchyNode newChild,
                        int childIndex)
method modified by lavanya on 03142002 Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex. newChild must not be null and must not be an ancestor of this node.

Parameters:
newChild - the HierarchyNode to insert under this node
childIndex - the index in this node's child array where this node is to be inserted
Throws:
java.lang.ArrayIndexOutOfBoundsException - if childIndex is out of bounds
java.lang.IllegalArgumentException - if newChild is null or is an ancestor of this node
java.lang.IllegalStateException - if this node does not allow children

insertAlternate

public void insertAlternate(HierarchyNode newAlternate,
                            int alternateIndex)

removeChild

public void removeChild(int childIndex)
Removes the child at the specified index from this node's children and sets that node's parent to null. The child node to remove must be a HierarchyNode.

Parameters:
childIndex - the index in this node's child array of the child to remove
Throws:
java.lang.ArrayIndexOutOfBoundsException - if childIndex is out of bounds

removeAlternate

public void removeAlternate(int alternateIndex)

removeAllAlternates

public void removeAllAlternates()

setParent

public void setParent(HierarchyNode newParent)
Sets this node's parent to newParent but does not change the parent's child array. This method is called from insert() and remove() to reassign a child's parent, it should not be messaged from anywhere else.

Parameters:
newParent - this node's new parent

getParent

public GPSNode getParent()
Returns this node's parent or null if this node has no parent.

Specified by:
getParent in class GPSNode
Returns:
this node's parent HierarchyNode, or null if this node has no parent

setParentNodesVector

public void setParentNodesVector(java.util.Vector parentNodesVector)

getParentNodesVector

public java.util.Vector getParentNodesVector()
Overrides:
getParentNodesVector in class GPSNode

addToParentNodesVector

public void addToParentNodesVector(HierarchyNode parentNode)

getSecondaryParentCount

public int getSecondaryParentCount()
method added by lavanya on 01242002 gets secondary parent nodes count

Returns:
int count

getSecondaryParentAt

public HierarchyNode getSecondaryParentAt(int index)
method added by lavanya on 01242002

Parameters:
int - index
Returns:
HierarchyNode second parent node

setSecondaryParentAt

public void setSecondaryParentAt(HierarchyNode secondaryParentNode,
                                 int position)
method added by lavanya on 02182002 sets secondary parent node at the specified position

Parameters:
HierarchyNode - secondary parent node
int - position

setRelationTypeID

public void setRelationTypeID(int relationTypeID)

getRelationTypeID

public int getRelationTypeID()

getChildAt

public HierarchyNode getChildAt(int index)
Returns the child at the specified index in this node's child array.

Parameters:
index - an index into this node's child array
Returns:
the HierarchyNode in this node's child array at the specified index
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of bounds

getAlternateAt

public HierarchyNode getAlternateAt(int index)

getChildCount

public int getChildCount()
Returns the number of children of this node.

Returns:
an int giving the number of children of this node

getAlternatesCount

public int getAlternatesCount()

getChildIndex

public int getChildIndex(HierarchyNode aChild)
Returns the index of the specified child in this node's child array. If the specified node is not a child of this node, returns -1. This method performs a linear search and is O(n) where n is the number of children.

Parameters:
aChild - the HierarchyNode to search for among this node's children
Returns:
an int giving the index of the node in this node's child array, or -1 if the specified node is a not a child of this node
Throws:
java.lang.IllegalArgumentException - if aChild is null

getAlternateIndex

public int getAlternateIndex(HierarchyNode alternateNode)

getChildrens

public java.util.Enumeration getChildrens()
Creates and returns a forward-order enumeration of this node's children. Modifying this node's child array invalidates any child enumerations created before the modification.

Overrides:
getChildrens in class GPSNode
Returns:
an Enumeration of this node's children

setChildrens

public void setChildrens(java.util.Vector children)

getAlternates

public java.util.Enumeration getAlternates()
Overrides:
getAlternates in class GPSNode

setAlternates

public void setAlternates(java.util.Vector alternates)

setAllowsChildren

public void setAllowsChildren(boolean allows)
Determines whether or not this node is allowed to have children. If allows is false, all of this node's children are removed.

Note: By default, a node allows children.

Parameters:
allows - true if this node is allowed to have children

getAllowsChildren

public boolean getAllowsChildren()
Returns true if this node is allowed to have children.

Returns:
true if this node allows children, else false

removeFromParent

public void removeFromParent()
Removes the subtree rooted at this node from the tree, giving this node a null parent. Does nothing if this node is the root of its tree.


remove

public void remove(HierarchyNode aChild)
Removes aChild from this node's child array, giving it a null parent.

Parameters:
aChild - a child of this node to remove
Throws:
java.lang.IllegalArgumentException - if aChild is null or is not a child of this node

removeAllChildren

public void removeAllChildren()
Removes all of this node's children, setting their parents to null. If this node has no children, this method does nothing.


addChild

public void addChild(HierarchyNode newChild)
Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Parameters:
newChild - node to add as a child of this node
Throws:
java.lang.IllegalArgumentException - if newChild is null
java.lang.IllegalStateException - if this node does not allow children

addAlternate

public void addAlternate(HierarchyNode newAlternate)

addAlternateAt

public void addAlternateAt(HierarchyNode newAlternate,
                           int index)
method added by lavanya kumar chinta on 01202002 adds alternate at specified position

Parameters:
HierarchyNode - new alternate
int - index

addChildAt

public void addChildAt(HierarchyNode newChild,
                       int index)
method added by lavanya kumar chinta on 01202002 adds child at specified position

Parameters:
HierarchyNode - new child
int - index

getChildVector

public java.util.Vector getChildVector()
gets child nodes

Returns:
Vector

getAlternateVector

public java.util.Vector getAlternateVector()
gets alternate vector


setRelationName

public void setRelationName(java.lang.String relationName)

getRelationName

public java.lang.String getRelationName()
Overrides:
getRelationName in class GPSNode

setMode

public void setMode(int mode)

getMode

public int getMode()

setLegIncrementedFlag

public void setLegIncrementedFlag(boolean legIncrementedFlag)

getLegIncrementedFlag

public boolean getLegIncrementedFlag()

setLegIndex

public void setLegIndex(int index)

getLegIndex

public int getLegIndex()

setLevelIndex

public void setLevelIndex(int index)

getLevelIndex

public int getLevelIndex()

setNodeNumber

public void setNodeNumber(int nodeNumber)

getNodeNumber

public int getNodeNumber()

toString

public java.lang.String toString()
Description copied from class: GPSNode
toString method

Overrides:
toString in class GPSNode
Returns:
String string representation of object

clone

public java.lang.Object clone()
Overrides:
clone in class GPSNode

setAlternateFlag

public void setAlternateFlag(boolean alternateFlag)

isAlternate

public boolean isAlternate()
Specified by:
isAlternate in class GPSNode

setPrimaryNode

public void setPrimaryNode(GPSNode primaryNode)
written by lavanya sets the primary node reference, if the node is alternate node

Specified by:
setPrimaryNode in class GPSNode
Parameters:
HierarchyNode - primary node

getPrimaryNode

public GPSNode getPrimaryNode()
written by lavanya gets the primary node reference, if the node is alternate node

Specified by:
getPrimaryNode in class GPSNode
Returns:
GPSNode primary node

setSecondaryParentFlag

public void setSecondaryParentFlag(boolean secondaryParentFlag)

getSecondaryParentFlag

public boolean getSecondaryParentFlag()
Overrides:
getSecondaryParentFlag in class GPSNode

setPosition

public void setPosition(int position)
code added by lavanya on 02182002 sets position in the list of nodes to its parent/primary/child

Parameters:
int - position

getPosition

public int getPosition()
code added by lavanya on 02182002 gets position in the list of nodes to its parent/primary/child

Returns:
int position

setCreatedBy

public void setCreatedBy(int createdBy)
sets who created the node

Specified by:
setCreatedBy in class GPSNode
Parameters:
int - created by constant

getCreatedBy

public int getCreatedBy()
gets who created the node

Specified by:
getCreatedBy in class GPSNode
Returns:
int created by constant

setPathKey

public void setPathKey(int pathKey)
Sets path key

Parameters:
int - key

getPathKey

public int getPathKey()
Returns path key

Returns:
int key

setAvailableInPath

public void setAvailableInPath(boolean availableInPath)
sets available in path flag for this node

Parameters:
boolean - availableInPath

getAvailableInPath

public boolean getAvailableInPath()
gets available in path flag for this node

Returns:
boolean availableInPath

setRelationalORType

public void setRelationalORType(boolean relationalORType)
sets relational OR type flag, whether the node having OR Type relation with it's sibblings or not

Parameters:
boolean - relationalORType

getRelationalORType

public boolean getRelationalORType()
gets relational OR type flag, whether the node having OR Type relation with it's sibblings or not

Returns:
boolean relationalORType