org.apache.commons.collections

Class StringStack

Implemented Interfaces:
Serializable

public class StringStack
extends java.lang.Object
implements Serializable

This class implements a stack for String objects.

This class provides a way to collect a list of unique strings and join them with an optional separator.

Version:
$Id: StringStack.java,v 1.3.2.1 2004/05/22 12:14:01 scolebourne Exp $
Authors:
John D. McNally
Daniel Rall
Stephen Colebourne
Since:
2.0

Constructor Summary

StringStack()
Creates an empty instance.

Method Summary

StringStack
add(String s)
Adds the String to the collection if it does not already contain it.
StringStack
addAll(StringStack ss)
Adds all Strings in the given StringStack to the collection (skipping those it already contains)
void
clear()
Clears the stack.
boolean
contains(String s)
Returns whether this stack contain the specified text.
boolean
empty()
Whether the stack is empty.
boolean
equals(Object ssbuf)
Compares two StringStacks.
String
get(int i)
Get a string off the stack at a certain position.
int
size()
Returns the size of the stack.
String
toString()
Converts the stack to a single java.lang.String with no separator.
String
toString(String separator)
Converts the stack to a single java.lang.String.
String[]
toStringArray()
Turns this stack into an array.

Constructor Details

StringStack

public StringStack()
Creates an empty instance.

Method Details

add

public StringStack add(String s)
Adds the String to the collection if it does not already contain it.
Parameters:
s - The String object to add to this stack (if it is not null and doesn't already exist in the stack).
Returns:
A reference to this stack (useful for when this method is called repeatedly).

addAll

public StringStack addAll(StringStack ss)
Adds all Strings in the given StringStack to the collection (skipping those it already contains)
Parameters:
ss - The stack of String objects to add to this stack (if it is not null and doesn't already exist in the stack).
Returns:
A reference to this stack (useful for when this method is called repeatedly).

clear

public void clear()
Clears the stack.

contains

public boolean contains(String s)
Returns whether this stack contain the specified text.
Parameters:
s - The text to search for.
Returns:
Whether the stack contains the text.

empty

public final boolean empty()
Whether the stack is empty.
Returns:
Whether the stack is empty.

equals

public boolean equals(Object ssbuf)
Compares two StringStacks. Considered equal if the toString() method returns such.

get

public String get(int i)
Get a string off the stack at a certain position.
Parameters:
i - The position.
Returns:
A the string from the specified position.

size

public final int size()
Returns the size of the stack.
Returns:
The size of the stack.

toString

public String toString()
Converts the stack to a single java.lang.String with no separator.
Returns:
The stack elements as a single block of text.

toString

public String toString(String separator)
Converts the stack to a single java.lang.String.
Parameters:
separator - The text to use as glue between elements in the stack.
Returns:
The stack elements--glued together by separator--as a single block of text.

toStringArray

public String[] toStringArray()
Turns this stack into an array.
Returns:
This stack as an array.

Copyright © 2001-2004 Apache Software Foundation. Documenation generated ${TODAY}.