Module Design - Node Object

 

Designed by: Kunal Mittal
Version: 1.03 28th. April 1998.
Overview: This object maintains all the information regarding the nodes on the screen. It stores links to adjacent nodes, a data value for the node and lots of private data for easier implementation. The constructor needs to initialize all the private data members to NULL or 0.

Private Data:
int xLocation, yLocation: Location of the node on the screen. This is the grid location. (xLocation can be from 0 thru 5 and yLocation can be 0 thru 7.
Node prevNode: Pointer to the Prev Node. Only valid when working with doubly linked list nodes and tree nodes.
Node nextNode: Pointer to the Next Node.
String data: This contains the data value of the node. It does not care whether the data is integers or characters or any combination of them. The maximum length of this string can be 3 alpha-numeric characters.
static char 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.
static int height, breadth: These will hold the dimensions of the node. This is important for re-sizing of the node.
boolean isReachable: This will be used by the MasterNodeObject.leakCheck() to determine whether there is a memory leak or no.

Methods:
public Node GetNext(void);
Overview: Returns the next or right node associated with a given node.
Parameters: None.
Pre-conditions: None.
Post-conditions: None.
Algorithm: Manipulation of private data within the object.
Interaction with other Objects: None.
Error conditions: None.
Return Value: Pointer to a node object if a node exists, and NULL otherwise. If the pointer is uninitialized, return unInitializedNode.
public Node GetPrev(void);
Overview: Returns the prev or left node associated with a given node.
Parameters: None.
Pre-conditions: Type must not be "S"
Post-conditions: None.
Algorithm: Must check node Type. If it is "S" then throw an exception. The rest is manipulation of private data within the object.
Interaction with other Objects: None.
Error conditions: None.
Return Value: Pointer to a node object if a node exists, and NULL otherwise. If the pointer is uninitialized, return unInitializedNode. If nodeType is "S" then throw an exception.
public void SetNext(Node target);
Overview: Sets the next or right node associated with a given node.
Parameters: A pointer to a Node object
Pre-conditions: None.
Post-conditions: Sets a value for the Next node within this Node object.
Algorithm: Manipulation of internal data.
Interaction with other Objects: Master Link Object.
Error conditions: None.
Return Value: None.
public void SetPrev(Node target);
Overview: Sets the prev or right node associated with a given node.
Parameters: A pointer to a Node object
Pre-conditions: None.
Post-conditions: Sets a value for the Prev node within this Node object.
Algorithm: Manipulation of internal data.
Interaction with other Objects: Master Link Object.
Error conditions: None.
Return Value: None.
public String GetData(void)
Overview: Returns the value of the data field of a node. The object does not care whether it is a "string" data or an "integer" data. Internally it is all stored as a string.
Parameters: None.
Pre-conditions: The length of the string cannot be more than 3 alphanumeric characters.
Post-conditions: None.
Algorithm: Manipulation of private data.
Interaction with other Objects: None.
Error conditions: None.
Return Value: Returns a string of length 0-3 alphanumeric characters.
public void SetData(string newData)
Overview: Sets the value of the data field of a node. The object does not care whether it is a "string" data or an "integer" data. Internally it is all stored as a string.
Parameters: A alphanumeric string of length 0-3 characters.
Pre-conditions: The length of the string cannot be more than 3 alphanumeric characters.
Post-conditions: Sets the value of the "data" variable to the string passed in.
Algorithm: Manipulation of private data. Should call the "Draw Error( String )" method in the Error object if the length of the data string passed in is longer than 3 characters.
Interaction with other Objects: Interacts with the "Error" object.
Error conditions: Must check and confirm that the length of the alphanumeric string is not more than 3 characters. If so, must return an error.
Return Value: None.
public int GetLoc(void)
Overview: Returns the (x,y) grid location of a node on the screen. Since we are not sure whether Java can return arrays, we return a single int with the two int's encoded.
Parameters: None.
Pre-conditions: None.
Post-conditions: None.
Algorithm: The int to return should be ((xLocation<<8)+yLocation).
Interaction with other Objects: None.
Error conditions: None.
Return Value: Returns the location of the node. The value of "xLocation" can be from 0 thru 5 and the value of "yLocation" can be from 0 thru 7. The int returned will be ((xLocation<<8)+yLocation).
static 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. This method does not care whether the other nodes are of the same type. That will be handled by the master node object. Note: A GetNodeType() is not needed, because all methods within this object can access the data variable, and if any other object needs to know the node Type it should look at the MasterNode object.
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: Manipulation of internal data.
Interaction with other Objects: None.
Error conditions: If the parameters is passed in incorrectly, we could end up with nodes of different types. The master node object should be able to handle this.
Return Value: None.
static void SetDimensions(int tall, int wide)
Overview: Sets the dimensions of the node to be drawn. The pointer boxes are drawn proportional to these dimensions. This is needed for re-sizing the node when the screen is re-sized or the font size is changed.
Parameters: A dimension for the length and height of the node.
Pre-conditions: None.
Post-conditions: Sets the dimensions for the node.
Algorithm: Manipulation of internal data.
Interaction with other Objects: None.
Error conditions: None.
Return Value: None.
public boolean IsReachable(void)
Overview: This allows the MasterNodeObject.LeakCheck() to determine whether a node is reachable by traversing a "prev" or a "next" pointer.
Parameters: None.
Pre-conditions: None.
Post-conditions: None.
Algorithm: Manipulation of private data.
Interaction with other Objects: None.
Error conditions: None.
Return Value: Returns "true" if the node is reachable and "false" otherwise.
public void SetReachable(boolean reachable)
Overview: Sets the value of the variable "isReachable". For more information on how this is used, please refer to the MasterNodeObject.
Parameters: A boolean.
Pre-conditions: None.
Post-conditions: Sets the value of the "isReachable" variable to the boolean passed in.
Algorithm: Manipulation of private data.
Interaction with other Objects: None.
Error conditions: None.
Return Value: None.
public void DrawMe(void)
Overview: Tells the node to draw itself on the screen. It will draw the nodes as boxes and shaded boxes and then draw a rounded rectangle within the node. It will then write the data value into the rounded rectangle. This method does not care about the links.
Parameters: None.
Pre-conditions: None.
Post-conditions: A node gets drawn on the screen with its data content.
Algorithm: Check whether a node already exists at the location where this node has to be drawn. If a node exists, then just change the data content, by clearing the existing data content and writing the new one. If the node does not exist, draw the node (i.e. the node box with the appropriate pointer boxes (check node Type). The dimensions of these boxes are available as static data. The pointer boxes must be drawn proportional to the node size and thus will be calculated at the time of drawing. The font size will be the default browser font size.
Interaction with other Objects: None.
Error conditions: Ensure that the node Type has been set correctly and we don't end up with different types of nodes on the screen.
Return Value: None.

Search engine sitemap created by AutoSitemap.com