org.apache.qpid.junit.extensions.util
Class StackQueue<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector<E>
              extended by java.util.Stack<E>
                  extended by org.apache.qpid.junit.extensions.util.StackQueue<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, Queue<E>, RandomAccess

public class StackQueue<E>
extends Stack<E>
implements Queue<E>

The Stack class in java.util (most unhelpfully) does not implement the Queue interface. This is an adaption of that class as a queue.

CRC Card
Responsibilities Collaborations
Turn a stack into a queue.

See Also:
Serialized Form
Todo:
Need to override the add method, and iterator and consider other methods too. They work like LIFO but really wany FIFO behaviour accross the whole data structure.

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
StackQueue()
           
 
Method Summary
 E element()
          Retrieves, but does not remove, the head of this queue.
 boolean offer(E o)
          Inserts the specified element into this queue, if possible.
 E peek()
          Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
 E poll()
          Retrieves and removes the head of this queue, or null if this queue is empty.
 E remove()
          Retrieves and removes the head of this queue.
 
Methods inherited from class java.util.Stack
empty, pop, push, search
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, iterator, lastElement, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Queue
add
 
Methods inherited from interface java.util.Collection
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

StackQueue

public StackQueue()
Method Detail

element

public E element()
Retrieves, but does not remove, the head of this queue.

Specified by:
element in interface Queue<E>
Returns:
The element at the top of the stack.

offer

public boolean offer(E o)
Inserts the specified element into this queue, if possible.

Specified by:
offer in interface Queue<E>
Parameters:
o - The data element to push onto the stack.
Returns:
True if it was added to the stack, false otherwise (this implementation always returns true).

peek

public E peek()
Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.

Specified by:
peek in interface Queue<E>
Overrides:
peek in class Stack<E>
Returns:
The top element from the stack, or null if the stack is empty.

poll

public E poll()
Retrieves and removes the head of this queue, or null if this queue is empty.

Specified by:
poll in interface Queue<E>
Returns:
The top element from the stack, or null if the stack is empty.

remove

public E remove()
Retrieves and removes the head of this queue.

Specified by:
remove in interface Queue<E>
Returns:
The top element from the stack, or null if the stack is empty.
Throws:
NoSuchElementException - If the stack is empty so no element can be removed from it.


Licensed to the Apache Software Foundation