Package org.web3d.util
Class SimpleStack
java.lang.Object
org.web3d.util.SimpleStack
- All Implemented Interfaces:
SimpleStackInterface
- Direct Known Subclasses:
SimpleStackLogged
A stack that has a minimal implementation and no synchronisation.
This stack is designed to be used in a high-speed, single threaded environment. It is directly backed by an array for fast access.
- Version:
- $Revision: 1.10 $
- Author:
- Justin Couch
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
The initial size of the stack for element processing -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty hashtable with a default capacity and load factor, which is20
respectively.SimpleStack
(int initialCapacity) Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is0.75
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears this stack so that it contains no values.boolean
Returns true if this stack contains an instance of the value.boolean
isEmpty()
Tests if this stack maps no values.peek()
Peek at the value on the top of the stack without removing it.pop()
Pop the value from the top of the stack.void
Push a new value onto the top of the stack.void
Remove the given object from the stack if it exists.int
size()
Returns the number of keys in this hashtable.toString()
Generate a string representation of this stack object.
-
Field Details
-
STACK_START_SIZE
protected static final int STACK_START_SIZEThe initial size of the stack for element processing- See Also:
-
-
Constructor Details
-
SimpleStack
public SimpleStack()Constructs a new, empty hashtable with a default capacity and load factor, which is20
respectively. -
SimpleStack
public SimpleStack(int initialCapacity) Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is0.75
.- Parameters:
initialCapacity
- the initial capacity of the hashtable.- Throws:
IllegalArgumentException
- if the initial capacity is less than zero.
-
-
Method Details
-
toString
-
size
public int size()Returns the number of keys in this hashtable.- Specified by:
size
in interfaceSimpleStackInterface
- Returns:
- the number of keys in this hashtable.
-
isEmpty
public boolean isEmpty()Tests if this stack maps no values.- Specified by:
isEmpty
in interfaceSimpleStackInterface
- Returns:
true
if this stack has no values
-
push
Push a new value onto the top of the stack. The value may be any legal reference to an object including null.- Specified by:
push
in interfaceSimpleStackInterface
- Parameters:
val
- The new value for the stack.
-
peek
Peek at the value on the top of the stack without removing it. If the value pushed was null, then null is returned here.- Specified by:
peek
in interfaceSimpleStackInterface
- Returns:
- A reference to the object on the top of the stack
- Throws:
EmptyStackException
- The stack is currently empty
-
pop
Pop the value from the top of the stack. If the last value in the stack was null then this will return null.- Specified by:
pop
in interfaceSimpleStackInterface
- Returns:
- The top object on the stack
-
contains
Returns true if this stack contains an instance of the value. The checl looks at both the reference comparison (==) and the equality using.equals()
. If the stack is currently empty this will always return false. The search order is from the top of the stack towards the bottom.- Specified by:
contains
in interfaceSimpleStackInterface
- Parameters:
value
- The value whose presence in this stack is to be tested.- Returns:
- true if this stack contains the value.
-
remove
Remove the given object from the stack if it exists. If it is not in the stack, then ignore it quietly.- Specified by:
remove
in interfaceSimpleStackInterface
- Parameters:
obj
- The object to be removed
-
clear
public void clear()Clears this stack so that it contains no values.- Specified by:
clear
in interfaceSimpleStackInterface
-