com.virtuosotechnologies.lib.base
Class LinkedObject

java.lang.Object
  extended bycom.virtuosotechnologies.lib.base.LinkedObject

public class LinkedObject
extends Object

Base class for elements in a "naked" circular linked list, i.e. it doesn't support the collections interface, but instead exposes the list cells. Useful for building larger data structures involving links without having the object and search overhead of using java.util.LinkedList internally.

The list is circular, e.g. there are never null pointers involved. You can create a "bounded" list using a delimiter element. The element whose next pointer points to the delimiter is the end, and the element whose prev pointer points to the delimiter is the beginning. As a corollary, an element that isn't linked up has both its next and prev pointers pointing to this.

Not synchronized. This is intended only to be a building block for larger data structures, so the synchronization policy is deferred to the client.


Constructor Summary
LinkedObject()
          Constructor
 
Method Summary
 LinkedObject getNext()
          Get the next element.
 LinkedObject getPrevious()
          Get the previous element.
 void linkThisAfter(LinkedObject element)
          Inserts this element after the given one.
 void linkThisBefore(LinkedObject element)
          Inserts this element before the given one.
 void unlinkThis()
          Remove this element from its current link.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkedObject

public LinkedObject()
Constructor

Method Detail

getNext

public LinkedObject getNext()
Get the next element.

Returns:
non-null next element.

getPrevious

public LinkedObject getPrevious()
Get the previous element.

Returns:
non-null previous element.

linkThisAfter

public void linkThisAfter(LinkedObject element)
Inserts this element after the given one. Removes this element from any link it is already part of first.

Returns:
element element for this one to follow.

linkThisBefore

public void linkThisBefore(LinkedObject element)
Inserts this element before the given one. Removes this element from any link it is already part of first.

Returns:
element element for this one to precede.

unlinkThis

public void unlinkThis()
Remove this element from its current link. Does nothing if it is not in a link.