Module Design - Master Node Object

 

Designed by: Kunal Mittal
Version: 1.11 28th. April 1998.
Overview: This object can more appropriately be called "Node Collection Object". It contains an array of Node Objects. The constructor should initialize all private data to NULL.


Private Data:
char nodeType: This will be "S" for singly linked list nodes, "D" for doubly linked list nodes and "T" for tree nodes. It will be case specific, upper case is required.
char dataType: This will be "I" for int nodes and "S" for string nodes. It will be case specific, upper case is required.
Node p,q,r,s: Node "p" is equivalent to location y=0 in the Node object, Node "q" is equivalent to location y=2 and so on.
Node nodeArray[][]: This is a collection of all the nodes. It will follow the p,q,r,s numbering system described above. e.g. nodeArray[0][] and nodeArray[1][] will contain all the nodes in the "p" row. The dimensions of this array will be 8x7.
static Node unInitializedNode: This will be a dummy node used to distinguish between uninitialized pointers and NULL pointers. This will have grid coordinates -1,-1 and will NOT exist within the nodeArray.


Methods:
public Node NewNode(Node nodeName);
Overview: This creates a new node at the nearest appropriate space on the screen.
Parameters: node Name will be either p,q,r or s. It can also be NULL if the user does not care where the node is created.
Pre-conditions: None.
Post-conditions: A new node object is created and drawn on the screen.
Algorithm: If NodeName is not NULL, check to see whether a node can be drawn at that "y" coordinate (same node name). If not we just assume that the NodeName is NULL. If NodeName is NULL then we draw the node at the first available position. This means, we search through the nodeArray, and at the first empty slot, create a Node Object. Otherwise draw the node at the first available "x" coordinate for the specified "y" coordinate. Set all the fields in the Node Object (locX, locY, type, data). Call the DrawNodes().
Interaction with other Objects: Creates instances of the Node Object. Calls all the Set methods.
Error conditions: If there are (8x4) 32 nodes already on the screen and we try to draw another one. If the nodeArray has not been updated correctly by a prior call of the DeleteNode() method, it will cause overlapping nodes and some serious bugs.
Return Value: Return the Node just created.
public void DrawNodes(void);
Overview: Invokes DrawMe() on each non-null member of nodeArray.
Parameters: None.
Pre-conditions: nodeArray must contain entries for all the nodes that exist.
Post-conditions: All the nodes that exist in nodeArray get drawn on the screen.
Algorithm: Call Node.DrawMe() for every node in the nodeArray as long as they are not NULL.
Interaction with other Objects: Calls the DrawMe() method in the Node object.
Error conditions: None.
Return Value: None.
public void LeakCheck(void);
Overview: Determines if there is a memory leak, and invokes the Error object if there is an unreachable node.
Parameters: None.
Pre-conditions: None.
Post-conditions: Checks to see if any node is unreachable. It causes an error window to be displayed if any node is unreachable.
Algorithm: Start by setting the isReachable flag in every non-NULL node object to be "false". Check nodeType. If it is "S" we are dealing with next pointers only. In that case, start at the first node and traverse the next pointers. For every node that we reach, change the isReachable flag to "true". In case of "D" or T" follow each prev or left pointer in a similar manner. After doing this for every node, check each node in the nodeArray. If any of them yet have isReachable to be "false" we have a memory leak.
Interaction with other Objects: MasterLink, Node and Error objects.
Error conditions: None.
Return Value: None.
public void DeleteNode(int x, int y);
Overview: Delete the node at grid location x,y in the two dimensional array nodeArray. It also makes the appropriate method calls to delete all the links that point to this node. Furthermore, the Next and Prev pointers for every node that point to the node that is going to be deleted, have to be updated appropriately.
Parameters: Location (x,y) of the node to be deleted.
Pre-conditions: The node must exist in the nodeArray.
Post-conditions: Deletes a node from the nodeArray. All associated links are removed from the MasterLink object. Also, the "next" and "prev" pointers of all the nodes that point to the deleted node are updated.
Algorithm: Check whether node exists in nodeArray. If so, then delete the node. Check all the nodes and if any node has a "next" or "prev" pointer pointing to this node, change it to point to "unInitializedNode". Then call the MasterLink object to delete all the links to this node. Update the nodeArray. Although physical deletion of the node will be handled by Java's garbage collection, we need to clear the entry in the nodeArray, to enable future creation of nodes to work correctly.
Interaction with other Objects: MasterLink and Node objects .
Error conditions: None.
Return Value: None.
void SetNodeType(char type)
Overview: Sets the node Type. This will be "S" for singly linked list nodes, "D" for doubly linked list nodes and "T" for tree nodes. It will be case specific, so upper case is required.
Parameters: A single character which will be one of the following three: "S", "D" or "T".
Pre-conditions: The input character must be in upper case.
Post-conditions: Sets a node type for the particular node.
Algorithm: This must check whether any nodes exist within the nodeArray. If nodes do exist, then we cannot allow them to change the nodeType. Thus return an error. If nodes do not exist, then change the nodeType.
Interaction with other Objects: Node and Error objects.
Error conditions: None.
Return Value: None.
char GetNodeType(void)
Overview: Returns the nodeType.
Parameters: None.
Pre-conditions: None.
Post-conditions: None.
Algorithm: Manipulation of internal data.
Interaction with other Objects: None.
Error conditions: None.
Return Value: Returns the nodeType which should be "S", "D" or "T".
void SetdataType(char type)
Overview: Sets the data Type. This will be "S" for string data and "I" for int data. It will be case specific, so upper case is required.
Parameters: A single character which will be one of the following "S" or "I".
Pre-conditions: The input character must be in upper case.
Post-conditions: Sets a data type for the nodes.
Algorithm: This must check whether any nodes exist within the nodeArray. If nodes do exist, then we cannot allow them to change the dataType. Thus return an error. If nodes do not exist, then change the dataType.
Interaction with other Objects: Node and Error objects.
Error conditions: None.
Return Value: None.
char GetDataType(void)
Overview: Returns the dataType.
Parameters: None.
Pre-conditions: None.
Post-conditions: None.
Algorithm: Manipulation of internal data.
Interaction with other Objects: None.
Error conditions: None.
Return Value: Returns the dataype which should be "S" or "I".

Search engine sitemap created by AutoSitemap.com