ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ThreadLocalRandom.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ThreadLocalRandom.java (file contents):
Revision 1.34 by jsr166, Wed Jan 7 02:40:31 2015 UTC vs.
Revision 1.35 by jsr166, Sat Sep 19 21:07:11 2015 UTC

# Line 220 | Line 220 | public class ThreadLocalRandom extends R
220      }
221  
222      // IllegalArgumentException messages
223 <    static final String BadBound = "bound must be positive";
224 <    static final String BadRange = "bound must be greater than origin";
225 <    static final String BadSize  = "size must be non-negative";
223 >    static final String BAD_BOUND = "bound must be positive";
224 >    static final String BAD_RANGE = "bound must be greater than origin";
225 >    static final String BAD_SIZE  = "size must be non-negative";
226  
227      /**
228       * The form of nextLong used by LongStream Spliterators.  If
# Line 320 | Line 320 | public class ThreadLocalRandom extends R
320       */
321      public int nextInt(int bound) {
322          if (bound <= 0)
323 <            throw new IllegalArgumentException(BadBound);
323 >            throw new IllegalArgumentException(BAD_BOUND);
324          int r = mix32(nextSeed());
325          int m = bound - 1;
326          if ((bound & m) == 0) // power of two
# Line 347 | Line 347 | public class ThreadLocalRandom extends R
347       */
348      public int nextInt(int origin, int bound) {
349          if (origin >= bound)
350 <            throw new IllegalArgumentException(BadRange);
350 >            throw new IllegalArgumentException(BAD_RANGE);
351          return internalNextInt(origin, bound);
352      }
353  
# Line 371 | Line 371 | public class ThreadLocalRandom extends R
371       */
372      public long nextLong(long bound) {
373          if (bound <= 0)
374 <            throw new IllegalArgumentException(BadBound);
374 >            throw new IllegalArgumentException(BAD_BOUND);
375          long r = mix64(nextSeed());
376          long m = bound - 1;
377          if ((bound & m) == 0L) // power of two
# Line 398 | Line 398 | public class ThreadLocalRandom extends R
398       */
399      public long nextLong(long origin, long bound) {
400          if (origin >= bound)
401 <            throw new IllegalArgumentException(BadRange);
401 >            throw new IllegalArgumentException(BAD_RANGE);
402          return internalNextLong(origin, bound);
403      }
404  
# Line 424 | Line 424 | public class ThreadLocalRandom extends R
424       */
425      public double nextDouble(double bound) {
426          if (!(bound > 0.0))
427 <            throw new IllegalArgumentException(BadBound);
427 >            throw new IllegalArgumentException(BAD_BOUND);
428          double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound;
429          return (result < bound) ? result : // correct for rounding
430              Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1);
# Line 443 | Line 443 | public class ThreadLocalRandom extends R
443       */
444      public double nextDouble(double origin, double bound) {
445          if (!(origin < bound))
446 <            throw new IllegalArgumentException(BadRange);
446 >            throw new IllegalArgumentException(BAD_RANGE);
447          return internalNextDouble(origin, bound);
448      }
449  
# Line 500 | Line 500 | public class ThreadLocalRandom extends R
500       */
501      public IntStream ints(long streamSize) {
502          if (streamSize < 0L)
503 <            throw new IllegalArgumentException(BadSize);
503 >            throw new IllegalArgumentException(BAD_SIZE);
504          return StreamSupport.intStream
505              (new RandomIntsSpliterator
506               (0L, streamSize, Integer.MAX_VALUE, 0),
# Line 542 | Line 542 | public class ThreadLocalRandom extends R
542      public IntStream ints(long streamSize, int randomNumberOrigin,
543                            int randomNumberBound) {
544          if (streamSize < 0L)
545 <            throw new IllegalArgumentException(BadSize);
545 >            throw new IllegalArgumentException(BAD_SIZE);
546          if (randomNumberOrigin >= randomNumberBound)
547 <            throw new IllegalArgumentException(BadRange);
547 >            throw new IllegalArgumentException(BAD_RANGE);
548          return StreamSupport.intStream
549              (new RandomIntsSpliterator
550               (0L, streamSize, randomNumberOrigin, randomNumberBound),
# Line 569 | Line 569 | public class ThreadLocalRandom extends R
569       */
570      public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
571          if (randomNumberOrigin >= randomNumberBound)
572 <            throw new IllegalArgumentException(BadRange);
572 >            throw new IllegalArgumentException(BAD_RANGE);
573          return StreamSupport.intStream
574              (new RandomIntsSpliterator
575               (0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
# Line 588 | Line 588 | public class ThreadLocalRandom extends R
588       */
589      public LongStream longs(long streamSize) {
590          if (streamSize < 0L)
591 <            throw new IllegalArgumentException(BadSize);
591 >            throw new IllegalArgumentException(BAD_SIZE);
592          return StreamSupport.longStream
593              (new RandomLongsSpliterator
594               (0L, streamSize, Long.MAX_VALUE, 0L),
# Line 630 | Line 630 | public class ThreadLocalRandom extends R
630      public LongStream longs(long streamSize, long randomNumberOrigin,
631                              long randomNumberBound) {
632          if (streamSize < 0L)
633 <            throw new IllegalArgumentException(BadSize);
633 >            throw new IllegalArgumentException(BAD_SIZE);
634          if (randomNumberOrigin >= randomNumberBound)
635 <            throw new IllegalArgumentException(BadRange);
635 >            throw new IllegalArgumentException(BAD_RANGE);
636          return StreamSupport.longStream
637              (new RandomLongsSpliterator
638               (0L, streamSize, randomNumberOrigin, randomNumberBound),
# Line 657 | Line 657 | public class ThreadLocalRandom extends R
657       */
658      public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
659          if (randomNumberOrigin >= randomNumberBound)
660 <            throw new IllegalArgumentException(BadRange);
660 >            throw new IllegalArgumentException(BAD_RANGE);
661          return StreamSupport.longStream
662              (new RandomLongsSpliterator
663               (0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
# Line 677 | Line 677 | public class ThreadLocalRandom extends R
677       */
678      public DoubleStream doubles(long streamSize) {
679          if (streamSize < 0L)
680 <            throw new IllegalArgumentException(BadSize);
680 >            throw new IllegalArgumentException(BAD_SIZE);
681          return StreamSupport.doubleStream
682              (new RandomDoublesSpliterator
683               (0L, streamSize, Double.MAX_VALUE, 0.0),
# Line 721 | Line 721 | public class ThreadLocalRandom extends R
721      public DoubleStream doubles(long streamSize, double randomNumberOrigin,
722                                  double randomNumberBound) {
723          if (streamSize < 0L)
724 <            throw new IllegalArgumentException(BadSize);
724 >            throw new IllegalArgumentException(BAD_SIZE);
725          if (!(randomNumberOrigin < randomNumberBound))
726 <            throw new IllegalArgumentException(BadRange);
726 >            throw new IllegalArgumentException(BAD_RANGE);
727          return StreamSupport.doubleStream
728              (new RandomDoublesSpliterator
729               (0L, streamSize, randomNumberOrigin, randomNumberBound),
# Line 748 | Line 748 | public class ThreadLocalRandom extends R
748       */
749      public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
750          if (!(randomNumberOrigin < randomNumberBound))
751 <            throw new IllegalArgumentException(BadRange);
751 >            throw new IllegalArgumentException(BAD_RANGE);
752          return StreamSupport.doubleStream
753              (new RandomDoublesSpliterator
754               (0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines