Package org.agrona.collections
Class LongArrayQueue
Queue of longs which stores the elements without boxing. Null is represented by a special
nullValue().
The LongArrayQueue.LongIterator is cached by default to avoid allocation unless directed to do so in the constructor.
Note: This class is not threadsafe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classSpecialisedIteratorfrom which the value can be retrieved without boxing viaLongArrayQueue.LongIterator.nextValue(). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault representation of null for an element.static final intMinimum capacity for the queue which must also be a power of 2. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new queue defaulting toMIN_CAPACITYcapacity,DEFAULT_NULL_VALUEand cached iterators.LongArrayQueue(int initialCapacity, long nullValue) Construct a new queue default to cached iterators.LongArrayQueue(int initialCapacity, long nullValue, boolean shouldAvoidAllocation) Construct a new queue providing all the config options.LongArrayQueue(long nullValue) Construct a new queue defaulting toMIN_CAPACITYcapacity and cached iterators. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddLong(long element) Offer an element to the tail of the queue without boxing.intcapacity()The current capacity for the collection.voidclear()element()longPeek at the element on the head of the queue without boxing.voidvoidforEachLong(LongConsumer action) Iterate over the collection without boxing.booleanisEmpty()iterator()longThe value representing a null element.booleanbooleanofferLong(long element) Offer an element to the tail of the queue without boxing.peek()longpeekLong()Peek at the element on the head of the queue without boxing.poll()longpollLong()Poll the element from the head of the queue without boxing.remove()longRemove the element at the head of the queue without boxing.intsize()toString()Methods inherited from class java.util.AbstractQueue
addAllMethods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
DEFAULT_NULL_VALUE
public static final long DEFAULT_NULL_VALUEDefault representation of null for an element.- See Also:
-
MIN_CAPACITY
public static final int MIN_CAPACITYMinimum capacity for the queue which must also be a power of 2.- See Also:
-
-
Constructor Details
-
LongArrayQueue
public LongArrayQueue()Construct a new queue defaulting toMIN_CAPACITYcapacity,DEFAULT_NULL_VALUEand cached iterators. -
LongArrayQueue
public LongArrayQueue(long nullValue) Construct a new queue defaulting toMIN_CAPACITYcapacity and cached iterators.- Parameters:
nullValue- cannot be stored in the queue and used as a sentinel.
-
LongArrayQueue
public LongArrayQueue(int initialCapacity, long nullValue) Construct a new queue default to cached iterators.- Parameters:
initialCapacity- for the queue which will be rounded up to the nearest power of 2.nullValue- which cannot be stored in the queue and used as a sentinel.
-
LongArrayQueue
public LongArrayQueue(int initialCapacity, long nullValue, boolean shouldAvoidAllocation) Construct a new queue providing all the config options.- Parameters:
initialCapacity- for the queue which will be rounded up to the nearest power of 2.nullValue- which cannot be stored in the queue and used as a sentinel.shouldAvoidAllocation- true to cache the iterator otherwise false to allocate a new iterator each time.
-
-
Method Details
-
nullValue
public long nullValue()The value representing a null element.- Returns:
- value representing a null element.
-
capacity
public int capacity()The current capacity for the collection.- Returns:
- the current capacity for the collection.
-
size
public int size()- Specified by:
sizein interfaceCollection<Long>- Specified by:
sizein classAbstractCollection<Long>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Long>- Overrides:
isEmptyin classAbstractCollection<Long>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<Long>- Overrides:
clearin classAbstractQueue<Long>
-
offer
-
offerLong
public boolean offerLong(long element) Offer an element to the tail of the queue without boxing.- Parameters:
element- to be offered to the queue.- Returns:
- will always be true as long as the underlying array can be expanded.
-
add
- Specified by:
addin interfaceCollection<Long>- Specified by:
addin interfaceQueue<Long>- Overrides:
addin classAbstractQueue<Long>
-
addLong
public boolean addLong(long element) Offer an element to the tail of the queue without boxing.- Parameters:
element- to be offered to the queue.- Returns:
- will always be true as long as the underlying array can be expanded.
-
peek
-
peekLong
public long peekLong()Peek at the element on the head of the queue without boxing.- Returns:
- the element at the head of the queue without removing it.
-
poll
-
pollLong
public long pollLong()Poll the element from the head of the queue without boxing.- Returns:
- the element at the head of the queue removing it. If empty then
nullValue.
-
remove
-
element
-
elementLong
public long elementLong()Peek at the element on the head of the queue without boxing.- Returns:
- the element at the head of the queue without removing it.
- Throws:
NoSuchElementException- if the queue is empty.
-
removeLong
public long removeLong()Remove the element at the head of the queue without boxing.- Returns:
- the element at the head of the queue.
- Throws:
NoSuchElementException- if the queue is empty.
-
toString
- Overrides:
toStringin classAbstractCollection<Long>
-
forEach
-
forEachLong
Iterate over the collection without boxing.- Parameters:
action- to be taken for each element.
-
iterator
- Specified by:
iteratorin interfaceCollection<Long>- Specified by:
iteratorin interfaceIterable<Long>- Specified by:
iteratorin classAbstractCollection<Long>
-