vnt

Class Node_LinkedList


(package private) class Node_LinkedList
extends java.lang.Object

A standard doubly-linked list. Generally used by the Node structure primarily to store and manipulate information for the adjacency lists.

The goal for this class is for the adjacency list to behave like a set:

Note: This class is used heavily by the Node_Analysis plug-in, which is still very recent and needs significant testing. As a result, this class has a large number of print statements for debugging purposes.

Version:
1.0
Author:
Michael Miller - Truman State University
Since:
1.0

Field Summary

private Node_LinkedList
after
private Node_LinkedList
before
private Node
myNode

Constructor Summary

Node_LinkedList(Node creator)
Simple constructor.
Node_LinkedList(Node creator, Node_LinkedList bef, Node_LinkedList aft)
Constructor.

Method Summary

void
addBefore(Node insertMe)
Inserts a Node into the list before the current node.
boolean
compareNode(Node compare)
Compares a given node's X and Y coordinates to this node.
void
deleteMe()
Removes this node from the list.
Node_LinkedList
findAdjacent(Node findMe)
Searches [preorder] this, before (iteratively), and after (iteratively) for the given node.
Node_LinkedList
getAfter()
Accessor to the linked node after this one.
Node_LinkedList
getBefore()
Accessor to the linked node before this one.
Node
getNode()
Accessor to the node variable.
boolean
isAdjacent(Node findMe)
Searches [preorder] this, before (iteratively), and after (iteratively) for the given node.
boolean
listDeleteItem(Node deleteMe)
Searches the adjacency list for the target node.
int
listDissolve(boolean preserveSymmetry)
Iteratively deletes the entire linked list.
boolean
listInsert(Node insertMe)
Attempts to insert the node insertMe.
int
listUnion(Node_LinkedList unionMe, boolean preserveSymmetry)
Unions a given linked list into this linked list.
void
setAfter(Node_LinkedList target)
Simple Mutator to after variable.
void
setBefore(Node_LinkedList target)
Simple mutator to before variable.

Field Details

after

private Node_LinkedList after

before

private Node_LinkedList before

myNode

private Node myNode

Constructor Details

Node_LinkedList

public Node_LinkedList(Node creator)
Simple constructor. No adjacencies by default.

Pre: None.
Post: This node exists. It has an origin (itself) and no adjacencies.

Parameters:
creator - The node with which this adjacency list this is associated.

Node_LinkedList

public Node_LinkedList(Node creator,
                       Node_LinkedList bef,
                       Node_LinkedList aft)
Constructor. Will also link the nodes given.

Pre: None.
Post: This node exists. It has an origin (itself) and possibly connections. These connections can lead to any number of adjacencies.

Parameters:
bef - The Node before. Its after parameter will change to this. Can be null.
aft - The Node after. Its before parameter will change to this. Can be null.

Method Details

addBefore

public void addBefore(Node insertMe)
Inserts a Node into the list before the current node. Note: There is no addAfter() intentionally. Since adjacency list information is to be treated like a set, order has no meaning and therefore there is no reason to specify adding before or after the present node. (In the future, an index could be assigned for speeded searching, however this is trivial due to the small size of these adjacency lists. The typical adjacency list for a vascular network will not exceed three connections.)

Pre: This node adjacency exists.
Post: A new node adjacency is added

Parameters:
insertMe - The node to be inserted.

compareNode

public boolean compareNode(Node compare)
Compares a given node's X and Y coordinates to this node.

Pre: This node adjacency exists. Assumes compare exists.
Post: No changes.

Parameters:
compare - The node to compare to this node.
Returns:
Returns true if the compare node's x and y matches this node. Returns false otherwise.

deleteMe

public void deleteMe()
Removes this node from the list. Cleans up connections with before and after (keeps them linked if they exist).

Pre: This adjacency node exists and may or may not have connections to other adjacency list elements.
Post: This particular adjacency node is removed from it's neigboring connections. If before or after existed, their connections are updated to maintain proper connectivity.


