Package org.apache.commons.rng.core.util
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
-
Nested Class Summary
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 final long
The upper limit of the range.private final RandomStreams.SeededObjectFactory
<T> Factory to create new instances.private static final String
Message when the consumer action is null.private long
The current position in the range.private long
Seed used to initialise the new instances.private final SplittableUniformRandomProvider
Source of randomness used to initialise the new instances.Fields inherited from interface java.util.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 TypeMethodDescriptionint
long
void
forEachRemaining
(Consumer<? super T> action) boolean
tryAdvance
(Consumer<? super T> action) 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.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
NULL_ACTION
Message when the consumer action is null.- See Also:
-
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 thestart
position.
-
-
Method Details
-
estimateSize
public long estimateSize()- Specified by:
estimateSize
in interfaceSpliterator<T>
-
characteristics
public int characteristics()- Specified by:
characteristics
in interfaceSpliterator<T>
-
trySplit
- Specified by:
trySplit
in interfaceSpliterator<T>
-
tryAdvance
- Specified by:
tryAdvance
in interfaceSpliterator<T>
-
forEachRemaining
- Specified by:
forEachRemaining
in interfaceSpliterator<T>
-