Class RandomStreams.SeededObjectSpliterator<T>

  • Type Parameters:
    T - the object type
    All Implemented Interfaces:
    java.util.Spliterator<T>
    Enclosing class:
    RandomStreams

    private static final class RandomStreams.SeededObjectSpliterator<T>
    extends java.lang.Object
    implements java.util.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

        java.util.Spliterator.OfDouble, java.util.Spliterator.OfInt, java.util.Spliterator.OfLong, java.util.Spliterator.OfPrimitive<T extends java.lang.Object,​T_CONS extends java.lang.Object,​T_SPLITR extends java.util.Spliterator.OfPrimitive<T,​T_CONS,​T_SPLITR>>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long end
      The upper limit of the range.
      private RandomStreams.SeededObjectFactory<T> factory
      Factory to create new instances.
      private static java.lang.String NULL_ACTION
      Message when the consumer action is null.
      private long position
      The current position in the range.
      private long seed
      Seed used to initialise the new instances.
      private SplittableUniformRandomProvider source
      Source of randomness used to initialise the new instances.
      • Fields inherited from interface java.util.Spliterator

        CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int characteristics()  
      long estimateSize()  
      void forEachRemaining​(java.util.function.Consumer<? super T> action)  
      boolean tryAdvance​(java.util.function.Consumer<? super T> action)  
      java.util.Spliterator<T> 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 Detail

      • NULL_ACTION

        private static final java.lang.String NULL_ACTION
        Message when the consumer action is null.
        See Also:
        Constant Field Values
      • position

        private long position
        The current position in the range.
      • end

        private final long end
        The upper limit of the range.
      • seed

        private long seed
        Seed 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.
    • Constructor Detail

      • 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 the start position.
    • Method Detail

      • estimateSize

        public long estimateSize()
        Specified by:
        estimateSize in interface java.util.Spliterator<T>
      • characteristics

        public int characteristics()
        Specified by:
        characteristics in interface java.util.Spliterator<T>
      • trySplit

        public java.util.Spliterator<T> trySplit()
        Specified by:
        trySplit in interface java.util.Spliterator<T>
      • tryAdvance

        public boolean tryAdvance​(java.util.function.Consumer<? super T> action)
        Specified by:
        tryAdvance in interface java.util.Spliterator<T>
      • forEachRemaining

        public void forEachRemaining​(java.util.function.Consumer<? super T> action)
        Specified by:
        forEachRemaining in interface java.util.Spliterator<T>