org.shiftone.cache.util
Class LinkedList

java.lang.Object
  extended byorg.shiftone.cache.util.LinkedList

public class LinkedList
extends java.lang.Object

This linked list is different from the java.util implementation in that it exposes access to the nodes themselves, allowing lower level manipulation. This ends up being rather critical when removing elements from a cache. Having a reference to the node allows it to be removed in constant time - rather than having to search for it first.

Version:
$Revision: 1.9 $
Author:
Jeff Drost

Constructor Summary
LinkedList()
          Constructor LinkedList
 
Method Summary
 LinkedListNode addBefore(LinkedListNode node, java.lang.Object obj)
          Method addBefore (somewhat expensive - alloc)
 LinkedListNode addFirst(java.lang.Object obj)
          adding an object to the list, making it the new first node.
 LinkedListNode addLast(java.lang.Object obj)
          adding an object to the list, making it the new last node.
 void addNodeBefore(LinkedListNode nodeToAddBefore, LinkedListNode newPreviousNode)
          Method addNodeBefore
 java.lang.Object dequeue()
          remove a node from the end of the list (list is being used like a queue).
static void main(java.lang.String[] args)
          Method main
 void moveToFirst(LinkedListNode node)
          promotes this node to the front of the the list.
 void moveToLast(LinkedListNode node)
          demotes this node to the end of the list.
 LinkedListNode peekFirst()
          peek the first element without removing it.
 LinkedListNode peekLast()
          peek the last element without removing it.
 java.lang.Object pop()
          remove a node from the beginning of the list (list is being used like a stack)
 java.lang.Object remove(LinkedListNode node)
          Removes the node from the list and returns the value of the former node.
 int size()
          Method size
 java.lang.String toString()
          Method toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinkedList

public LinkedList()
Constructor LinkedList

Method Detail

addFirst

public final LinkedListNode addFirst(java.lang.Object obj)
adding an object to the list, making it the new first node. for the purposes of treating this list as a queue or stack, this is the end of the list that should be used when adding.


addLast

public final LinkedListNode addLast(java.lang.Object obj)
adding an object to the list, making it the new last node.


dequeue

public final java.lang.Object dequeue()
remove a node from the end of the list (list is being used like a queue).


pop

public final java.lang.Object pop()
remove a node from the beginning of the list (list is being used like a stack)


peekFirst

public final LinkedListNode peekFirst()
peek the first element without removing it. This is a stack style peek


peekLast

public final LinkedListNode peekLast()
peek the last element without removing it. This is a queue style peek


moveToFirst

public final void moveToFirst(LinkedListNode node)
promotes this node to the front of the the list.


moveToLast

public final void moveToLast(LinkedListNode node)
demotes this node to the end of the list.


addBefore

public final LinkedListNode addBefore(LinkedListNode node,
                                      java.lang.Object obj)
Method addBefore (somewhat expensive - alloc)


addNodeBefore

public final void addNodeBefore(LinkedListNode nodeToAddBefore,
                                LinkedListNode newPreviousNode)
Method addNodeBefore


remove

public final java.lang.Object remove(LinkedListNode node)
Removes the node from the list and returns the value of the former node.


size

public int size()
Method size


toString

public java.lang.String toString()
Method toString


main

public static void main(java.lang.String[] args)
Method main