Sharkysoft home

lava.string
Class CharacterStack

java.lang.Object
  |
  +--lava.string.CharacterStack

public class CharacterStack
extends java.lang.Object

Character stack.

Details: A CharacterStack is a LIFO queue of characters suitable for use in various text parsing applications. Characters are popped and pushed one at a time, but entire strings of characters can also be pushed with a single call. For character stacking, this class is more efficient than the java.util.Stack class because it does not require object encapsulation for the characters.

Author:
Sharky

Constructor Summary
CharacterStack()
          Initializes empty character stack.
 
Method Summary
 java.lang.Object clone()
          Clones stack.
 int pop()
          Pops character.
 void push(char c)
          Pushes character.
 void push(char[] src)
          Pushes characters.
 void push(char[] src, int offset, int amt)
          Pushes characters.
 void push(java.lang.String s)
          Pushes string.
 int size()
          Returns stack height.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharacterStack

public CharacterStack()
Initializes empty character stack.
Method Detail

push

public void push(char c)
Pushes character.

Details: push pushes a character onto the stack.

Parameters:
c - the character

push

public void push(java.lang.String s)
Pushes string.

Details: Pushes a string of characters onto the stack. The first character of the string is pushed first.

Parameters:
s - the string

push

public final void push(char[] src)
Pushes characters.

Details: push pushes an array of characters onto the stack.

Parameters:
src - the array
Since:
2000.06.03

push

public void push(char[] src,
                 int offset,
                 int amt)
Pushes characters.

Details: push pushes an array of characters (src) onto the stack, starting with the character at the given offset (offset), and pushing only amt characters.

Parameters:
src - the array
offset - the offset
amt - number of characters
Since:
2000.06.03

pop

public int pop()
Pops character.

Details: Pops a single character from the stack and returns it. If the stack is empty, -1 is returned.

Returns:
popped character

size

public int size()
Returns stack height.

Details: Returns the number of characters currently on the stack.

Returns:
stack height

clone

public java.lang.Object clone()
Clones stack.

Details: Returns an independent copy of this character stack. Useful for "backing up" the stack.

Overrides:
clone in class java.lang.Object
Returns:
copy

Sharkysoft home