magi.toolkit.util.queue
Class Stack

java.lang.Object
  |
  +--magi.toolkit.util.queue.Stack
All Implemented Interfaces:
Queue
Direct Known Subclasses:
LIFOQueue

public class Stack
extends java.lang.Object
implements Queue

An implementation of a stack, for pushing and popping objects. The Stack implements the Queue interface, as a Stack can be considered to be a LIFO Queue implementation.

Author:
Paul Atkinson, Magi Systems Pty Ltd.

Constructor Summary
Stack()
          Default constructor.
Stack(java.lang.Object[] objects)
          Creates a Stack pre-populated with an array of Objects.
 
Method Summary
 boolean isEmpty()
          Returns true if the stack currently contains no elements.
 java.lang.Object peek()
          Peek at the next Object available on the stack.
 java.lang.Object[] peekAll()
          Peek at all Objects available in the stack, in the correct stacking order.
 java.lang.Object pop()
          Pops an Object off the stack.
 java.lang.Object[] popAll()
          Pops all Objects off the stack, in the correct stacking order.
 void push(java.lang.Object object)
          Pushes an Object onto the stack.
 void pushAll(java.lang.Object[] objects)
          Pushes an array of Objects onto the stack.
 void remove(java.lang.Object object)
          Removes an Object directly from this stack, regardless of its current position in the stack.
 int size()
          Returns the number of Objects currently in the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stack

public Stack()
Default constructor.


Stack

public Stack(java.lang.Object[] objects)
Creates a Stack pre-populated with an array of Objects. The elements are queued from left to right, where element 0 is queued first, element 1 is queued next, and so on. The last array element will then be popped first.

Method Detail

push

public void push(java.lang.Object object)
Pushes an Object onto the stack.

Specified by:
push in interface Queue
Parameters:
object - the Object to insert.

pushAll

public void pushAll(java.lang.Object[] objects)
Pushes an array of Objects onto the stack. The elements are queued from left to right, where element 0 is queued first, element 1 is queued next, and so on. The last array element will then be popped first.

Specified by:
pushAll in interface Queue
Parameters:
objects - the Object array to queue up.

pop

public java.lang.Object pop()
Pops an Object off the stack.

Specified by:
pop in interface Queue
Returns:
the Object removed from the stack.

popAll

public java.lang.Object[] popAll()
Pops all Objects off the stack, in the correct stacking order. This means that the next object due to be popped is element 0, and the next is element 1, and so on.

Specified by:
popAll in interface Queue
Returns:
the Object array removed from the stack.

peek

public java.lang.Object peek()
Peek at the next Object available on the stack. This method does NOT remove the Object from the stack.

Specified by:
peek in interface Queue
Returns:
the Object that is next on the stack.

peekAll

public java.lang.Object[] peekAll()
Peek at all Objects available in the stack, in the correct stacking order. This means that the next object due to be popped is element 0, and the next is element 1, and so on. This method does NOT remove any Objects from the queue.

Specified by:
peekAll in interface Queue
Returns:
the Object array in the queue.

size

public int size()
Returns the number of Objects currently in the stack.

Specified by:
size in interface Queue
Returns:
the int size of the stack collection.

isEmpty

public boolean isEmpty()
Returns true if the stack currently contains no elements.

Specified by:
isEmpty in interface Queue
Returns:
true if empty, false if not.

remove

public void remove(java.lang.Object object)
Removes an Object directly from this stack, regardless of its current position in the stack.

Specified by:
remove in interface Queue
Parameters:
object - the Object to remove.