Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8265221

java.util.Random suddenly has new public methods nowhere documented

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
      source, binary
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      New APIs only recently pushed (no release contains methods.)
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      makeXXXSpliterator methods in java.util.Random,java.util.concurrent.ThreadLocalRandom and java.util.SplittableRandom should not be public.

      Problem

      The makeXXXSpliterator methods were meant to be overridden by implementors of RandomGenerators but never meant to be part of the user API. The current implementation poorly hides the existence of these methods, and exposes them with public access.

      Solution

      Implement these methods as static methods in RandomSupport and call from instance methods in Random and ThreadRandomLocal. With this dependency gone, Random can implement RandomGenerator directly without extending AbstractSpliteratorGenerator.

      No javadoc is affected other than the interfaces implemented by Random.

      Specification

          diff --git a/src/java.base/share/classes/java/util/Random.java b/src/java.base/share/classes/java/util/Random.java
          index 9c2f1534cf1..a1c7d66c83f 100644
          --- a/src/java.base/share/classes/java/util/Random.java
          +++ b/src/java.base/share/classes/java/util/Random.java
          @@ -27,15 +27,12 @@ package java.util;
      
           import java.io.*;
           import java.util.concurrent.atomic.AtomicLong;
          +import java.util.random.RandomGenerator;
           import java.util.stream.DoubleStream;
           import java.util.stream.IntStream;
           import java.util.stream.LongStream;
          +import jdk.internal.util.random.RandomSupport.*;
      
          -import jdk.internal.util.random.RandomSupport.AbstractSpliteratorGenerator;
          -import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
          -import jdk.internal.util.random.RandomSupport.RandomIntsSpliterator;
          -import jdk.internal.util.random.RandomSupport.RandomLongsSpliterator;
          -import jdk.internal.util.random.RandomSupport.RandomDoublesSpliterator;
           import static jdk.internal.util.random.RandomSupport.*;
      
           import jdk.internal.misc.Unsafe;
          @@ -85,8 +82,7 @@ import jdk.internal.misc.Unsafe;
                   i = 48, j = 0, k = 0,
                   equidistribution = 0
           )
          -public class Random extends AbstractSpliteratorGenerator
          -        implements java.io.Serializable {
          +public class Random implements RandomGenerator, java.io.Serializable {
               /** use serialVersionUID from JDK 1.1 for interoperability */
               @java.io.Serial
               static final long serialVersionUID = 3905348978240129619L;
          @@ -615,32 +611,6 @@ public class Random extends AbstractSpliteratorGenerator
                   unsafe.putReferenceVolatile(this, seedOffset, new AtomicLong(seedVal));
               }
      
          -    // Methods required by class AbstractSpliteratorGenerator
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
          -        return new RandomIntsSpliterator(this, index, fence, origin, bound);
          -    }
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
          -        return new RandomLongsSpliterator(this, index, fence, origin, bound);
          -    }
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
          -        return new RandomDoublesSpliterator(this, index, fence, origin, bound);
          -    }
          -
               /**
                * Returns a stream producing the given {@code streamSize} number of
                * pseudorandom {@code int} values.
          @@ -656,7 +626,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public IntStream ints(long streamSize) {
          -        return super.ints(streamSize);
          +        return AbstractSpliteratorGenerator.ints(this, streamSize);
               }
      
               /**
          @@ -674,7 +644,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public IntStream ints() {
          -        return super.ints();
          +        return AbstractSpliteratorGenerator.ints(this);
               }
      
               /**
          @@ -711,7 +681,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
          -        return super.ints(streamSize, randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.ints(this, streamSize, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -749,7 +719,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
          -        return super.ints(randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.ints(this, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -767,7 +737,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public LongStream longs(long streamSize) {
          -        return super.longs(streamSize);
          +        return AbstractSpliteratorGenerator.longs(this, streamSize);
               }
      
               /**
          @@ -785,7 +755,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public LongStream longs() {
          -        return super.longs();
          +        return AbstractSpliteratorGenerator.longs(this);
               }
      
               /**
          @@ -827,7 +797,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) {
          -        return super.longs(streamSize, randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.longs(this, streamSize, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -870,7 +840,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
          -        return super.longs(randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.longs(this, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -889,7 +859,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public DoubleStream doubles(long streamSize) {
          -        return super.doubles(streamSize);
          +        return AbstractSpliteratorGenerator.doubles(this, streamSize);
               }
      
               /**
          @@ -908,7 +878,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public DoubleStream doubles() {
          -        return super.doubles();
          +        return AbstractSpliteratorGenerator.doubles(this);
               }
      
              /**
          @@ -940,7 +910,7 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) {
          -        return super.doubles(streamSize, randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.doubles(this, streamSize, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -972,6 +942,6 @@ public class Random extends AbstractSpliteratorGenerator
                */
               @Override
               public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
          -        return super.doubles(randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.doubles(this, randomNumberOrigin, randomNumberBound);
               }
           }
          diff --git a/src/java.base/share/classes/java/util/SplittableRandom.java b/src/java.base/share/classes/java/util/SplittableRandom.java
          index 718a0051490..77bfa17593a 100644
          --- a/src/java.base/share/classes/java/util/SplittableRandom.java
          +++ b/src/java.base/share/classes/java/util/SplittableRandom.java
          @@ -280,30 +280,6 @@ public final class SplittableRandom extends AbstractSplittableGenerator {
                   return new SplittableRandom(source.nextLong(), mixGamma(source.nextLong()));
               }
      
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
          -        return super.makeIntsSpliterator(index, fence, origin, bound);
          -    }
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
          -        return super.makeLongsSpliterator(index, fence, origin, bound);
          -    }
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
          -        return super.makeDoublesSpliterator(index, fence, origin, bound);
          -    }
          -
               @Override
               public int nextInt() {
                   return mix32(nextSeed());
          diff --git a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java
          index 0727f1e57e0..2f415ca806b 100644
          --- a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java
          +++ b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java
          @@ -51,11 +51,7 @@ import java.util.stream.DoubleStream;
           import java.util.stream.IntStream;
           import java.util.stream.LongStream;
           import jdk.internal.util.random.RandomSupport;
          -import jdk.internal.util.random.RandomSupport.AbstractSpliteratorGenerator;
          -import jdk.internal.util.random.RandomSupport.RandomIntsSpliterator;
          -import jdk.internal.util.random.RandomSupport.RandomLongsSpliterator;
          -import jdk.internal.util.random.RandomSupport.RandomDoublesSpliterator;
          -import jdk.internal.util.random.RandomSupport.RandomGeneratorProperties;
          +import jdk.internal.util.random.RandomSupport.*;
           import jdk.internal.misc.Unsafe;
           import jdk.internal.misc.VM;
      
          @@ -396,48 +392,6 @@ public class ThreadLocalRandom extends Random {
               /** The common ThreadLocalRandom */
               private static final ThreadLocalRandom instance = new ThreadLocalRandom();
      
          -    private static final class ThreadLocalRandomProxy extends Random {
          -        @java.io.Serial
          -        static final long serialVersionUID = 0L;
          -
          -
          -        static final AbstractSpliteratorGenerator proxy = new ThreadLocalRandomProxy();
          -
          -
          -        public int nextInt() {
          -            return ThreadLocalRandom.current().nextInt();
          -        }
          -
          -        public long nextLong() {
          -            return ThreadLocalRandom.current().nextLong();
          -        }
          -    }
          -
          -    // Methods required by class AbstractSpliteratorGenerator
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
          -        return new RandomIntsSpliterator(ThreadLocalRandomProxy.proxy, index, fence, origin, bound);
          -    }
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
          -        return new RandomLongsSpliterator(ThreadLocalRandomProxy.proxy, index, fence, origin, bound);
          -    }
          -
          -    /**
          -     * @hidden
          -     */
          -    @Override
          -    public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
          -        return new RandomDoublesSpliterator(ThreadLocalRandomProxy.proxy, index, fence, origin, bound);
          -    }
          -
               /**
                * The next seed for default constructors.
                */
          @@ -457,6 +411,19 @@ public class ThreadLocalRandom extends Random {
                   }
               }
      
          +    @SuppressWarnings("serial")
          +    private static final class ThreadLocalRandomProxy extends Random {
          +        static final Random PROXY = new ThreadLocalRandomProxy();
          +
          +        public int nextInt() {
          +            return ThreadLocalRandom.current().nextInt();
          +        }
          +
          +        public long nextLong() {
          +            return ThreadLocalRandom.current().nextLong();
          +        }
          +    }
          +
               /**
                * {@inheritDoc}
                */
          @@ -579,7 +546,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public IntStream ints(long streamSize) {
          -        return super.ints(streamSize);
          +        return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY, streamSize);
               }
      
               /**
          @@ -590,7 +557,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public IntStream ints() {
          -        return super.ints();
          +        return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY);
               }
      
               /**
          @@ -600,7 +567,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
          -        return super.ints(streamSize, randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY, streamSize, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -612,7 +579,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
          -        return super.ints(randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.ints(ThreadLocalRandomProxy.PROXY, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -622,7 +589,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public LongStream longs(long streamSize) {
          -        return super.longs(streamSize);
          +        return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY, streamSize);
               }
      
               /**
          @@ -633,7 +600,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public LongStream longs() {
          -        return super.longs();
          +        return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY);
               }
      
               /**
          @@ -643,7 +610,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public LongStream longs(long streamSize, long randomNumberOrigin, long randomNumberBound) {
          -        return super.longs(streamSize, randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY, streamSize, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -655,7 +622,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
          -        return super.longs(randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.longs(ThreadLocalRandomProxy.PROXY, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -665,7 +632,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public DoubleStream doubles(long streamSize) {
          -        return super.doubles(streamSize);
          +        return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY, streamSize);
               }
      
               /**
          @@ -676,7 +643,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public DoubleStream doubles() {
          -        return super.doubles();
          +        return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY);
               }
      
               /**
          @@ -686,7 +653,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) {
          -        return super.doubles(streamSize, randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY, streamSize, randomNumberOrigin, randomNumberBound);
               }
      
               /**
          @@ -698,7 +665,7 @@ public class ThreadLocalRandom extends Random {
                */
               @Override
               public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
          -        return super.doubles(randomNumberOrigin, randomNumberBound);
          +        return AbstractSpliteratorGenerator.doubles(ThreadLocalRandomProxy.PROXY, randomNumberOrigin, randomNumberBound);
               }
      
           }
          diff --git a/src/java.base/share/classes/jdk/internal/util/random/RandomSupport.java b/src/java.base/share/classes/jdk/internal/util/random/RandomSupport.java
          index 1cf59d753df..244d28d17f1 100644
          --- a/src/java.base/share/classes/jdk/internal/util/random/RandomSupport.java
          +++ b/src/java.base/share/classes/jdk/internal/util/random/RandomSupport.java
          @@ -28,6 +28,7 @@ package jdk.internal.util.random;
           import java.lang.annotation.*;
           import java.math.BigInteger;
           import java.util.Objects;
          +import java.util.Random;
           import java.util.function.Consumer;
           import java.util.function.DoubleConsumer;
           import java.util.function.IntConsumer;
          @@ -50,8 +51,6 @@ import java.util.stream.StreamSupport;
            * internal package it is not intended for general use.
            *
            * @since 17
          - * @hidden
          - *
            */
           public class RandomSupport {
               /**
          @@ -952,7 +951,7 @@ public class RandomSupport {
                */
               public static class RandomIntsSpliterator extends RandomSupport.RandomSpliterator
                       implements Spliterator.OfInt {
          -        final AbstractSpliteratorGenerator generatingGenerator;
          +        final RandomGenerator generatingGenerator;
                   final int origin;
                   final int bound;
      
          @@ -965,7 +964,7 @@ public class RandomSupport {
                    * @param origin the (inclusive) lower bound on the pseudorandom values to be generated
                    * @param bound the (exclusive) upper bound on the pseudorandom values to be generated
                    */
          -        public RandomIntsSpliterator(AbstractSpliteratorGenerator generatingGenerator,
          +        public RandomIntsSpliterator(RandomGenerator generatingGenerator,
                                                long index, long fence, int origin, int bound) {
                       super(index, fence);
                       this.generatingGenerator = generatingGenerator;
          @@ -1010,7 +1009,7 @@ public class RandomSupport {
                */
               public static class RandomLongsSpliterator extends RandomSupport.RandomSpliterator
                       implements Spliterator.OfLong {
          -        final AbstractSpliteratorGenerator generatingGenerator;
          +        final RandomGenerator generatingGenerator;
                   final long origin;
                   final long bound;
      
          @@ -1023,7 +1022,7 @@ public class RandomSupport {
                    * @param origin the (inclusive) lower bound on the pseudorandom values to be generated
                    * @param bound the (exclusive) upper bound on the pseudorandom values to be generated
                    */
          -        public RandomLongsSpliterator(AbstractSpliteratorGenerator generatingGenerator,
          +        public RandomLongsSpliterator(RandomGenerator generatingGenerator,
                                                 long index, long fence, long origin, long bound) {
                       super(index, fence);
                       this.generatingGenerator = generatingGenerator;
          @@ -1068,7 +1067,7 @@ public class RandomSupport {
                */
               public static class RandomDoublesSpliterator extends RandomSupport.RandomSpliterator
                       implements Spliterator.OfDouble {
          -        final AbstractSpliteratorGenerator generatingGenerator;
          +        final RandomGenerator generatingGenerator;
                   final double origin;
                   final double bound;
      
          @@ -1081,7 +1080,7 @@ public class RandomSupport {
                    * @param origin the (inclusive) lower bound on the pseudorandom values to be generated
                    * @param bound the (exclusive) upper bound on the pseudorandom values to be generated
                    */
          -        public RandomDoublesSpliterator(AbstractSpliteratorGenerator generatingGenerator,
          +        public RandomDoublesSpliterator(RandomGenerator generatingGenerator,
                                                   long index, long fence, double origin, double bound) {
                       super(index, fence);
                       this.generatingGenerator = generatingGenerator;
          @@ -1405,17 +1404,12 @@ public class RandomSupport {
                * only to extend this class and provide implementations for the methods
                * {@link RandomGenerator#nextInt() nextInt}(),
                * {@link RandomGenerator#nextLong() nextLong}(),
          -     * {@link AbstractSpliteratorGenerator#makeIntsSpliterator(long, long, int, int) makeIntsSpliterator}(index, fence, origin, bound),
          -     * {@link AbstractSpliteratorGenerator#makeLongsSpliterator(long, long, long, long) makeLongsSpliterator}(index, fence, origin, bound),
          -     * and
          -     * {@link AbstractSpliteratorGenerator#makeDoublesSpliterator(long, long, double, double) makeDoublesSpliterator}(index, fence, origin, bound).
                *
                * <p> This class is not public; it provides shared code to the public
                * classes {@link AbstractSplittableGenerator}, and
                * {@link AbstractArbitrarilyJumpableGenerator}.
                *
                * @since 17
          -     * @hidden
                */
               public abstract static class AbstractSpliteratorGenerator implements RandomGenerator {
                   /*
          @@ -1425,75 +1419,18 @@ public class RandomSupport {
                    * satisfy the interface RandomGenerator.  An implementation of this
                    * interface need only extend this class and provide implementations
                    * of six methods: nextInt, nextLong, and nextDouble (the versions
          -         * that take no arguments) and makeIntsSpliterator,
          -         * makeLongsSpliterator, and makeDoublesSpliterator.
          +         * that take no arguments).
                    *
                    * File organization: First the non-public abstract methods needed
                    * to create spliterators, then the main public methods.
                    */
      
                   /**
          -         * Explicit constructor.
          +         * No instances.
                    */
          -        protected AbstractSpliteratorGenerator() {
          +        private AbstractSpliteratorGenerator() {
                   }
      
          -        /**
          -         * Create an instance of {@link Spliterator.OfInt} that for each
          -         * traversal position between the specified index (inclusive) and the
          -         * specified fence (exclusive) generates a pseudorandomly chosen
          -         * {@code int} value between the specified origin (inclusive) and the
          -         * specified bound (exclusive).
          -         *
          -         * @param index the (inclusive) lower bound on traversal positions
          -         * @param fence the (exclusive) upper bound on traversal positions
          -         * @param origin the (inclusive) lower bound on the pseudorandom values to be generated
          -         * @param bound the (exclusive) upper bound on the pseudorandom values to be generated
          -         *
          -         * @return an instance of {@link Spliterator.OfInt}
          -         *
          -         * @hidden
          -         */
          -        public abstract Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound);
          -
          -        /**
          -         * Create an instance of {@link Spliterator.OfLong} that for each
          -         * traversal position between the specified index (inclusive) and the
          -         * specified fence (exclusive) generates a pseudorandomly chosen
          -         * {@code long} value between the specified origin (inclusive) and the
          -         * specified bound (exclusive).
          -         *
          -         * @param index the (inclusive) lower bound on traversal positions
          -         * @param fence the (exclusive) upper bound on traversal positions
          -         * @param origin the (inclusive) lower bound on the pseudorandom values to be generated
          -         * @param bound the (exclusive) upper bound on the pseudorandom values to be generated
          -         *
          -         * @return an instance of {@link Spliterator.OfLong}
          -         *
          -         * @hidden
          -         */
          -        public abstract Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound);
          -
          -        /**
          -         * Create an instance of {@link Spliterator.OfDouble} that for each
          -         * traversal position between the specified index (inclusive) and the
          -         * specified fence (exclusive) generates a pseudorandomly chosen
          -         * {@code double} value between the specified origin (inclusive) and the
          -         * specified bound (exclusive).
          -         *
          -         * @param index the (inclusive) lower bound on traversal positions
          -         * @param fence the (exclusive) upper bound on traversal positions
          -         * @param origin the (inclusive) lower bound on the pseudorandom values to be generated
          -         * @param bound the (exclusive) upper bound on the pseudorandom values to be generated
          -         *
          -         * @return an instance of {@link Spliterator.OfDouble}
          -         *
          -         * @hidden
          -         */
          -        public abstract Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound);
          -
          -        /* ---------------- public methods ---------------- */
          -
                   // stream methods, coded in a way intended to better isolate for
                   // maintenance purposes the small differences across forms.
      
          @@ -1509,79 +1446,116 @@ public class RandomSupport {
                       return StreamSupport.doubleStream(srng, false);
                   }
      
          -        @Override
          -        public IntStream ints(long streamSize) {
          +        /* ---------------- public static methods ---------------- */
          +
          +       public static IntStream ints(RandomGenerator gen, long streamSize) {
                       RandomSupport.checkStreamSize(streamSize);
          -            return intStream(makeIntsSpliterator(0L, streamSize, Integer.MAX_VALUE, 0));
          +            return intStream(new RandomIntsSpliterator(gen, 0L, streamSize, Integer.MAX_VALUE, 0));
                   }
      
          -        @Override
          -        public IntStream ints() {
          -            return intStream(makeIntsSpliterator(0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0));
          +        public static IntStream ints(RandomGenerator gen) {
          +            return intStream(new RandomIntsSpliterator(gen, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0));
                   }
      
          -        @Override
          -        public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
          +        public static IntStream ints(RandomGenerator gen, long streamSize, int randomNumberOrigin, int randomNumberBound) {
                       RandomSupport.checkStreamSize(streamSize);
                       RandomSupport.checkRange(randomNumberOrigin, randomNumberBound);
          -            return intStream(makeIntsSpliterator(0L, streamSize, randomNumberOrigin, randomNumberBound));
          +            return intStream(new RandomIntsSpliterator(gen, 0L, streamSize, randomNumberOrigin, randomNumberBound));
                   }
      
          -        @Override
          -        public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
          +        public static IntStream ints(RandomGenerator gen, int randomNumberOrigin, int randomNumberBound) {
                       RandomSupport.checkRange(randomNumberOrigin, randomNumberBound);
          -            return intStream(makeIntsSpliterator(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound));
          +            return intStream(new RandomIntsSpliterator(gen, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound));
                   }
      
          -        @Override
          -        public LongStream longs(long streamSize) {
          +        public static LongStream longs(RandomGenerator gen, long streamSize) {
                       RandomSupport.checkStreamSize(streamSize);
          -            return longStream(makeLongsSpliterator(0L, streamSize, Long.MAX_VALUE, 0L));
          +            return longStream(new RandomLongsSpliterator(gen, 0L, streamSize, Long.MAX_VALUE, 0L));
                   }
      
          -        @Override
          -        public LongStream longs() {
          -            return longStream(makeLongsSpliterator(0L, Long.MAX_VALUE, Long.MAX_VALUE, 0L));
          +        public static LongStream longs(RandomGenerator gen) {
          +            return longStream(new RandomLongsSpliterator(gen, 0L, Long.MAX_VALUE, Long.MAX_VALUE, 0L));
                   }
      
          -        @Override
          -        public LongStream longs(long streamSize, long randomNumberOrigin,
          -                                long randomNumberBound) {
          +        public static LongStream longs(RandomGenerator gen, long streamSize, long randomNumberOrigin, long randomNumberBound) {
                       RandomSupport.checkStreamSize(streamSize);
                       RandomSupport.checkRange(randomNumberOrigin, randomNumberBound);
          -            return longStream(makeLongsSpliterator(0L, streamSize, randomNumberOrigin, randomNumberBound));
          +            return longStream(new RandomLongsSpliterator(gen, 0L, streamSize, randomNumberOrigin, randomNumberBound));
                   }
      
          -        @Override
          -        public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
          +        public static LongStream longs(RandomGenerator gen, long randomNumberOrigin, long randomNumberBound) {
                       RandomSupport.checkRange(randomNumberOrigin, randomNumberBound);
          -            return StreamSupport.longStream
          -                    (makeLongsSpliterator(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
          -                            false);
          +            return longStream(new RandomLongsSpliterator(gen, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound));
                   }
      
          -        @Override
          -        public DoubleStream doubles(long streamSize) {
          +        public static DoubleStream doubles(RandomGenerator gen, long streamSize) {
                       RandomSupport.checkStreamSize(streamSize);
          -            return doubleStream(makeDoublesSpliterator(0L, streamSize, Double.MAX_VALUE, 0.0));
          +            return doubleStream(new RandomDoublesSpliterator(gen, 0L, streamSize, Double.MAX_VALUE, 0.0));
                   }
      
          -        @Override
          -        public DoubleStream doubles() {
          -            return doubleStream(makeDoublesSpliterator(0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0));
          +        public static DoubleStream doubles(RandomGenerator gen) {
          +            return doubleStream(new RandomDoublesSpliterator(gen, 0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0));
                   }
      
          -        @Override
          -        public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) {
          +        public static DoubleStream doubles(RandomGenerator gen, long streamSize, double randomNumberOrigin, double randomNumberBound) {
                       RandomSupport.checkStreamSize(streamSize);
                       RandomSupport.checkRange(randomNumberOrigin, randomNumberBound);
          -            return doubleStream(makeDoublesSpliterator(0L, streamSize, randomNumberOrigin, randomNumberBound));
          +            return doubleStream(new RandomDoublesSpliterator(gen, 0L, streamSize, randomNumberOrigin, randomNumberBound));
                   }
      
          -        @Override
          -        public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
          +        public static DoubleStream doubles(RandomGenerator gen, double randomNumberOrigin, double randomNumberBound) {
                       RandomSupport.checkRange(randomNumberOrigin, randomNumberBound);
          -            return doubleStream(makeDoublesSpliterator(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound));
          +            return doubleStream(new RandomDoublesSpliterator(gen, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound));
          +        }
          +
          +        /* ---------------- public instance methods ---------------- */
          +
          +        public IntStream ints(long streamSize) {
          +            return ints(this, streamSize);
          +        }
          +
          +        public IntStream ints() {
          +            return ints(this);
          +        }
          +
          +        public IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
          +            return ints(this, streamSize, randomNumberOrigin, randomNumberBound);
          +        }
          +
          +        public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
          +            return ints(this, randomNumberOrigin, randomNumberBound);
          +        }
          +
          +        public LongStream longs(long streamSize) {
          +            return longs(this, streamSize);
          +        }
          +
          +        public LongStream longs() {
          +            return longs(this);
          +        }
          +
          +        public LongStream longs(long streamSize, long randomNumberOrigin,long randomNumberBound) {
          +            return longs(this, streamSize, randomNumberOrigin, randomNumberBound);
          +        }
          +
          +        public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
          +            return longs(this, randomNumberOrigin, randomNumberBound);
          +        }
          +
          +        public DoubleStream doubles(long streamSize) {
          +            return doubles(this, streamSize);
          +        }
          +
          +        public DoubleStream doubles() {
          +            return doubles(this);
          +        }
          +
          +        public DoubleStream doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) {
          +            return doubles(this, streamSize, randomNumberOrigin, randomNumberBound);
          +        }
          +
          +        public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
          +            return doubles(this, randomNumberOrigin, randomNumberBound);
                   }
      
               }
          @@ -1636,7 +1610,6 @@ public class RandomSupport {
                * admits a more efficient implementation.
                *
                * @since 17
          -     * @hidden
                */
               public abstract static class AbstractArbitrarilyJumpableGenerator
                       extends AbstractSpliteratorGenerator implements RandomGenerator.ArbitrarilyJumpableGenerator {
          @@ -1661,20 +1634,6 @@ public class RandomSupport {
                   protected AbstractArbitrarilyJumpableGenerator() {
                   }
      
          -        // Methods required by class AbstractSpliteratorGenerator
          -
          -        public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
          -            return new RandomIntsSpliterator(this, index, fence, origin, bound);
          -        }
          -
          -        public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
          -            return new RandomLongsSpliterator(this, index, fence, origin, bound);
          -        }
          -
          -        public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
          -            return new RandomDoublesSpliterator(this, index, fence, origin, bound);
          -        }
          -
                   // Similar methods used by this class
      
                   Spliterator<RandomGenerator> makeJumpsSpliterator(long index, long fence, double distance) {
          @@ -2078,7 +2037,6 @@ public class RandomSupport {
                * admits a more efficient implementation.
                *
                * @since 17
          -     * @hidden
                */
               public abstract static class AbstractSplittableGenerator extends AbstractSpliteratorGenerator implements SplittableGenerator {
      
          @@ -2103,18 +2061,6 @@ public class RandomSupport {
                   protected AbstractSplittableGenerator() {
                   }
      
          -        public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
          -            return new RandomIntsSpliterator(this, index, fence, origin, bound);
          -        }
          -
          -        public Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound) {
          -            return new RandomLongsSpliterator(this, index, fence, origin, bound);
          -        }
          -
          -        public Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound) {
          -            return new RandomDoublesSpliterator(this, index, fence, origin, bound);
          -        }
          -
                   Spliterator<SplittableGenerator> makeSplitsSpliterator(long index, long fence, SplittableGenerator source) {
                       return new RandomSplitsSpliterator(source, index, fence, this);
                   }
          @@ -2382,7 +2328,6 @@ public class RandomSupport {
                * admits a more efficient implementation.
                *
                * @since 17
          -     * @hidden
                */
               public abstract static class AbstractSplittableWithBrineGenerator
                       extends AbstractSplittableGenerator {

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlaskey Jim Laskey
              Reporter:
              uschindler Uwe Schindler
              Reviewed By:
              Joe Darcy, Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: