Methods Summary |
---|
public synchronized Linkable | getHead()Return the object at the head of a linked list.
return this.head;
|
public synchronized int | getSize()Return size of the linked list.
return this.size;
|
public synchronized Linkable | getTail()Return the object at the tail of a linked list.
return this.tail;
|
public synchronized void | insertAtHead(Linkable node)Insert an object at the head of a linked list.
if (node instanceof Linkable)
{
if (this.head == null)
{
node.setNext(null); // Fixup node nextlink.
node.setPrevious(null); // Fixup node backlink.
this.head = node; // Insert node at head of list.
}
else
{
Linkable oldHead = this.head; // Fixup current head node.
oldHead.setPrevious(node); // Set backlink to new node.
node.setNext(oldHead); // Fixup new node nextlink.
node.setPrevious(null); // Fixup new node backlink.
this.head = node; // Insert node at head of list.
}
if (this.tail == null) // If list was empty,
{
this.tail = node; // Insert node at tail of list.
}
this.size++;
}
|
public synchronized void | insertAtTail(Linkable node)Insert an object at the tail of a linked list.
if (node instanceof Linkable)
{
if (this.tail == null)
{
node.setNext(null); // Fixup node nextlink.
node.setPrevious(null); // Fixup node backlink.
this.tail = node; // Insert node at end of list.
}
else
{
Linkable oldTail = this.tail; // Fixup current tail node.
oldTail.setNext(node); // Set backlink to new node.
node.setNext(null) ; // Fixup new node backlink.
node.setPrevious(oldTail); // Fixup new node nextlink.
this.tail = node; // Insert node at end of list.
}
if (this.head == null) // If list was empty,
{
this.head = node; // Insert node at head of list.
}
this.size++;
}
|
public synchronized void | insertIntoList(Linkable afternode, Linkable newnode)Insert an object anywhere into the linked list.
if ((newnode instanceof Linkable) && (afternode instanceof Linkable))
{
if (this.tail == afternode) // If inserting at the tail,
{
this.insertAtTail(newnode); // Use insertAtTail method.
}
else
{
Linkable nextnode = afternode.getNext();
newnode.setNext(nextnode); // Point to next node.
newnode.setPrevious(afternode); // Point to previous node.
afternode.setNext(newnode); // Fixup backlink in afternode.
nextnode.setPrevious(newnode); // Fixup nextlink in next node.
}
this.size++;
}
|
public synchronized Linkable | removeFromHead()Remove and return an object from the head of a linked list.
Linkable node = this.head;
if (node instanceof Linkable)
{
this.head = node.getNext(); // Set head to next node.
if (this.head == null) // If we emptied the list,
{
this.tail = null; // Fixup the tail pointer.
}
else
{
this.head.setPrevious(null);// Clear head node backlink.
}
node.setNext(null); // Clear removed node nextlink.
node.setPrevious(null); // Clear romoved node backlink.
this.size--;
}
return node;
|
public synchronized void | removeFromList(Linkable node)Remove the specified object from anywhere in the linked list.
This method is usually used by the object to remove itself
from the list.
if ((this.size <= 0) || ((this.head == null) && (this.tail == null)))
{
return;
}
if (node instanceof Linkable)
{
Linkable p = node.getPrevious(); // Reference to previous node.
Linkable n = node.getNext(); // Reference to next node.
if (p == null) // Is this the first (or only) node in the list?
{
this.head = n; // Yes, set the head of the list to point to the next.
}
else
{
p.setNext(n); // No, set the previous node to point to the next.
}
if (n == null) // Is this the last (or only) node in the list?
{
this.tail = p; // Yes, set the tail to point to the previous.
}
else
{
n.setPrevious(p); // No, set the next node to point to the previous.
}
node.setNext(null);
node.setPrevious(null);
this.size--;
}
|
public synchronized Linkable | removeFromTail()Remove and return an object from the tail of a linked list.
Linkable node = this.tail;
if (node instanceof Linkable)
{
this.tail = node.getPrevious(); // Set tail to previous node.
if (this.tail == null) // If we emptied the list,
{
this.head = null; // Fixup the head pointer.
}
else
{
this.tail.setNext(null); // Clear tail node nextlink.
}
node.setNext(null); // Clear removed node nextlink.
node.setPrevious(null); // Clear removed node backlink.
this.size--;
}
return node;
|
public synchronized java.lang.String | toString()Return a string representation of this DoubleLinkedList object.
/* boolean dif = ThreadContext.lgr().test
( // Check for trace flag sp:1:1
TraceLogger.CONFIGURATION,
TraceLogger.SVC_SP,
SPLogFlags.CFG_DIFFABLE_EXCEPTS,
1
);
String buf = "DoubleLinkedList@\n";
if(!dif)
{
buf = buf + " head = " + this.head + "\n";
buf = buf + " tail = " + this.tail + "\n";
}
buf = buf + " size = " + this.size + "\n";
return buf;
*/
return null;
|