Package org.htmlunit.cyberneko.util
Class MiniStack<E>
- java.lang.Object
-
- org.htmlunit.cyberneko.util.MiniStack<E>
-
public class MiniStack<E> extends java.lang.Object
Extremely light stack implementation. Perfect for inlining.- Since:
- 3.10.0
-
-
Constructor Summary
Constructors Constructor Description MiniStack()
Create a new empty stack with 8 elements capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Empties the stack.boolean
isEmpty()
Checks if we have any element at all on the stack.E
peek()
Returns the top/last element without removing it.E
pop()
Removes and returns the last elementvoid
push(E element)
Add a new element on top of the stack.void
reset()
Resets the stack to zero but does not clean it.int
size()
Returns the current size of the stack.
-
-
-
Method Detail
-
clear
public void clear()
Empties the stack. It will not only reset the pointer but empty out the backing array to ensure we are not holding old references.
-
reset
public void reset()
Resets the stack to zero but does not clean it. Use with caution to avoid holding old objects and preventing them from GC.
-
pop
public E pop()
Removes and returns the last element- Returns:
- the last element or null of none
-
peek
public E peek()
Returns the top/last element without removing it. Will return null if we don't have a last element.- Returns:
- the top/last element if any, null otherwise
-
push
public void push(E element)
Add a new element on top of the stack. You can add null but the return value of pop and peek will become ambiguous.- Parameters:
element
- the element to add
-
isEmpty
public boolean isEmpty()
Checks if we have any element at all on the stack.- Returns:
- true if the stack holds elements, false otherwise
-
size
public int size()
Returns the current size of the stack.- Returns:
- the size of the stack, always >= 0
-
-