type.lib
Class CharStack

java.lang.Object
  extended by type.lib.CharStack

public class CharStack
extends java.lang.Object

This class encapsulates a stack (last-in first-out) of characters. It provides services for adding an element to the top of the stack, removing the element at the top, and detecting of the stack is empty.

Version:
7.0 - Summer 2010
Author:
H. Roumani, roumani@cse.yorku.ca

Field Summary
static int DEFAULT_SIZE
           
 
Constructor Summary
CharStack()
          Constructs a stack capable of holding DEFAULT_SIZE characters.
CharStack(int size)
          Constructs a stack capable of holding upto size characters.
 
Method Summary
 void add(char c)
          Adds the passed character to the stack to the top of the stack.
 boolean isEmpty()
          Return true if the stack is empty and return false otherwise.
 char removeLast()
          Remove the character that was last added to the top of the stack and return it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SIZE

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

CharStack

public CharStack(int size)
Constructs a stack capable of holding upto size characters.


CharStack

public CharStack()
Constructs a stack capable of holding DEFAULT_SIZE characters.

Method Detail

add

public void add(char c)
Adds the passed character to the stack to the top of the stack.

Parameters:
c - the character to add.
Throws:
java.nio.BufferOverflowException - if the stack is already full and, hence, no additional elements can be added.

removeLast

public char removeLast()
Remove the character that was last added to the top of the stack and return it.

Returns:
the character that was last added.
Throws:
java.util.NoSuchElementException - if the stack is empty.

isEmpty

public boolean isEmpty()
Return true if the stack is empty and return false otherwise.



Java by Abstraction: A Client-View Approach