java::util::ListStack Class Reference

Inheritance diagram for java::util::ListStack:

Inheritance graph
java::lang::Objectjava::lang::Interfacejava::util::Stack
[legend]
Collaboration diagram for java::util::ListStack:

Collaboration graph
java::lang::Objectjava::lang::Interfacejava::util::Stack
[legend]

List of all members.


Detailed Description

The ListStack class represents a last-in-first-out (LIFO) stack of objects.

It accept class List with operations that allow a list to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack isEmpty, and a method to search the stack for an item and discover how far it is from the top.

When a stack is first created, it contains no items.

Author:
Jonathan Payne
Version:
1.25, 12/03/01
Since:
JDK1.0

Public Member Functions

 ListStack (const Ref< List > &list=0)
 Creates an empty ListStack.
virtual jint size () const
 The size of this stack.
virtual jboolean isEmpty () const
 Tests if this stack is empty.
virtual ObjectRef push (const ObjectRef &item)
 Pushes an item onto the top of this stack.
virtual ObjectRef pop ()
 Removes the object at the top of this stack and returns that object as the value of this function.
virtual ObjectRef peek () const
 Looks at the object at the top of this stack without removing it from the stack.
virtual jint search (const ObjectRef &o) const
 Returns the 1-based position where an object is on this stack.
virtual void clear ()
 Removes all elements from the stack.

Constructor & Destructor Documentation

java::util::ListStack::ListStack ( const Ref< List > &  list = 0  ) 

Creates an empty ListStack.

The default data structure used is ArrayList.


Member Function Documentation

virtual jint java::util::ListStack::size (  )  const [virtual]

The size of this stack.

Returns:
the number of objects in this stack.

Implements java::util::Stack.

virtual jboolean java::util::ListStack::isEmpty (  )  const [virtual]

Tests if this stack is empty.

Returns:
true if and only if this stack contains no items; false otherwise.

Implements java::util::Stack.

virtual ObjectRef java::util::ListStack::push ( const ObjectRef item  )  [virtual]

Pushes an item onto the top of this stack.

Parameters:
item the item to be pushed onto this stack.
Returns:
the item argument.
See also:
java.util.Vector::addElement

Implements java::util::Stack.

virtual ObjectRef java::util::ListStack::pop (  )  [virtual]

Removes the object at the top of this stack and returns that object as the value of this function.

Returns:
The object at the top of this stack (the last item of the Vector object).
Exceptions:
NoSuchElementException if this stack is empty.

Implements java::util::Stack.

virtual ObjectRef java::util::ListStack::peek (  )  const [virtual]

Looks at the object at the top of this stack without removing it from the stack.

Returns:
the object at the top of this stack (the last item of the Vector object).
Exceptions:
NoSuchElementException if this stack is empty.

Implements java::util::Stack.

virtual jint java::util::ListStack::search ( const ObjectRef o  )  const [virtual]

Returns the 1-based position where an object is on this stack.

If the object o occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance 1. The equals method is used to compare o to the items in this stack.

Parameters:
o the desired object.
Returns:
the 1-based position from the top of the stack where the object is located; the return value -1 indicates that the object is not on the stack.

Implements java::util::Stack.

virtual void java::util::ListStack::clear (  )  [virtual]

Removes all elements from the stack.

Implements java::util::Stack.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:49 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3