findAdjacent

public Node_LinkedList findAdjacent(Node findMe)
Searches [preorder] this, before (iteratively), and after (iteratively) for the given node.

Pre: Requires that the given node exists. Assumes all connections are well formed.
Post: Returns the LinkedList associated with the given node in this particularly adjacency list if it compareNode()'d to one of the nodes in this adjacency list.

Parameters:
findMe - The node's coordinate data to search for.
Returns:
Returns the linked list pointer if findMe matches it. Otherwise returns null.

getAfter

public Node_LinkedList getAfter()
Accessor to the linked node after this one.

Pre: This node adjacency exists.
Post: No change.

Returns:
The linked node in the list after this one. Can be null.

getBefore

public Node_LinkedList getBefore()
Accessor to the linked node before this one.

Pre: This node adjacency exists.
Post: No change.

Returns:
The linked node in the list before this one. Can be null.

getNode

public Node getNode()
Accessor to the node variable.

Pre: This node adjacency exists.
Post: No changes.

Returns:
Returns the node associated with this adjacency list.

isAdjacent

public boolean isAdjacent(Node findMe)
Searches [preorder] this, before (iteratively), and after (iteratively) for the given node.

Pre: Requires that the given node exists. Assumes all connections are well formed.
Post: Returns true or false if the given node compareNode()'d to one of the nodes in this adjacency list.

Parameters:
findMe - The node's coordinate data to search for.
Returns:
Returns true if compareNode(findMe) is true for this or any connected adjacency list item. Otherwise returns false if it was not found.

listDeleteItem

public boolean listDeleteItem(Node deleteMe)
Searches the adjacency list for the target node. If it is found, the links around it are deleted and Java's natural garbage collection deletes it.

Pre: Assumes that the given node exists.
Post: If the given node was found in this adjacency list, removes it. Symmetry is not preserved by this method alone. Otherwise, no change is made.

Parameters:
deleteMe - The node to search for to delete.
Returns:
Returns true if the node was found (and consequently deleted), otherwise false.

listDissolve

public int listDissolve(boolean preserveSymmetry)
Iteratively deletes the entire linked list.

Pre: Assumes the connections are well formed (no broken links, no endless loops, etc).
Post: Deletes all connections to this node's adjacency. Symmetry preservation is determined by the second parameter.

Parameters:
preserveSymmetry - If true, the symmetric connections will also be added. If false, the only changes will be to this linked list.
Returns:
Returns the number of nodes that were deleted.

listInsert

public boolean listInsert(Node insertMe)
Attempts to insert the node insertMe. If no duplicates are found, then the insertion is performed.

Pre: Assumes insertMe is a valid node to search for.
Post: Either adds the node if it is new, or does not if it was found in the adjacency list.

Parameters:
insertMe - The node to attempt to insert.
Returns:
Returns true if the node was added successfully. Otherwise false if the node already existed in the list.

listUnion

public int listUnion(Node_LinkedList unionMe,
                     boolean preserveSymmetry)
Unions a given linked list into this linked list. Elements of the union are node adjacencies.

Pre: Requires that the given Node_LinkedList exists.
Post: All connections in the given Node_LinkedList that are not in this list are added to this list. Symmetry depends on the second parameter.

Parameters:
unionMe - The list to be merged onto this one.
preserveSymmetry - If true, the symmetric connections will also be added. If false, the only changes will be to this linked list.
Returns:
The number of new nodes added to this list. Duplicates do not count.

setAfter

public void setAfter(Node_LinkedList target)
Simple Mutator to after variable.

Pre: This node adjacency exists.
Post: No change.

Parameters:
target - What the after variable will be changed to.

setBefore

public void setBefore(Node_LinkedList target)
Simple mutator to before variable.

Pre: This node adjacency exists.
Post: No change.

Parameters:
target - What the before variable will be changed to.