Package org.jboss.util.collection
Class ListQueue<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- org.jboss.util.collection.AbstractQueue<E>
-
- org.jboss.util.collection.ListQueue<E>
-
- Type Parameters:
E
- the element type
- All Implemented Interfaces:
java.lang.Iterable<E>
,java.util.Collection<E>
,Queue<E>
public class ListQueue<E> extends AbstractQueue<E>
A ListQueue implements a first-in, first-out container using a List as a data structure.- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<E>
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
Constructors Constructor Description ListQueue()
Construct a new unconstrained ListQueue using aLinkedList
for a data-structure.ListQueue(int maxSize)
Construct a new constrained ListQueue using aLinkedList
for a data-structure.ListQueue(java.util.List<E> list)
Construct a new unconstrained ListQueue.ListQueue(java.util.List<E> list, int maxSize)
Construct a new constrained ListQueue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
addLast(E obj)
Appends the given element to the end of this list.E
getBack()
Get the object at the back of the queue.E
getFront()
Get the object at the front of the queue.java.util.Iterator<E>
iterator()
Returns an iterator over the elements in this list in proper sequence.protected E
removeFirst()
Remove the first object in the queue.java.util.Iterator<E>
reverseIterator()
Returns an iterator over the elements in this list in reverse sequence.int
size()
Get the size of the queue.java.lang.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
-
-
-
-
Field Detail
-
list
protected final java.util.List<E> list
List container
-
-
Constructor Detail
-
ListQueue
public ListQueue(java.util.List<E> 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:
java.lang.IllegalArgumentException
- List is null.
-
ListQueue
public ListQueue(int maxSize)
Construct a new constrained ListQueue using aLinkedList
for a data-structure.- Parameters:
maxSize
- The maximum size of the queue.
-
ListQueue
public ListQueue(java.util.List<E> list)
Construct a new unconstrained ListQueue.- Parameters:
list
- The list which will be used to store queued objects.- Throws:
java.lang.IllegalArgumentException
- List is null
-
ListQueue
public ListQueue()
Construct a new unconstrained ListQueue using aLinkedList
for a data-structure.
-
-
Method Detail
-
addLast
protected boolean addLast(E obj)
Appends the given element to the end of this list.- Specified by:
addLast
in classAbstractQueue<E>
- Parameters:
obj
- Object to append.- Returns:
- Per Collection.add(), we return a boolean to indicate if the object modified the collection.
-
removeFirst
protected E removeFirst()
Remove the first object in the queue.- Specified by:
removeFirst
in classAbstractQueue<E>
- Returns:
- First object in the queue.
-
size
public int size()
Get the size of the queue.
-
iterator
public java.util.Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.
-
getFront
public E 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 E 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 java.util.Iterator<E> 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 java.lang.String toString()
Return a String representation of this queue.- Overrides:
toString
in classjava.util.AbstractCollection<E>
- Returns:
- String
-
-