Package org.apache.sis.util.collection
Class IntegerList.PrimitiveSpliterator
java.lang.Object
org.apache.sis.util.collection.IntegerList.PrimitiveSpliterator
- All Implemented Interfaces:
Iterator<Integer>
,PrimitiveIterator<Integer,
,IntConsumer> PrimitiveIterator.OfInt
,Spliterator<Integer>
,Spliterator.OfInt
,Spliterator.OfPrimitive<Integer,
IntConsumer, Spliterator.OfInt>
- Enclosing class:
IntegerList
private final class IntegerList.PrimitiveSpliterator
extends Object
implements Spliterator.OfInt, PrimitiveIterator.OfInt
Same as
IntegerList.spliterator()
, but without value boxing.
This spliterator provides a fail-fast way to traverse list content, which means
that any alteration to the list content causes a failure of the advance operation
with a ConcurrentModificationException
.
This implementation opportunistically provides an iterator implementation on
integer values too, but only one of the Iterator
or Spliterator
API should be used on a given instance.
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.PrimitiveIterator
PrimitiveIterator.OfDouble, PrimitiveIterator.OfInt, PrimitiveIterator.OfLong
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,
T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
TheAbstractList.modCount
value as iterator construction time.private int
Index of the last elements removed by aremove()
operation.private int
Index of the next element to be returned.private int
Index after the last element returned by this spliterator.Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
Creates a new iterator for the whole content of the backing list.private
PrimitiveSpliterator
(IntegerList.PrimitiveSpliterator suffix, int startAt) Creates the prefix spliterator in a call totrySplit()
. -
Method Summary
Modifier and TypeMethodDescriptionint
Declares that this split iterator does not return null elements, that all elements are traversed in a fixed order (which is increasing index values) and thatIntegerList.size()
represents an exact count of elements.long
Returns the exact number of values to be encountered by aforEachRemaining(…)
traversal.void
forEachRemaining
(Consumer<? super Integer> action) Performs the given action on all remaining elements.void
forEachRemaining
(IntConsumer action) Performs the given action on all remaining elements.boolean
hasNext()
Returnstrue
if there is one more value to return.int
nextInt()
Returns the next integer values in iterator order.void
remove()
Removes the last element returned bynextInt()
.boolean
tryAdvance
(IntConsumer action) If a remaining element exists, performs the given action on it and returnstrue
.trySplit()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.PrimitiveIterator.OfInt
next
Methods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
Methods inherited from interface java.util.Spliterator.OfInt
tryAdvance
-
Field Details
-
stopAt
private int stopAtIndex after the last element returned by this spliterator. This is initiallyIntegerList.size
, but may be set to a smaller value by call totrySplit()
. -
nextIndex
private int nextIndexIndex of the next element to be returned. -
expectedModCount
private int expectedModCountTheAbstractList.modCount
value as iterator construction time. Used for detecting modification in the backing list during traversal. -
lastRemove
private int lastRemoveIndex of the last elements removed by aremove()
operation. This is used for checking thatremove()
is not invoked twice before the next advance.
-
-
Constructor Details
-
PrimitiveSpliterator
PrimitiveSpliterator()Creates a new iterator for the whole content of the backing list. -
PrimitiveSpliterator
Creates the prefix spliterator in a call totrySplit()
.- Parameters:
suffix
- the spliterator which will continue iteration after this spliterator.startAt
- index of the first element to be returned by this prefix spliterator.
-
-
Method Details
-
characteristics
public int characteristics()Declares that this split iterator does not return null elements, that all elements are traversed in a fixed order (which is increasing index values) and thatIntegerList.size()
represents an exact count of elements.- Specified by:
characteristics
in interfaceSpliterator<Integer>
-
estimateSize
public long estimateSize()Returns the exact number of values to be encountered by aforEachRemaining(…)
traversal.- Specified by:
estimateSize
in interfaceSpliterator<Integer>
-
trySplit
- Specified by:
trySplit
in interfaceSpliterator<Integer>
- Specified by:
trySplit
in interfaceSpliterator.OfInt
- Specified by:
trySplit
in interfaceSpliterator.OfPrimitive<Integer,
IntConsumer, Spliterator.OfInt>
-
hasNext
public boolean hasNext()Returnstrue
if there is one more value to return. This method also ensures that no alteration has happened on the backing list since the spliterator creation. -
nextInt
public int nextInt()Returns the next integer values in iterator order.- Specified by:
nextInt
in interfacePrimitiveIterator.OfInt
-
tryAdvance
If a remaining element exists, performs the given action on it and returnstrue
. Otherwise returnsfalse
.- Specified by:
tryAdvance
in interfaceSpliterator.OfInt
- Specified by:
tryAdvance
in interfaceSpliterator.OfPrimitive<Integer,
IntConsumer, Spliterator.OfInt>
-
forEachRemaining
Performs the given action on all remaining elements. This implementation is shared by bothIterator
andSpliterator
interfaces.- Specified by:
forEachRemaining
in interfacePrimitiveIterator<Integer,
IntConsumer> - Specified by:
forEachRemaining
in interfacePrimitiveIterator.OfInt
- Specified by:
forEachRemaining
in interfaceSpliterator.OfInt
- Specified by:
forEachRemaining
in interfaceSpliterator.OfPrimitive<Integer,
IntConsumer, Spliterator.OfInt>
-
forEachRemaining
Performs the given action on all remaining elements. This implementation is shared by bothIterator
andSpliterator
interfaces.- Specified by:
forEachRemaining
in interfaceIterator<Integer>
- Specified by:
forEachRemaining
in interfacePrimitiveIterator.OfInt
- Specified by:
forEachRemaining
in interfaceSpliterator<Integer>
- Specified by:
forEachRemaining
in interfaceSpliterator.OfInt
-
remove
public void remove()Removes the last element returned bynextInt()
.
-