public class IntStack
extends java.lang.Object
int
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. See the base
classes for other details of the implementation.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE
Default initial array size.
|
protected int[] |
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 |
---|
IntStack()
Default constructor.
|
IntStack(int size)
Constructor with initial size specified.
|
IntStack(int[] ints)
Constructor from array of ints.
|
IntStack(int size,
int growth)
Constructor with full specification.
|
IntStack(IntStack 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.
|
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.
|
int |
peek()
Copy top value from the stack.
|
int |
peek(int depth)
Copy a value from the stack.
|
int |
pop()
Pop a value from the stack.
|
int |
pop(int count)
Pop multiple values from the stack.
|
void |
push(int 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.
|
int[] |
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 int[] m_baseArray
public IntStack(int size, int growth)
size
- number of int
values initially allowed in
stackgrowth
- maximum size increment for growing stackpublic IntStack(int size)
size
- number of int
values initially allowed in
stackpublic IntStack()
public IntStack(IntStack base)
base
- instance being copiedpublic IntStack(int[] ints)
ints
- array of ints for initial contentsprivate void resizeCopy(java.lang.Object base, java.lang.Object grown)
base
- original array containing datagrown
- resized array for dataprivate void growArray(int required)
required
- new minimum size requiredpublic final void ensureCapacity(int min)
min
- minimum capacity to be guaranteedpublic void push(int value)
value
- value to be addedpublic int pop()
java.lang.ArrayIndexOutOfBoundsException
- on attempt to pop empty stackpublic int 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 int peek(int depth)
depth
- depth of value to be returnedjava.lang.ArrayIndexOutOfBoundsException
- on attempt to peek past end of
stackpublic int peek()
java.lang.ArrayIndexOutOfBoundsException
- on attempt to peek empty stackpublic int[] 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()