Class FixedStack<N>
- java.lang.Object
-
- com.conversantmedia.util.collection.FixedStack<N>
-
- All Implemented Interfaces:
Stack<N>
public class FixedStack<N> extends java.lang.Object implements Stack<N>
A very high performance stack to replace java.util.Stack. This stack wraps around rather than checking for bounds. The java version of Stack is based on Vector and completely outdated. The performance of java.util.Stack is poor at best. This version is a small fast fixed size stack. There is no bounds checking so it should only be used when the stack size is known in advance. This object is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description FixedStack(int size)
construct a new stack of given capacity
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
clear the stackboolean
contains(N n)
Linear search the stack for contains - not an efficient operationboolean
isEmpty()
N
peek()
peek at the top of the stackN
pop()
pop the next element off the stackboolean
push(N n)
add an element to the stackint
remainingCapacity()
how much available space in the stackint
size()
Return the size of the stack
-
-
-
Field Detail
-
size
private final int size
-
mask
private final int mask
-
stack
private final N[] stack
-
stackTop
private int stackTop
-
-
Method Detail
-
push
public boolean push(N n)
add an element to the stack
-
contains
public boolean contains(N n)
Description copied from interface:Stack
Linear search the stack for contains - not an efficient operation
-
peek
public N peek()
peek at the top of the stack
-
pop
public N pop()
pop the next element off the stack
-
size
public int size()
Return the size of the stack
-
remainingCapacity
public int remainingCapacity()
how much available space in the stack- Specified by:
remainingCapacity
in interfaceStack<N>
- Returns:
- int - the number of empty slots available in the stack
-
isEmpty
public boolean isEmpty()
-
-