Module Design - Master Link Object
Last Modified: 04/22/98
- This object was designed by Johan Raffin
- Private Data:
- Link nextLink: Two dimensional static array to store the location of the Next pointers. This should be the default array when using a singly linked list.
- Link prevLink: Two dimensional static array to store the location of the Prev pointers. Note: this is used in conjunction with the NextLink array when using a doubly linked list or a tree.
- int direction: indicates the direction of the pointer (prev or next). The integer 1 means that the link is of type next, and an integer of value -1 means that the link is of type prev.
- NOTE: Parameters in the 2 dimensional link (the location of the pointers of a node) should match the same parameter of the location of the node in the master node object 2 dimensional array using the Cartesian coordinate system. The drawLinks methods has been removed since it will be handled in the master line object.
public void AddLink( Node, direction ); Overview: Add a prev or next link to a node. Parameters: Node pointer , direction of link. Pre-conditions: MasterLine::SetPrev() or MasterLine::SetNext() has been called. Direction of the link is established. Post-conditions: Adds a link into NextLink or PrevLink arrays if the link does not already exist. Algorithm: Get the location coordinates of the node. Stores the link into the prevLink or nextLink array depending on the direction. The link is stored in the array using the coordinates from the Node object. If the information already exist in that location then overwrite it. This does not check for collision. Also, call the MasterLine::MakeLink() to draw the link on the screen. This method overwrites any old link from the p,q,r,s pointers, which is eventually discarded via Java garbage collection. Interaction with other Objects: MasterLine object. Error conditions: Given array index is invalid. Return Value: None.
public void DeleteLink(Link); Overview: Delete a link object from the PrevLink or NextLink array. Parameters: Pointer to a link object. Pre-conditions: Need a valid array index in LinkComponent array. LinkComponent array should not be empty. Post-conditions: Remove link from the NextLink array or the PrevLink array. Algorithm: Delete the two dimensional array (NextLink or PrevLink) index from the coordinates of the link object passed in. In order to do so obtain link type of node and call MasterLink:: GetFirstLine() and delete the line with DeleteLink(). Set the pointer from the PrevLink or NextLink array to Link object to NULL. If the Link passed in is NULL then do not perform any actions and terminate the method. Interaction with other Objects: Link object. Error condition: None. Return Value: None.
** public link LinkTo(Node); Overview: search for links pointing to a given node Parameters: pointer to a Node. Pre-conditions: None. Post-conditions: None. Algorithm: search the NexLink and PrevLink array if there is an existing link with the given coordinates of the node position. The link is leaving the node. If this link exist then return it, else return NULL. Repeat this method until the function returns NULL. Interaction with other Objects: None. Error conditions: None. Return Value: return a pointer to a link object if link exist, else return NULL.
** public link LinkFrom(Node, char linkType); Overview: search for links leaving from a given node Parameters: pointer to a Node object and the link type (i.e: Next or Perv). Pre-conditions: None. Post-conditions: None. Algorithm: search the NexLink and/or PrevLink array (depending on the link type) if there is an existing link with the given coordinates of the node position. The link is coming to the node. If this link exist then return it, else return NULL. Repeat this method until NULL is returned. Interaction with other Objects: None. Error conditions: None. Return Value: return a pointer to a link object if link exist, else return NULL.