sdsu.util
Class CharStack

java.lang.Object
  |
  +--sdsu.util.CharStack

public final class CharStack
extends java.lang.Object

This class implements a characater stack. Yes the JKD does contain a general stack. However that stack operates on objects. This stack just handles char elements. Use in IO operations where converting chars to objects will be too expensive.

Version:
1.0 21 August 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)

Field Summary
static int DEFAULT_QUEUE_SIZE
           
 
Constructor Summary
CharStack()
          Create a stack of the default size.
CharStack(int initialSize)
          Create a stack with the given initial size.
 
Method Summary
 int capacity()
          Returns the total number of locations,, used or not, for chars in the stack
 void clear()
          Removes all elements from the stack.
 boolean isEmpty()
          Returns true is stack is empty.
 char peek()
          Returns the top char on the stack.
 char pop()
          Remove and return the top char on the stack.
 void push(char addMe)
          Adds a char to the top of the stack.
 void push(char[] addMe)
          Adds an array of characters to the stack.
 void push(java.lang.String addMe)
          Adds an array of characters to the stack.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_QUEUE_SIZE

public static final int DEFAULT_QUEUE_SIZE
Constructor Detail

CharStack

public CharStack()
Create a stack of the default size.

CharStack

public CharStack(int initialSize)
Create a stack with the given initial size.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isEmpty

public boolean isEmpty()
Returns true is stack is empty.

pop

public char pop()
Remove and return the top char on the stack. Assumes stack is not empty.

peek

public char peek()
Returns the top char on the stack. Does not remove any elements. Assumes stack is not empty.

capacity

public int capacity()
Returns the total number of locations,, used or not, for chars in the stack

push

public void push(char addMe)
Adds a char to the top of the stack.

push

public void push(char[] addMe)
Adds an array of characters to the stack. First element of the array is pushed first.

push

public void push(java.lang.String addMe)
Adds an array of characters to the stack. First element of the array is pushed first.

clear

public void clear()
Removes all elements from the stack.