public class ObjectStack extends 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 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(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.
|
Object |
clone()
Duplicates the object with the generic call.
|
void |
ensureCapacity(int min)
Ensure that the array has the capacity for at least the specified
number of values.
|
boolean |
isEmpty()
Check if stack is empty.
|
Object |
peek()
Copy top value from the stack.
|
Object |
peek(int depth)
Copy a value from the stack.
|
Object |
pop()
Pop a value from the stack.
|
Object |
pop(int count)
Pop multiple values from the stack.
|
void |
push(Object value)
Push a value on the stack.
|
int |
size()
Get the number of values currently present in the stack.
|
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 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(Object[] strings)
strings - array of strings for initial contentspublic final void ensureCapacity(int min)
min - minimum capacity to be guaranteedpublic void push(Object value)
value - value to be addedpublic Object pop()
ArrayIndexOutOfBoundsException - on attempt to pop empty stackpublic Object pop(int count)
count - number of values to pop from stack (must be strictly
positive)ArrayIndexOutOfBoundsException - on attempt to pop past end of
stackpublic Object peek(int depth)
depth - depth of value to be returnedArrayIndexOutOfBoundsException - on attempt to peek past end of
stackpublic Object peek()
ArrayIndexOutOfBoundsException - on attempt to peek empty stackpublic Object[] toArray()
public Object clone()
public int size()
public boolean isEmpty()
true if stack empty, false if notpublic void clear()
Copyright © 2005–2016 jibx.org. All rights reserved.