org.ceryle.util
Class Queue

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
                  extended by org.ceryle.util.Queue
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, List, RandomAccess

public class Queue
extends Stack

Queue extends java.util.Stack (a class that represents a last-in-first-out (LIFO) stack of objects) to allow to rotate its contents up (top element --> bottom) or down (bottom element --> top).

As a queue, it also adds enqueue (a synonym for 'add') and dequeue(), which extracts items from the bottom of the Stack rather than the top, in first-in-first-out (FIFO) fashion.

Since:
JDK1.2
Version:
$Id: Queue.java,v 3.3 2007-06-15 12:09:57 altheim Exp $
Author:
Murray Altheim
See Also:
Stack, Serialized Form

Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Queue()
           
 
Method Summary
 Object dequeue()
          Treats the Stack (backed up by a Vector) as a first-in-first-out (FIFO) queue, dequeue retrieving the bottom (zero-eth) element.
 boolean enqueue(Object o)
          Treats the Stack (backed up by a Vector) as a first-in-first-out (FIFO) queue, enqueue a synonym for java.util.Vector's add or java.util.Stack's push, all of which add the new Object o to the top of the underlying Vector.
 void rotateDown()
          Rotates the Stack by removing the first element and pushing it to the end of the Stack.
 void rotateDown(int count)
          Rotates the Stack count times by repeatedly removing the first element and pushing it to the end of the Stack.
 void rotateUp()
          Rotates the Stack by popping the last element and inserting it at the beginning of the Stack.
 void rotateUp(int count)
          Rotates the Stack count times by repeatedly popping the last element and inserting it at the beginning of the Stack.
 
Methods inherited from class java.util.Stack
empty, peek, 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, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

Queue

public Queue()
Method Detail

rotateUp

public void rotateUp(int count)
              throws EmptyStackException
Rotates the Stack count times by repeatedly popping the last element and inserting it at the beginning of the Stack.

Throws:
EmptyStackException

rotateUp

public void rotateUp()
              throws EmptyStackException
Rotates the Stack by popping the last element and inserting it at the beginning of the Stack.

Throws:
EmptyStackException

rotateDown

public void rotateDown(int count)
                throws EmptyStackException
Rotates the Stack count times by repeatedly removing the first element and pushing it to the end of the Stack.

Throws:
EmptyStackException

rotateDown

public void rotateDown()
                throws EmptyStackException
Rotates the Stack by removing the first element and pushing it to the end of the Stack.

Throws:
EmptyStackException

enqueue

public boolean enqueue(Object o)
Treats the Stack (backed up by a Vector) as a first-in-first-out (FIFO) queue, enqueue a synonym for java.util.Vector's add or java.util.Stack's push, all of which add the new Object o to the top of the underlying Vector.

Returns:
true if the object was added

dequeue

public Object dequeue()
               throws EmptyStackException
Treats the Stack (backed up by a Vector) as a first-in-first-out (FIFO) queue, dequeue retrieving the bottom (zero-eth) element.

Throws:
EmptyStackException


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.