org.apache.commons.collections.primitives
Class ByteStack

java.lang.Object
  extended by org.apache.commons.collections.primitives.ByteStack

public class ByteStack
extends Object

A primitive byte based Stack. The underlying backing store is an ArrayByteList where the front of the list is the bottom of the stack and the tail of the list is the top of the stack.

Since:
Commons Primitives 1.1
Version:
$Revision: 480460 $ $Date: 2006-11-29 09:14:21 +0100 (Wed, 29 Nov 2006) $
Author:
Apache Directory Project

Constructor Summary
ByteStack()
          Creates an empty primitive stack.
ByteStack(byte[] numbas)
          Creates a stack prepopulating it with values.
 
Method Summary
 void clear()
          Empties the contents of the stack.
 boolean empty()
          Tests if this stack is empty.
 byte get(int index)
          Gets items from the stack where the index is zero based and the top of the stack is at an index of size()-1 with the bottom of the stack at an index of 0.
 byte peek()
          Looks at the top of this stack without removing it.
 byte peek(int n)
          Return the n'th byte down the stack, where 0 is the top element and [size()-1] is the bottom element.
 byte pop()
          Removes the value at the top of this stack and returns it.
 byte push(byte item)
          Pushes a value onto the top of this stack.
 int search(byte item)
          Returns the 1-based position where a value is on this stack.
 int size()
          Gets the size of this stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteStack

public ByteStack()
Creates an empty primitive stack.


ByteStack

public ByteStack(byte[] numbas)
Creates a stack prepopulating it with values.

Parameters:
numbas - the array to add
Method Detail

empty

public boolean empty()
Tests if this stack is empty.

Returns:
true if and only if this stack is empty; false otherwise

peek

public byte peek()
Looks at the top of this stack without removing it.

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

peek

public byte peek(int n)
Return the n'th byte down the stack, where 0 is the top element and [size()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
EmptyStackException - if the stack is empty
IndexOutOfBoundsException - if the index is out of bounds

pop

public byte pop()
Removes the value at the top of this stack and returns it.

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

push

public byte push(byte item)
Pushes a value onto the top of this stack.

Parameters:
item - the value to push onto this stack
Returns:
the item argument for call chaining

search

public int search(byte item)
Returns the 1-based position where a value is on this stack. If the value 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.

Parameters:
item - the value to search for from the top down
Returns:
the 1-based position from the top of the stack where the int is located; the return value -1 indicates that the int is not on the stack

get

public byte get(int index)
Gets items from the stack where the index is zero based and the top of the stack is at an index of size()-1 with the bottom of the stack at an index of 0.

Parameters:
index - the index into the stack treated as a list
Returns:
the value at the index

size

public int size()
Gets the size of this stack.

Returns:
the size of this stack

clear

public void clear()
Empties the contents of the stack.



Copyright © 2002-2010 Apache Software Foundation. All Rights Reserved.