public class ObjectStack
extends java.lang.Object
Object
stack with type specific access methods. This
implementation is unsynchronized in order to provide the best possible
performance for typical usage scenarios, so explicit synchronization must
be implemented by a wrapper class or directly by the application in cases
where instances are modified in a multithreaded environment.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE
Default initial array size.
|
protected java.lang.Object[] |
m_baseArray
The underlying array used for storing the data.
|
protected int |
m_countLimit
Size of the current array.
|
protected int |
m_countPresent
The number of values currently present in the stack.
|
protected int |
m_maximumGrowth
Maximum size increment for growing array.
|
Constructor and Description |
---|
ObjectStack()
Default constructor.
|
ObjectStack(int size)
Constructor with initial size specified.
|
ObjectStack(int size,
int growth)
Constructor with full specification.
|
ObjectStack(java.lang.Object[] strings)
Constructor from array of strings.
|
ObjectStack(ObjectStack base)
Copy (clone) constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Set the stack to the empty state.
|
java.lang.Object |
clone()
Duplicates the object with the generic call.
|
private void |
discardValues(int from,
int to)
Discards values for a range of indices in the array.
|
void |
ensureCapacity(int min)
Ensure that the array has the capacity for at least the specified
number of values.
|
private int |
getAddIndex()
Gets the array offset for appending a value to those in the stack.
|
private void |
growArray(int required)
Increase the size of the array to at least a specified size.
|
boolean |
isEmpty()
Check if stack is empty.
|
java.lang.Object |
peek()
Copy top value from the stack.
|
java.lang.Object |
peek(int depth)
Copy a value from the stack.
|
java.lang.Object |
pop()
Pop a value from the stack.
|
java.lang.Object |
pop(int count)
Pop multiple values from the stack.
|
void |
push(java.lang.Object value)
Push a value on the stack.
|
private void |
resizeCopy(java.lang.Object base,
java.lang.Object grown)
Copy data after array resize.
|
int |
size()
Get the number of values currently present in the stack.
|
java.lang.Object[] |
toArray()
Constructs and returns a simple array containing the same data as held
in this stack.
|
public static final int DEFAULT_SIZE
protected int m_countLimit
protected int m_countPresent
protected int m_maximumGrowth
protected java.lang.Object[] m_baseArray
public ObjectStack(int size, int growth)
size
- number of Object
values initially allowed in
stackgrowth
- maximum size increment for growing stackpublic ObjectStack(int size)
size
- number of Object
values initially allowed in
stackpublic ObjectStack()
public ObjectStack(ObjectStack base)
base
- instance being copiedpublic ObjectStack(java.lang.Object[] strings)
strings
- array of strings for initial contentsprivate void resizeCopy(java.lang.Object base, java.lang.Object grown)
base
- original array containing datagrown
- resized array for dataprivate void discardValues(int from, int to)
from
- index of first value to be discardedto
- index past last value to be discardedprivate void growArray(int required)
required
- new minimum size requiredpublic final void ensureCapacity(int min)
min
- minimum capacity to be guaranteedpublic void push(java.lang.Object value)
value
- value to be addedpublic java.lang.Object pop()
java.lang.ArrayIndexOutOfBoundsException
- on attempt to pop empty stackpublic java.lang.Object pop(int count)
count
- number of values to pop from stack (must be strictly
positive)java.lang.ArrayIndexOutOfBoundsException
- on attempt to pop past end of
stackpublic java.lang.Object peek(int depth)
depth
- depth of value to be returnedjava.lang.ArrayIndexOutOfBoundsException
- on attempt to peek past end of
stackpublic java.lang.Object peek()
java.lang.ArrayIndexOutOfBoundsException
- on attempt to peek empty stackpublic java.lang.Object[] toArray()
public java.lang.Object clone()
clone
in class java.lang.Object
private int getAddIndex()
public int size()
public boolean isEmpty()
true
if stack empty, false
if notpublic void clear()