Package com.amazon.ion.impl
Class _Private_RecyclingStack<T>
- java.lang.Object
-
- com.amazon.ion.impl._Private_RecyclingStack<T>
-
- Type Parameters:
T- the type of elements stored.
public final class _Private_RecyclingStack<T> extends java.lang.ObjectA stack whose elements are recycled. This can be useful when the stack needs to grow and shrink frequently and has a predictable maximum depth.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface_Private_RecyclingStack.ElementFactory<T>Factory for new stack elements.
-
Constructor Summary
Constructors Constructor Description _Private_RecyclingStack(int initialCapacity, _Private_RecyclingStack.ElementFactory<T> elementFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisEmpty()Tpeek()Tpop()Pops an element from the stack, retaining a reference to the element so that it can be reused the next time the stack grows to the element's depth.Tpush()Pushes an element onto the top of the stack, instantiating a new element only if the stack has not previously grown to the new depth.intsize()
-
-
-
Constructor Detail
-
_Private_RecyclingStack
public _Private_RecyclingStack(int initialCapacity, _Private_RecyclingStack.ElementFactory<T> elementFactory)- Parameters:
initialCapacity- the initial capacity of the underlying collection.elementFactory- the factory used to create a new element onpush()when the stack has not previously grown to the new depth.
-
-
Method Detail
-
push
public T push()
Pushes an element onto the top of the stack, instantiating a new element only if the stack has not previously grown to the new depth.- Returns:
- the element at the top of the stack after the push. This element must be initialized by the caller.
-
peek
public T peek()
- Returns:
- the element at the top of the stack, or null if the stack is empty.
-
pop
public T pop()
Pops an element from the stack, retaining a reference to the element so that it can be reused the next time the stack grows to the element's depth.- Returns:
- the element that was at the top of the stack before the pop, or null if the stack was empty.
-
isEmpty
public boolean isEmpty()
- Returns:
- true if the stack is empty; otherwise, false.
-
size
public int size()
- Returns:
- the number of elements on the stack.
-
-