org.jboss.util.collection
Class ListQueue

java.lang.Object
  extended by java.util.AbstractCollection
      extended by org.jboss.util.collection.AbstractQueue
          extended by org.jboss.util.collection.ListQueue
All Implemented Interfaces:
Iterable, Collection, Queue

public class ListQueue
extends AbstractQueue

A ListQueue implements a first-in, first-out container using a List as a data structure.

Version:
$Revision: 1.3.6.1 $
Author:
Jason Dillon

Field Summary
protected  List list
          List container
 
Fields inherited from class org.jboss.util.collection.AbstractQueue
DEFAULT_MAXIMUM_SIZE, maximumSize
 
Fields inherited from interface org.jboss.util.collection.Queue
UNLIMITED_MAXIMUM_SIZE
 
Constructor Summary
ListQueue()
          Construct a new unconstrained ListQueue using a LinkedList for a data-structure.
ListQueue(int maxSize)
          Construct a new constrained ListQueue using a LinkedList for a data-structure.
ListQueue(List list)
          Construct a new unconstrained ListQueue.
ListQueue(List list, int maxSize)
          Construct a new constrained ListQueue.
 
Method Summary
protected  boolean addLast(Object obj)
          Appends the given element to the end of this list.
 Object getBack()
          Get the object at the back of the queue.
 Object getFront()
          Get the object at the front of the queue.
 Iterator iterator()
          Returns an iterator over the elements in this list in proper sequence.
protected  Object removeFirst()
          Remove the first object in the queue.
 Iterator reverseIterator()
          Returns an iterator over the elements in this list in reverse sequence.
 int size()
          Get the size of the queue.
 String toString()
          Return a String representation of this queue.
 
Methods inherited from class org.jboss.util.collection.AbstractQueue
add, clear, getMaximumSize, isEmpty, isFull, remove, setMaximumSize
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

list

protected final List list
List container

Constructor Detail

ListQueue

public ListQueue(List list,
                 int maxSize)
Construct a new constrained ListQueue.

Parameters:
list - The list which will be used to store queued objects.
maxSize - The maximum size of the queue.
Throws:
IllegalArgumentException - List is null.

ListQueue

public ListQueue(int maxSize)
Construct a new constrained ListQueue using a LinkedList for a data-structure.

Parameters:
maxSize - The maximum size of the queue.

ListQueue

public ListQueue(List list)
Construct a new unconstrained ListQueue.

Parameters:
list - The list which will be used to store queued objects.
Throws:
IllegalArgumentException - List is null

ListQueue

public ListQueue()
Construct a new unconstrained ListQueue using a LinkedList for a data-structure.

Method Detail

addLast

protected boolean addLast(Object obj)
Appends the given element to the end of this list.

Specified by:
addLast in class AbstractQueue
Parameters:
obj - Object to append.
Returns:
Per Collection.add(), we return a boolean to indicate if the object modified the collection.

removeFirst

protected Object removeFirst()
Remove the first object in the queue.

Specified by:
removeFirst in class AbstractQueue
Returns:
First object in the queue.

size

public int size()
Get the size of the queue.

Specified by:
size in interface Collection
Specified by:
size in class AbstractCollection
Returns:
The number of elements in the queue.

iterator

public Iterator iterator()
Returns an iterator over the elements in this list in proper sequence.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in class AbstractCollection
Returns:
An iterator over the elements in this list in proper sequence.

getFront

public Object getFront()
                throws EmptyCollectionException
Get the object at the front of the queue.

Returns:
Object at the front of the queue.
Throws:
EmptyCollectionException - The queue is empty.

getBack

public Object getBack()
               throws EmptyCollectionException
Get the object at the back of the queue.

Returns:
Object at the back of the queue.
Throws:
EmptyCollectionException - The queue is empty.

reverseIterator

public Iterator reverseIterator()
Returns an iterator over the elements in this list in reverse sequence.

Returns:
An iterator over the elements in this list in reverse sequence.

toString

public String toString()
Return a String representation of this queue.

Overrides:
toString in class AbstractCollection
Returns:
String


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.