Package com.graphaware.common.util
Class BoundedConcurrentStack<E>
- java.lang.Object
-
- com.graphaware.common.util.BoundedConcurrentStack<E>
-
- All Implemented Interfaces:
Iterable<E>
public class BoundedConcurrentStack<E> extends Object implements Iterable<E>
A stack (last-in-first-out) with a configurable maximum capacity. Optimised for high concurrent read throughput. When the number of elements in the stack exceeds its capacity, the oldest entries are dropped. Please note that in multi-threaded environments, the size of the stack can temporarily exceed this number. This is a design decision (to avoid synchronising writes).
-
-
Constructor Summary
Constructors Constructor Description BoundedConcurrentStack(int maxCapacity)
Construct a new stack.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isEmpty()
Iterator<E>
iterator()
Get iterator over the elements of this stack.void
populate(Collection<E> elements)
Populate the stack.void
push(E e)
Push an element onto the stack.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
push
public void push(E e)
Push an element onto the stack.- Parameters:
e
- to push.
-
populate
public void populate(Collection<E> elements)
Populate the stack. Please note that the elements are added to the stack in the reverse order than presented by the input parameters. In other words, the first element of the input parameter will be returned first by this stack's iterator.- Parameters:
elements
- to populate the stack with.
-
iterator
public Iterator<E> iterator()
Get iterator over the elements of this stack. Note that the order of iteration is the reverse of the order in which elements were added.
-
isEmpty
public boolean isEmpty()
- Returns:
- true iff the stack is empty.
-
-