Top Description Inners Fields Constructors Methods
com.amazon.ion.impl

public final Class _Private_RecyclingStack<T>

extends Object
implements Iterable<T>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Type Parameters
<T>
the type of elements stored.
Imports
java.util.ArrayList, .List, .ListIterator, .NoSuchElementException

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 and Inner Type Summary

Modifier and TypeClass and Description
private class
public static interface
_Private_RecyclingStack.ElementFactory<
the type of element.
T
>

Factory for new stack elements.

public static interface

Field Summary

Modifier and TypeField and Description
private int
private final _Private_RecyclingStack.ElementFactory<T>
private final List<T>
public _Private_RecyclingStack<T>.$Iterator
private T

Constructor Summary

AccessConstructor and Description
public
_Private_RecyclingStack(int
the initial capacity of the underlying collection.
initialCapacity
,
_Private_RecyclingStack.ElementFactory<T>
the factory used to create a new element on push(Recycler) when the stack has not previously grown to the new depth.
elementFactory
)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the stack is empty; otherwise, false.
isEmpty
()

public ListIterator<T>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public T

Returns:

the element at the top of the stack, or null if the stack is empty.
peek
()

public T

Returns:

the element that was at the top of the stack before the pop, or null if the stack was 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.

public T

Returns:

the element at the top of the stack after the push. This element must be initialized by the caller.
push
(_Private_RecyclingStack.Recycler<T> recycler)

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.

public int

Returns:

the number of elements on the stack.
size
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentIndexback to summary
private int currentIndex
elementFactoryback to summary
private final _Private_RecyclingStack.ElementFactory<T> elementFactory
elementsback to summary
private final List<T> elements
stackIteratorback to summary
public _Private_RecyclingStack<T>.$Iterator stackIterator
topback to summary
private T top

Constructor Detail

_Private_RecyclingStackback to summary
public _Private_RecyclingStack(int initialCapacity, _Private_RecyclingStack.ElementFactory<T> elementFactory)
Parameters
initialCapacity:int

the initial capacity of the underlying collection.

elementFactory:_Private_RecyclingStack.ElementFactory<T>

the factory used to create a new element on push(Recycler) when the stack has not previously grown to the new depth.

Method Detail

isEmptyback to summary
public boolean isEmpty()
Returns:boolean

true if the stack is empty; otherwise, false.

iteratorback to summary
public ListIterator<T> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:ListIterator<T>

an Iterator.

Annotations
@Override
peekback to summary
public T peek()
Returns:T

the element at the top of the stack, or null if the stack is empty.

popback to summary
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:T

the element that was at the top of the stack before the pop, or null if the stack was empty.

pushback to summary
public T push(_Private_RecyclingStack.Recycler<T> recycler)

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:T

the element at the top of the stack after the push. This element must be initialized by the caller.

sizeback to summary
public int size()
Returns:int

the number of elements on the stack.

com.amazon.ion.impl back to summary

private Class _Private_RecyclingStack.$Iterator

extends Object
implements ListIterator<T>
Class Inheritance
All Implemented Interfaces
java.util.ListIterator, java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
add(T
the element to insert
t
)

Implements java.util.ListIterator.add.

Inserts the specified element into the list (optional operation).

public boolean
hasNext()

Implements java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction.

public boolean
hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction.

public T
next()

Implements java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position.

public int
nextIndex()

Implements java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next.

public T
previous()

Implements java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards.

public int
previousIndex()

Implements java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous.

public void
remove()

Implements java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation).

public void
set(T
the element with which to replace the last element returned by next or previous
t
)

Implements java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cursorback to summary
private int cursor

Constructor Detail

$Iteratorback to summary
private $Iterator()

Method Detail

addback to summary
public void add(T t)

Implements java.util.ListIterator.add.

Doc from java.util.ListIterator.add.

Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned by next, if any, and after the element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Parameters
t:T

the element to insert

Annotations
@Override
hasNextback to summary
public boolean hasNext()

Implements java.util.ListIterator.hasNext.

Doc from java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the list iterator has more elements when traversing the list in the forward direction

Annotations
@Override
hasPreviousback to summary
public boolean hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Doc from java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.)

Returns:boolean

true if the list iterator has more elements when traversing the list in the reverse direction

Annotations
@Override
nextback to summary
public T next()

Implements java.util.ListIterator.next.

Doc from java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Returns:T

the next element in the list

Annotations
@Override
nextIndexback to summary
public int nextIndex()

Implements java.util.ListIterator.nextIndex.

Doc from java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next. (Returns list size if the list iterator is at the end of the list.)

Returns:int

the index of the element that would be returned by a subsequent call to next, or list size if the list iterator is at the end of the list

Annotations
@Override
previousback to summary
public T previous()

Implements java.util.ListIterator.previous.

Doc from java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Returns:T

the previous element in the list

Annotations
@Override
previousIndexback to summary
public int previousIndex()

Implements java.util.ListIterator.previousIndex.

Doc from java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the list iterator is at the beginning of the list.)

Returns:int

the index of the element that would be returned by a subsequent call to previous, or -1 if the list iterator is at the beginning of the list

Annotations
@Override
removeback to summary
public void remove()

Implements java.util.ListIterator.remove.

Doc from java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation). This call can only be made once per call to next or previous. It can be made only if add has not been called after the last call to next or previous.

Annotations
@Override
setback to summary
public void set(T t)

Implements java.util.ListIterator.set.

Doc from java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation). This call can be made only if neither remove nor add have been called after the last call to next or previous.

Parameters
t:T

the element with which to replace the last element returned by next or previous

Annotations
@Override
com.amazon.ion.impl back to summary

public Interface _Private_RecyclingStack.ElementFactory<T>

Type Parameters
<T>
the type of element.

Factory for new stack elements.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

a new instance.
newElement
()

Method Detail

newElementback to summary
public T newElement()
Returns:T

a new instance.

com.amazon.ion.impl back to summary

public Interface _Private_RecyclingStack.Recycler<T>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
recycle(T t)

Re-initialize an element

Method Detail

recycleback to summary
public void recycle(T t)

Re-initialize an element