Class RandomStreams.SeededObjectSpliterator<T>
java.lang.Object
org.apache.commons.rng.core.util.RandomStreams.SeededObjectSpliterator<T>
- Type Parameters:
T- the object type
- All Implemented Interfaces:
Spliterator<T>
- Enclosing class:
RandomStreams
private static final class RandomStreams.SeededObjectSpliterator<T>
extends Object
implements Spliterator<T>
Spliterator for streams of a given object type that can be created from a seed
and source of randomness. The source of randomness is splittable allowing parallel
stream support.
The seed is mixed with the stream position to ensure each object is created using a unique seed value. As the position increases the seed is left shifted until there is no bit overlap between the seed and the position, i.e the right-most 1-bit of the seed is larger than the left-most 1-bit of the position. s
- Since:
- 1.5
-
Nested Class Summary
Nested classes/interfaces inherited from interface Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,T_CONS, T_SPLITR> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longThe upper limit of the range.private final RandomStreams.SeededObjectFactory<T> Factory to create new instances.private static final StringMessage when the consumer action is null.private longThe current position in the range.private longSeed used to initialise the new instances.private final SplittableUniformRandomProviderSource of randomness used to initialise the new instances.Fields inherited from interface Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
ConstructorsConstructorDescriptionSeededObjectSpliterator(long start, long end, SplittableUniformRandomProvider source, RandomStreams.SeededObjectFactory<T> factory, long seed) -
Method Summary
Modifier and TypeMethodDescriptionintlongvoidforEachRemaining(Consumer<? super T> action) booleantryAdvance(Consumer<? super T> action) trySplit()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
NULL_ACTION
-
position
private long positionThe current position in the range. -
end
private final long endThe upper limit of the range. -
seed
private long seedSeed used to initialise the new instances. The least significant 1-bit of the seed must be above the most significant bit of the position. This is maintained by left shift when the position is updated. -
source
Source of randomness used to initialise the new instances. -
factory
Factory to create new instances.
-
-
Constructor Details
-
SeededObjectSpliterator
SeededObjectSpliterator(long start, long end, SplittableUniformRandomProvider source, RandomStreams.SeededObjectFactory<T> factory, long seed) - Parameters:
start- Start position of the stream (inclusive).end- Upper limit of the stream (exclusive).source- Source of randomness used to initialise the new instances.factory- Factory to create new instances.seed- Seed used to initialise the instances. The least significant 1-bit of the seed must be above the most significant bit of thestartposition.
-
-
Method Details
-
estimateSize
public long estimateSize()- Specified by:
estimateSizein interfaceSpliterator<T>
-
characteristics
public int characteristics()- Specified by:
characteristicsin interfaceSpliterator<T>
-
trySplit
- Specified by:
trySplitin interfaceSpliterator<T>
-
tryAdvance
- Specified by:
tryAdvancein interfaceSpliterator<T>
-
forEachRemaining
- Specified by:
forEachRemainingin interfaceSpliterator<T>
-