GNU Trove

gnu.trove.stack.array
Class TIntArrayStack

java.lang.Object
  extended by gnu.trove.stack.array.TIntArrayStack
All Implemented Interfaces:
TIntStack, java.io.Externalizable, java.io.Serializable

public class TIntArrayStack
extends java.lang.Object
implements TIntStack, java.io.Externalizable

A stack of int primitives, backed by a TIntArrayList

See Also:
Serialized Form

Field Summary
protected  TIntArrayList _list
          the list used to hold the stack values.
static int DEFAULT_CAPACITY
           
 
Constructor Summary
TIntArrayStack()
          Creates a new TIntArrayStack instance with the default capacity.
TIntArrayStack(int capacity)
          Creates a new TIntArrayStack instance with the specified capacity.
TIntArrayStack(int capacity, int no_entry_value)
          Creates a new TIntArrayStack instance with the specified capacity.
TIntArrayStack(TIntStack stack)
          Creates a new TIntArrayStack instance that is a copy of the instanced passed to us.
 
Method Summary
 void clear()
          Clears the stack.
 boolean equals(java.lang.Object o)
           
 int getNoEntryValue()
          Returns the value that is used to represent null.
 int hashCode()
           
 int peek()
          Returns the value at the top of the stack.
 int pop()
          Removes and returns the value at the top of the stack.
 void push(int val)
          Pushes the value onto the top of the stack.
 void readExternal(java.io.ObjectInput in)
           
 int size()
          Returns the current depth of the stack.
 int[] toArray()
          Copies the contents of the stack into a native array.
 void toArray(int[] dest)
          Copies a slice of the list into a native array.
 java.lang.String toString()
          Returns a String representation of the list, top to bottom.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_list

protected TIntArrayList _list
the list used to hold the stack values.


DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
See Also:
Constant Field Values
Constructor Detail

TIntArrayStack

public TIntArrayStack()
Creates a new TIntArrayStack instance with the default capacity.


TIntArrayStack

public TIntArrayStack(int capacity)
Creates a new TIntArrayStack instance with the specified capacity.

Parameters:
capacity - the initial depth of the stack

TIntArrayStack

public TIntArrayStack(int capacity,
                      int no_entry_value)
Creates a new TIntArrayStack instance with the specified capacity.

Parameters:
capacity - the initial depth of the stack
no_entry_value - value that represents null

TIntArrayStack

public TIntArrayStack(TIntStack stack)
Creates a new TIntArrayStack instance that is a copy of the instanced passed to us.

Parameters:
stack - the instance to copy
Method Detail

getNoEntryValue

public int getNoEntryValue()
Returns the value that is used to represent null. The default value is generally zero, but can be changed during construction of the collection.

Specified by:
getNoEntryValue in interface TIntStack
Returns:
the value that represents null

push

public void push(int val)
Pushes the value onto the top of the stack.

Specified by:
push in interface TIntStack
Parameters:
val - an int value

pop

public int pop()
Removes and returns the value at the top of the stack.

Specified by:
pop in interface TIntStack
Returns:
an int value

peek

public int peek()
Returns the value at the top of the stack.

Specified by:
peek in interface TIntStack
Returns:
an int value

size

public int size()
Returns the current depth of the stack.

Specified by:
size in interface TIntStack

clear

public void clear()
Clears the stack.

Specified by:
clear in interface TIntStack

toArray

public int[] toArray()
Copies the contents of the stack into a native array. Note that this will NOT pop them out of the stack. The front of the list will be the top of the stack.

Specified by:
toArray in interface TIntStack
Returns:
an int[] value

toArray

public void toArray(int[] dest)
Copies a slice of the list into a native array. Note that this will NOT pop them out of the stack. The front of the list will be the top of the stack.

If the native array is smaller than the stack depth, the native array will be filled with the elements from the top of the array until it is full and exclude the remainder.

Specified by:
toArray in interface TIntStack
Parameters:
dest - the array to copy into.

toString

public java.lang.String toString()
Returns a String representation of the list, top to bottom.

Overrides:
toString in class java.lang.Object
Returns:
a String value

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

GNU Trove