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.
A 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 ClassesModifier and TypeClassDescriptionstatic interfaceFactory for new stack elements. -
Constructor Summary
ConstructorsConstructorDescription_Private_RecyclingStack(int initialCapacity, _Private_RecyclingStack.ElementFactory<T> elementFactory) -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEmpty()peek()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.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.intsize()
-
Constructor Details
-
_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 Details
-
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
- Returns:
- the element at the top of the stack, or null if the stack is empty.
-
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.
-