Package com.sosnoski.util.stack

Type-specific stack collection classes.

See:
          Description

Class Summary
IntStack Growable int stack with type specific access methods.
ObjectStack Growable Object stack with type specific access methods.
StackBase Base class for type-specific stack classes with any type of values (including primitive types).
StringStack Growable String stack with type specific access methods.
 

Package com.sosnoski.util.stack Description

Type-specific stack collection classes. The classes in this package implement type-specific stacks based on growable arrays. They support a subset of the normal collection methods, as well as appropriate stack methods. The standard public access methods in these classes are as follows:

Method SignatureFrom
void clear()StackBase
Object clone()implementation class
void ensureCapacity(int)GrowableBase
boolean isEmpty()StackBase
type peek()implementation class
type peek(int)implementation class
type pop()implementation class
type pop(int)implementation class
void push(type)implementation class
int size()StackBase
type[] toArray()implementation class

The access methods are unsynchronized for best performance. The user program must implement appropriate locking if multiple threads need to access an instance of these classes while that instance may be modified.

Collections of a primitive type and of a specific object type are both supported. All variations derive directly from the StackBase base class. To define a stack of a new type, generally you can use one of the existing classes as a base and do a text substitution of the type names.

For instance, to define a stack of instances of Thread just copy StringStack.java to a new file named ThreadStack.java, then do a global text substitution of "Thread" for "String" in the new file.

Primitive types are only slightly more complicated. To implement a stack of a primitive type other than the included int, you're best off basing it on StringStack.java. If you're doing this for double, for instance, you'd need to first substitute "DoubleStack" for "StringStack", then "double" for "String". The last step is deleting the "m_baseArray[m_countPresent] = null;" line within the pop method,which is not needed for primitive types.



Company Web Site

XML Benchmark Home