Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.util
Class CircularLinkedList

java.lang.Object
  extended by com.jivesoftware.util.CircularLinkedList

public class CircularLinkedList
extends java.lang.Object

Simple circular LinkedList allowing the marking of a position, reset of position, and pass count.

The circular list provides several tools for 'spinning' the circular list. The circular list is best thought of as an iterator on the circular list without a head or tail. Adds are conducted at the current list position and nodes lack indexes. Call mark() to mark the current node as a 'zero' position. When the next list item is called, the pass count is incremented when the current position is equal to the marked position. This allows users of the circular list to mark and spin around the circular list, checking how many times they go around the list.


Constructor Summary
CircularLinkedList()
          Creates a new linked list.
CircularLinkedList(java.lang.Object firstItem)
          Creates a new linked list.
 
Method Summary
 void add(java.lang.Object item)
          Add the given item so the following call to next() will return the item.
 void clear()
          Erases all elements in the list and re-initializes it.
 boolean contains(java.lang.Object item)
          Returns true if the given object is contained in this list.
 int getPassCount()
          Obtain the number of times the iteration of the list has passed the mark.
 boolean isEmpty()
          Returns true if the circular linked list is empty.
 void mark()
          Resets the pass count to zero and sets the mark to the current list position.
 java.lang.Object next()
          Advances the list to the next item and returns the item found or null if no items are in the list.
 java.lang.Object prev()
          Moves the list to the previous item and returns the item found or null if no items are in the list.
 void remove()
          Removes the current item (the item last returned by next() or prev()).
 void remove(java.lang.Object item)
          Removes the first item found that matches equals() on the given item.
 void setNext(java.lang.Object item)
          Sets the object that will be return by next() to the given value.
 void setPrev(java.lang.Object item)
          Sets the object that will be return by prev() to the given value.
 int size()
          Returns the number of items in the list.
 java.lang.String toString()
          Returns a String representation of the linked list with a comma delimited list of all the elements in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CircularLinkedList

public CircularLinkedList()
Creates a new linked list.


CircularLinkedList

public CircularLinkedList(java.lang.Object firstItem)
Creates a new linked list.

Method Detail

getPassCount

public int getPassCount()

Obtain the number of times the iteration of the list has passed the mark.

The passcount is reset using the mark() method.

Returns:
The number of times the list has iterated past the mark

mark

public void mark()

Resets the pass count to zero and sets the mark to the current list position.


add

public void add(java.lang.Object item)

Add the given item so the following call to next() will return the item.

Parameters:
item - The item to be added

setNext

public void setNext(java.lang.Object item)

Sets the object that will be return by next() to the given value.

If no next value exists, nothing happens (no new items will be added.

Parameters:
item - The item to be set

setPrev

public void setPrev(java.lang.Object item)

Sets the object that will be return by prev() to the given value.

If no prev value exists, nothing happens (no new items will be added.

Parameters:
item - The item to be set

next

public java.lang.Object next()

Advances the list to the next item and returns the item found or null if no items are in the list.

Returns:
The next item in the list or null if none exists

prev

public java.lang.Object prev()

Moves the list to the previous item and returns the item found or null if no items are in the list.

Returns:
The next item in the list or null if none exists

clear

public void clear()
Erases all elements in the list and re-initializes it.


remove

public void remove(java.lang.Object item)

Removes the first item found that matches equals() on the given item.

If this list does not contain the element, it is unchanged. More formally, removes the first element found by calling next() such that (item==null ? get(i)==null : item.equals(get(i))) (if such an element is found before making a complete trip around the circular list).

Parameters:
item - the item to remove

remove

public void remove()

Removes the current item (the item last returned by next() or prev()).


contains

public boolean contains(java.lang.Object item)

Returns true if the given object is contained in this list.

Parameters:
item - The item to check for existance
Returns:
True if the given object is in the list

size

public int size()

Returns the number of items in the list.

Returns:
The number of items in the list

toString

public java.lang.String toString()
Returns a String representation of the linked list with a comma delimited list of all the elements in the list.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the LinkedList.

isEmpty

public boolean isEmpty()

Returns true if the circular linked list is empty.

Returns:
True if the list is empty

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.