org.jasn.util
Class LongStack

java.lang.Object
  extended byorg.jasn.util.LongStack

public class LongStack
extends Object

The class represents a last-in-first-out (LIFO) stack of long values. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack and a method to test whether the stack is empty.

Each Stack instance has a capacity. The capacity is the size of the array used to store the elements in the stack. It is always at least as large as the stack size. As elements are added to a Stack, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

An application can increase the capacity of a Stack instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.

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

Author:
Nicolas Vraux

Constructor Summary
LongStack()
          Creates an empty stack containing long values.
LongStack(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 void clear()
          Removes all of the elements from this stack.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 boolean isEmpty()
          Tests wether this stack is empty.
 long peek()
          Looks at the value at the top of this stack without removing it from the stack.
 long pop()
          Removes the value at the top of this stack and returns that value.
 void push(long l)
          Pushes the specified long value onto the top of this stack.
 int size()
          Returns the number of elements in this stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LongStack

public LongStack(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
Throws:
IllegalArgumentException - if the specified initial capacity is negative

LongStack

public LongStack()
Creates an empty stack containing long values.

Method Detail

push

public void push(long l)
Pushes the specified long value onto the top of this stack.

Parameters:
l - the item to be pushed onto this stack.

pop

public long pop()
Removes the value at the top of this stack and returns that value.

Returns:
The long value at the top of this stack.
Throws:
EmptyStackException - if this stack is empty.

peek

public long peek()
Looks at the value at the top of this stack without removing it from the stack.

Returns:
the long at the top of this stack.
Throws:
EmptyStackException - if this stack is empty.

isEmpty

public boolean isEmpty()
Tests wether this stack is empty.

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

size

public int size()
Returns the number of elements in this stack.

Returns:
the number of elements in this stack.

ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

clear

public void clear()
Removes all of the elements from this stack. The stack will be empty after this call returns.



Copyright © 2004 Nicolas Vraux. All Rights Reserved.