public class LongCyclicQueue extends AbstractLongList implements LongCollector
Modifier and Type | Class and Description |
---|---|
class |
LongCyclicQueue.PinnedIterator |
AbstractLongList.IndexIterator, AbstractLongList.SubList
LongCollector.Dummy
LongList.Single
DUMMY
Constructor and Description |
---|
LongCyclicQueue() |
LongCyclicQueue(int initialCapacity) |
Modifier and Type | Method and Description |
---|---|
void |
add(long x) |
void |
addAll(long... xs) |
void |
addAll(LongIterable iterable) |
void |
addAll(LongList xs) |
void |
attach(LongCyclicQueue.PinnedIterator iterator)
Attaches the specified iterator to this instance, so that it won't be possible to remove a value that
this iterator points at via
removeFirst() , removeFirst(int) , and clear() . |
void |
clear() |
void |
detach(LongCyclicQueue.PinnedIterator iterator) |
void |
ensureRoomToAdd(int nToAdd) |
long |
get(int i) |
int |
getCapacity() |
boolean |
isEmpty()
Checks whether collection is empty.
|
long |
peek()
Retrieves, but does not remove, the head of this queue,
|
LongCyclicQueue.PinnedIterator |
pinnedIterator()
Returns an iterator that, unlike normal iterators, survives concurrent modifications to this array:
neither
add(long) nor removeFirst() affect its value or make it throw
ConcurrentModificationException. |
LongCyclicQueue.PinnedIterator |
pinnedIterator(int idx)
Creates
pinned iterator pointing at the element at idx . |
long |
removeFirst()
Removes the first element and returns it.
|
int |
removeFirst(int n)
Removes the first n elements; if there are less elements present, removes all elements.
|
int |
size()
Size of the collection.
|
java.lang.String |
toStringWithPiterators() |
binarySearch, binarySearch, contains, equals, equalSortedUniqueValues, get, getLast, getNextDifferentValueIndex, hashCode, indexOf, isSorted, isSorted, isSortedUnique, iterator, iterator, iterator, subList, toList, toNativeArray, toNativeArray, toString, toString
public LongCyclicQueue(int initialCapacity)
public LongCyclicQueue()
public long get(int i)
public long peek()
java.util.NoSuchElementException
- if this queue is emptypublic int size()
LongList
size
in interface LongList
size
in interface LongSizedIterable
public boolean isEmpty()
LongList
isEmpty
in interface LongList
isEmpty
in class AbstractLongList
public void clear() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if there is any attached pinned iterator
.public void add(long x)
add
in interface LongCollector
public void addAll(long... xs)
addAll
in interface LongCollector
public void addAll(LongList xs)
addAll
in interface LongCollector
public void addAll(LongIterable iterable)
addAll
in interface LongCollector
public long removeFirst() throws java.util.NoSuchElementException, java.lang.IllegalStateException
java.util.NoSuchElementException
- if this array is emptyjava.lang.IllegalStateException
- if there is a pinnedIterator()
pointing at the first elementpublic int removeFirst(int n) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
java.lang.IndexOutOfBoundsException
- if n is negativejava.lang.IllegalStateException
- if there is a pinnedIterator()
pointing at any of the elements
to be removedpublic void ensureRoomToAdd(int nToAdd)
public int getCapacity()
@NotNull public LongCyclicQueue.PinnedIterator pinnedIterator()
Returns an iterator that, unlike normal iterators, survives concurrent modifications to this array:
neither add(long)
nor removeFirst()
affect its value or make it throw
ConcurrentModificationException.
Note that one could alternatively use the index of the current position in this sliding array, but they would need to update that index upon each modification, because these modifications move the window of active indices. In that regard, this iterator is "pinned" to the position in the host array.
Moreover, while this iterator is attached
, the elements this iterator points at
cannot be removed. Iterator points at its current (if present) and next element.
Because of that, one needs to call detach(com.almworks.integers.LongCyclicQueue.PinnedIterator)
on the iterator that will not be used,
so that removals of the element the iterator points at are possible.
public LongCyclicQueue.PinnedIterator pinnedIterator(int idx)
pinned iterator
pointing at the element at idx
.idx
- set 0 to have iterator return the first element from the first call to nextValue()public void attach(@Nullable LongCyclicQueue.PinnedIterator iterator)
Attaches the specified iterator to this instance, so that it won't be possible to remove a value that
this iterator points at via removeFirst()
, removeFirst(int)
, and clear()
.
Initially, iterator is attached (see pinnedIterator()
.)
If the specified iterator is not over this instance, the effect is undefined.
public void detach(@Nullable LongCyclicQueue.PinnedIterator iterator)
public java.lang.String toStringWithPiterators()