ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/extra166y/CommonOps.java
(Generate patch)

Comparing jsr166/src/extra166y/CommonOps.java (file contents):
Revision 1.1 by dl, Tue Jan 6 14:30:57 2009 UTC vs.
Revision 1.8 by jsr166, Sun Jan 18 20:17:32 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   package extra166y;
8 +
9   import jsr166y.*;
10   import static extra166y.Ops.*;
11   import java.util.*;
# Line 17 | Line 18 | public class CommonOps {
18      private CommonOps() {} // disable construction
19  
20      /**
21 <     * Returns a Comparator for Comparable objects
21 >     * Returns a Comparator for Comparable objects.
22       */
23      public static <T extends Comparable<? super T>> Comparator<T>
24                               naturalComparator(Class<T> type) {
# Line 35 | Line 36 | public class CommonOps {
36          return new Reducer<T>() {
37              public T op(T a, T b) {
38                  return (a != null &&
39 <                        (b == null || a.compareTo(b) >= 0))? a : b;
39 >                        (b == null || a.compareTo(b) >= 0)) ? a : b;
40              }
41          };
42      }
# Line 49 | Line 50 | public class CommonOps {
50          return new Reducer<T>() {
51              public T op(T a, T b) {
52                  return (a != null &&
53 <                        (b == null || a.compareTo(b) <= 0))? a : b;
53 >                        (b == null || a.compareTo(b) <= 0)) ? a : b;
54              }
55          };
56      }
# Line 64 | Line 65 | public class CommonOps {
65          return new Reducer<T>() {
66              public T op(T a, T b) {
67                  return (a != null &&
68 <                        (b == null || comparator.compare(a, b) >= 0))? a : b;
68 >                        (b == null || comparator.compare(a, b) >= 0)) ? a : b;
69              }
70          };
71      }
# Line 79 | Line 80 | public class CommonOps {
80          return new Reducer<T>() {
81              public T op(T a, T b) {
82                  return (a != null &&
83 <                        (b == null || comparator.compare(a, b) <= 0))? a : b;
83 >                        (b == null || comparator.compare(a, b) <= 0)) ? a : b;
84              }
85          };
86      }
# Line 100 | Line 101 | public class CommonOps {
101  
102      /**
103       * Returns a reducer returning maximum of two values, or
104 <     * <tt>null</tt> if both arguments are null, and that casts
104 >     * {@code null} if both arguments are null, and that casts
105       * its arguments as Comparable on each comparison, throwing
106       * ClassCastException on failure.
107       */
# Line 112 | Line 113 | public class CommonOps {
113          public Object op(Object a, Object b) {
114              return (a != null &&
115                      (b == null ||
116 <                     ((Comparable)a).compareTo((Comparable)b) >= 0))? a : b;
116 >                     ((Comparable)a).compareTo((Comparable)b) >= 0)) ? a : b;
117          }
118      }
119  
120      /**
121       * Returns a reducer returning minimum of two values, or
122 <     * <tt>null</tt> if both arguments are null, and that casts
122 >     * {@code null} if both arguments are null, and that casts
123       * its arguments as Comparable on each comparison, throwing
124       * ClassCastException on failure.
125       */
# Line 130 | Line 131 | public class CommonOps {
131          public Object op(Object a, Object b) {
132              return (a != null &&
133                      (b == null ||
134 <                     ((Comparable)a).compareTo((Comparable)b) <= 0))? a : b;
134 >                     ((Comparable)a).compareTo((Comparable)b) <= 0)) ? a : b;
135          }
136      }
137  
138  
139      /**
140 <     * Returns a comparator for doubles relying on natural ordering
140 >     * Returns a comparator for doubles relying on natural ordering.
141       */
142      public static DoubleComparator naturalDoubleComparator() {
143          return NaturalDoubleComparator.comparator;
# Line 152 | Line 153 | public class CommonOps {
153  
154      /**
155       * Returns a reducer returning the maximum of two double elements,
156 <     * using natural comparator
156 >     * using natural comparator.
157       */
158      public static DoubleReducer naturalDoubleMaxReducer() {
159          return NaturalDoubleMaxReducer.max;
# Line 167 | Line 168 | public class CommonOps {
168  
169      /**
170       * Returns a reducer returning the minimum of two double elements,
171 <     * using natural comparator
171 >     * using natural comparator.
172       */
173      public static DoubleReducer naturalDoubleMinReducer() {
174          return NaturalDoubleMinReducer.min;
# Line 181 | Line 182 | public class CommonOps {
182  
183      /**
184       * Returns a reducer returning the maximum of two double elements,
185 <     * using the given comparator
185 >     * using the given comparator.
186       */
187      public static DoubleReducer doubleMaxReducer
188          (final DoubleComparator comparator) {
189          return new DoubleReducer() {
190                  public double op(double a, double b) {
191 <                    return (comparator.compare(a, b) >= 0)? a : b;
191 >                    return (comparator.compare(a, b) >= 0) ? a : b;
192                  }
193              };
194      }
195  
196      /**
197       * Returns a reducer returning the minimum of two double elements,
198 <     * using the given comparator
198 >     * using the given comparator.
199       */
200      public static DoubleReducer doubleMinReducer
201          (final DoubleComparator comparator) {
202          return new DoubleReducer() {
203                  public double op(double a, double b) {
204 <                    return (comparator.compare(a, b) <= 0)? a : b;
204 >                    return (comparator.compare(a, b) <= 0) ? a : b;
205                  }
206              };
207      }
208  
209      /**
210 <     * Returns a comparator for longs relying on natural ordering
210 >     * Returns a comparator for longs relying on natural ordering.
211       */
212      public static LongComparator naturalLongComparator() {
213          return NaturalLongComparator.comparator;
# Line 216 | Line 217 | public class CommonOps {
217          static final NaturalLongComparator comparator = new
218              NaturalLongComparator();
219          public int compare(long a, long b) {
220 <            return a < b? -1 : ((a > b)? 1 : 0);
220 >            return (a < b) ? -1 : ((a > b) ? 1 : 0);
221          }
222      }
223  
224      /**
225       * Returns a reducer returning the maximum of two long elements,
226 <     * using natural comparator
226 >     * using natural comparator.
227       */
228      public static LongReducer naturalLongMaxReducer() {
229          return NaturalLongMaxReducer.max;
# Line 232 | Line 233 | public class CommonOps {
233          implements LongReducer {
234          public static final NaturalLongMaxReducer max =
235              new NaturalLongMaxReducer();
236 <        public long op(long a, long b) { return a >= b? a : b; }
236 >        public long op(long a, long b) { return (a >= b) ? a : b; }
237      }
238  
239      /**
240       * A reducer returning the minimum of two long elements,
241 <     * using natural comparator
241 >     * using natural comparator.
242       */
243      public static LongReducer naturalLongMinReducer() {
244          return NaturalLongMinReducer.min;
# Line 246 | Line 247 | public class CommonOps {
247          implements LongReducer {
248          public static final NaturalLongMinReducer min =
249              new NaturalLongMinReducer();
250 <        public long op(long a, long b) { return a <= b? a : b; }
250 >        public long op(long a, long b) { return (a <= b) ? a : b; }
251      }
252  
253      /**
254       * Returns a reducer returning the maximum of two long elements,
255 <     * using the given comparator
255 >     * using the given comparator.
256       */
257      public static LongReducer longMaxReducer
258          (final LongComparator comparator) {
259          return new LongReducer() {
260                  public long op(long a, long b) {
261 <                    return (comparator.compare(a, b) >= 0)? a : b;
261 >                    return (comparator.compare(a, b) >= 0) ? a : b;
262                  }
263              };
264      }
265  
266      /**
267       * Returns a reducer returning the minimum of two long elements,
268 <     * using the given comparator
268 >     * using the given comparator.
269       */
270      public static LongReducer longMinReducer
271          (final LongComparator comparator) {
272          return new LongReducer() {
273                  public long op(long a, long b) {
274 <                    return (comparator.compare(a, b) <= 0)? a : b;
274 >                    return (comparator.compare(a, b) <= 0) ? a : b;
275                  }
276              };
277      }
278  
279      /**
280       * Returns a composite mapper that applies a second mapper to the results
281 <     * of applying the first one
281 >     * of applying the first one.
282       */
283      public static <T,U,V> Op<T,V> compoundOp
284          (final Op<? super T, ? extends U> first,
# Line 289 | Line 290 | public class CommonOps {
290  
291      /**
292       * Returns a composite mapper that applies a second mapper to the results
293 <     * of applying the first one
293 >     * of applying the first one.
294       */
295      public static <T,V> Op<T,V> compoundOp
296          (final ObjectToDouble<? super T> first,
# Line 301 | Line 302 | public class CommonOps {
302  
303      /**
304       * Returns a composite mapper that applies a second mapper to the results
305 <     * of applying the first one
305 >     * of applying the first one.
306       */
307      public static <T,V> Op<T,V> compoundOp
308          (final ObjectToLong<? super T> first,
# Line 313 | Line 314 | public class CommonOps {
314  
315      /**
316       * Returns a composite mapper that applies a second mapper to the results
317 <     * of applying the first one
317 >     * of applying the first one.
318       */
319      public static <T,V> DoubleToObject<V> compoundOp
320          (final DoubleToObject<? extends T> first,
# Line 325 | Line 326 | public class CommonOps {
326  
327      /**
328       * Returns a composite mapper that applies a second mapper to the results
329 <     * of applying the first one
329 >     * of applying the first one.
330       */
331      public static <T,V> LongToObject<V> compoundOp
332          (final LongToObject<? extends T> first,
# Line 337 | Line 338 | public class CommonOps {
338  
339      /**
340       * Returns a composite mapper that applies a second mapper to the results
341 <     * of applying the first one
341 >     * of applying the first one.
342       */
343      public static <T,U> ObjectToDouble<T> compoundOp
344          (final Op<? super T, ? extends U> first,
# Line 349 | Line 350 | public class CommonOps {
350  
351      /**
352       * Returns a composite mapper that applies a second mapper to the results
353 <     * of applying the first one
353 >     * of applying the first one.
354       */
355      public static <T,U> ObjectToLong<T> compoundOp
356          (final Op<? super T, ? extends U> first,
# Line 361 | Line 362 | public class CommonOps {
362  
363      /**
364       * Returns a composite mapper that applies a second mapper to the results
365 <     * of applying the first one
365 >     * of applying the first one.
366       */
367      public static <T> ObjectToDouble<T> compoundOp
368          (final ObjectToDouble<? super T> first,
# Line 373 | Line 374 | public class CommonOps {
374  
375      /**
376       * Returns a composite mapper that applies a second mapper to the results
377 <     * of applying the first one
377 >     * of applying the first one.
378       */
379      public static <T> ObjectToLong<T> compoundOp
380          (final ObjectToDouble<? super T> first,
# Line 385 | Line 386 | public class CommonOps {
386  
387      /**
388       * Returns a composite mapper that applies a second mapper to the results
389 <     * of applying the first one
389 >     * of applying the first one.
390       */
391      public static <T> ObjectToLong<T> compoundOp
392          (final ObjectToLong<? super T> first,
# Line 397 | Line 398 | public class CommonOps {
398  
399      /**
400       * Returns a composite mapper that applies a second mapper to the results
401 <     * of applying the first one
401 >     * of applying the first one.
402       */
403      public static <T> ObjectToDouble<T> compoundOp
404          (final ObjectToLong<? super T> first,
# Line 409 | Line 410 | public class CommonOps {
410  
411      /**
412       * Returns a composite mapper that applies a second mapper to the results
413 <     * of applying the first one
413 >     * of applying the first one.
414       */
415      public static DoubleOp compoundOp
416          (final DoubleOp first,
# Line 421 | Line 422 | public class CommonOps {
422  
423      /**
424       * Returns a composite mapper that applies a second mapper to the results
425 <     * of applying the first one
425 >     * of applying the first one.
426       */
427      public static DoubleToLong compoundOp
428          (final DoubleOp first,
# Line 433 | Line 434 | public class CommonOps {
434  
435      /**
436       * Returns a composite mapper that applies a second mapper to the results
437 <     * of applying the first one
437 >     * of applying the first one.
438       */
439      public static DoubleToLong compoundOp
440          (final DoubleToLong first,
# Line 445 | Line 446 | public class CommonOps {
446  
447      /**
448       * Returns a composite mapper that applies a second mapper to the results
449 <     * of applying the first one
449 >     * of applying the first one.
450       */
451      public static <T> DoubleToObject<T> compoundOp
452          (final DoubleToLong first,
# Line 457 | Line 458 | public class CommonOps {
458  
459      /**
460       * Returns a composite mapper that applies a second mapper to the results
461 <     * of applying the first one
461 >     * of applying the first one.
462       */
463      public static <T> LongToObject<T> compoundOp
464          (final LongToDouble first,
# Line 469 | Line 470 | public class CommonOps {
470  
471      /**
472       * Returns a composite mapper that applies a second mapper to the results
473 <     * of applying the first one
473 >     * of applying the first one.
474       */
475      public static LongToDouble compoundOp
476          (final LongOp first,
# Line 481 | Line 482 | public class CommonOps {
482  
483      /**
484       * Returns a composite mapper that applies a second mapper to the results
485 <     * of applying the first one
485 >     * of applying the first one.
486       */
487      public static LongToDouble compoundOp
488          (final LongToDouble first,
# Line 493 | Line 494 | public class CommonOps {
494  
495      /**
496       * Returns a composite mapper that applies a second mapper to the results
497 <     * of applying the first one
497 >     * of applying the first one.
498       */
499      public static <T> DoubleToObject<T> compoundOp
500          (final DoubleOp first,
# Line 505 | Line 506 | public class CommonOps {
506  
507      /**
508       * Returns a composite mapper that applies a second mapper to the results
509 <     * of applying the first one
509 >     * of applying the first one.
510       */
511      public static <T> LongToObject<T> compoundOp
512          (final LongOp first,
# Line 517 | Line 518 | public class CommonOps {
518  
519      /**
520       * Returns a composite mapper that applies a second mapper to the results
521 <     * of applying the first one
521 >     * of applying the first one.
522       */
523      public static <T> DoubleOp compoundOp
524          (final DoubleToObject<? extends T> first,
525 <         final ObjectToDouble<? super T>  second) {
525 >         final ObjectToDouble<? super T> second) {
526          return new DoubleOp() {
527                  public final double op(double t) { return second.op(first.op(t)); }
528              };
# Line 529 | Line 530 | public class CommonOps {
530  
531      /**
532       * Returns a composite mapper that applies a second mapper to the results
533 <     * of applying the first one
533 >     * of applying the first one.
534       */
535      public static <T> LongToDouble compoundOp
536          (final LongToObject<? extends T> first,
537 <         final ObjectToDouble<? super T>  second) {
537 >         final ObjectToDouble<? super T> second) {
538          return new LongToDouble() {
539                  public final double op(long t) { return second.op(first.op(t)); }
540              };
# Line 541 | Line 542 | public class CommonOps {
542  
543      /**
544       * Returns a composite mapper that applies a second mapper to the results
545 <     * of applying the first one
545 >     * of applying the first one.
546       */
547      public static <T> DoubleToLong compoundOp
548          (final DoubleToObject<? extends T> first,
549 <         final ObjectToLong<? super T>  second) {
549 >         final ObjectToLong<? super T> second) {
550          return new DoubleToLong() {
551                  public final long op(double t) { return second.op(first.op(t)); }
552              };
# Line 553 | Line 554 | public class CommonOps {
554  
555      /**
556       * Returns a composite mapper that applies a second mapper to the results
557 <     * of applying the first one
557 >     * of applying the first one.
558       */
559      public static <T> LongOp compoundOp
560          (final LongToObject<? extends T> first,
561 <         final ObjectToLong<? super T>  second) {
561 >         final ObjectToLong<? super T> second) {
562          return new LongOp() {
563                  public final long op(long t) { return second.op(first.op(t)); }
564              };
# Line 565 | Line 566 | public class CommonOps {
566  
567      /**
568       * Returns a composite mapper that applies a second mapper to the results
569 <     * of applying the first one
569 >     * of applying the first one.
570       */
571      public static LongOp compoundOp
572          (final LongOp first,
# Line 577 | Line 578 | public class CommonOps {
578  
579      /**
580       * Returns a composite mapper that applies a second mapper to the results
581 <     * of applying the first one
581 >     * of applying the first one.
582       */
583      public static DoubleOp compoundOp
584          (final DoubleToLong first,
# Line 589 | Line 590 | public class CommonOps {
590  
591      /**
592       * Returns a composite mapper that applies a second mapper to the results
593 <     * of applying the first one
593 >     * of applying the first one.
594       */
595      public static LongOp compoundOp
596          (final LongToDouble first,
# Line 600 | Line 601 | public class CommonOps {
601      }
602  
603      /**
604 <     * Returns a predicate evaluating to the negation of its contained predicate
604 >     * Returns a predicate evaluating to the negation of its contained predicate.
605       */
606      public static <T> Predicate<T> notPredicate
607          (final Predicate<T> pred) {
# Line 610 | Line 611 | public class CommonOps {
611      }
612  
613      /**
614 <     * Returns a predicate evaluating to the negation of its contained predicate
614 >     * Returns a predicate evaluating to the negation of its contained predicate.
615       */
616      public static DoublePredicate notPredicate
617          (final DoublePredicate pred) {
# Line 620 | Line 621 | public class CommonOps {
621      }
622  
623      /**
624 <     * Returns a predicate evaluating to the negation of its contained predicate
624 >     * Returns a predicate evaluating to the negation of its contained predicate.
625       */
626      public static LongPredicate notPredicate
627          (final LongPredicate pred) {
# Line 630 | Line 631 | public class CommonOps {
631      }
632  
633      /**
634 <     * Returns a predicate evaluating to the conjunction of its contained predicates
634 >     * Returns a predicate evaluating to the conjunction of its contained predicates.
635       */
636      public static <S, T extends S> Predicate<T> andPredicate
637                                  (final Predicate<S> first,
# Line 643 | Line 644 | public class CommonOps {
644      }
645  
646      /**
647 <     * Returns a predicate evaluating to the disjunction of its contained predicates
647 >     * Returns a predicate evaluating to the disjunction of its contained predicates.
648       */
649      public static <S, T extends S> Predicate<T> orPredicate
650                                  (final Predicate<S> first,
# Line 656 | Line 657 | public class CommonOps {
657      }
658  
659      /**
660 <     * Returns a predicate evaluating to the conjunction of its contained predicates
660 >     * Returns a predicate evaluating to the conjunction of its contained predicates.
661       */
662      public static DoublePredicate andPredicate
663          (final DoublePredicate first,
# Line 669 | Line 670 | public class CommonOps {
670      }
671  
672      /**
673 <     * Returns a predicate evaluating to the disjunction of its contained predicates
673 >     * Returns a predicate evaluating to the disjunction of its contained predicates.
674       */
675      public static DoublePredicate orPredicate
676          (final DoublePredicate first,
# Line 683 | Line 684 | public class CommonOps {
684  
685  
686      /**
687 <     * Returns a predicate evaluating to the conjunction of its contained predicates
687 >     * Returns a predicate evaluating to the conjunction of its contained predicates.
688       */
689      public static LongPredicate andPredicate
690          (final LongPredicate first,
# Line 696 | Line 697 | public class CommonOps {
697      }
698  
699      /**
700 <     * Returns a predicate evaluating to the disjunction of its contained predicates
700 >     * Returns a predicate evaluating to the disjunction of its contained predicates.
701       */
702      public static LongPredicate orPredicate
703          (final LongPredicate first,
# Line 709 | Line 710 | public class CommonOps {
710      }
711  
712      /**
713 <     * Returns a predicate evaluating to true if its argument is non-null
713 >     * Returns a predicate evaluating to true if its argument is non-null.
714       */
715 <    public static  Predicate<Object> isNonNullPredicate() {
715 >    public static Predicate<Object> isNonNullPredicate() {
716          return IsNonNullPredicate.predicate;
717      }
718      static final class IsNonNullPredicate implements Predicate<Object> {
# Line 723 | Line 724 | public class CommonOps {
724      }
725  
726      /**
727 <     * Returns a predicate evaluating to true if its argument is null
727 >     * Returns a predicate evaluating to true if its argument is null.
728       */
729 <    public static  Predicate<Object> isNullPredicate() {
729 >    public static Predicate<Object> isNullPredicate() {
730          return IsNullPredicate.predicate;
731      }
732      static final class IsNullPredicate implements Predicate<Object> {
# Line 761 | Line 762 | public class CommonOps {
762      }
763  
764      /**
765 <     * Returns a reducer that adds two double elements
765 >     * Returns a reducer that adds two double elements.
766       */
767      public static DoubleReducer doubleAdder() { return DoubleAdder.adder; }
768      static final class DoubleAdder implements DoubleReducer {
# Line 770 | Line 771 | public class CommonOps {
771      }
772  
773      /**
774 <     * Returns a reducer that adds two long elements
774 >     * Returns a reducer that adds two long elements.
775       */
776      public static LongReducer longAdder() { return LongAdder.adder; }
777      static final class LongAdder implements LongReducer {
# Line 779 | Line 780 | public class CommonOps {
780      }
781  
782      /**
783 <     * Returns a reducer that adds two int elements
783 >     * Returns a reducer that adds two int elements.
784       */
785      public static IntReducer intAdder() { return IntAdder.adder; }
786      static final class IntAdder implements IntReducer {
# Line 790 | Line 791 | public class CommonOps {
791      /**
792       * Returns a generator producing uniform random values between
793       * zero and one, with the same properties as {@link
794 <     * java.util.Random#nextDouble} but operating independently across
794 <     * ForkJoinWorkerThreads and usable only within forkjoin
795 <     * computations.
794 >     * java.util.Random#nextDouble}.
795       */
796      public static DoubleGenerator doubleRandom() {
797          return DoubleRandomGenerator.generator;
# Line 801 | Line 800 | public class CommonOps {
800          static final DoubleRandomGenerator generator =
801              new DoubleRandomGenerator();
802          public double op() {
803 <            return ForkJoinWorkerThread.nextRandomDouble();
803 >            return ThreadLocalRandom.current().nextDouble();
804          }
805      }
806  
807      /**
808       * Returns a generator producing uniform random values between
809       * zero and the given bound, with the same properties as {@link
810 <     * java.util.Random#nextDouble} but operating independently across
812 <     * ForkJoinWorkerThreads and usable only within forkjoin
813 <     * computations.
810 >     * java.util.Random#nextDouble}.
811       * @param bound the upper bound (exclusive) of opd values
812       */
813      public static DoubleGenerator doubleRandom(double bound) {
# Line 820 | Line 817 | public class CommonOps {
817          final double bound;
818          DoubleBoundedRandomGenerator(double bound) { this.bound = bound; }
819          public double op() {
820 <            return ForkJoinWorkerThread.nextRandomDouble() * bound;
820 >            return ThreadLocalRandom.current().nextDouble() * bound;
821          }
822      }
823  
824      /**
825       * Returns a generator producing uniform random values between the
826 <     * given least value (inclusive) and bound (exclusive), operating
830 <     * independently across ForkJoinWorkerThreads and usable only
831 <     * within forkjoin computations.
826 >     * given least value (inclusive) and bound (exclusive).
827       * @param least the least value returned
828       * @param bound the upper bound (exclusive) of opd values
829       */
# Line 842 | Line 837 | public class CommonOps {
837              this.least = least; this.range = bound - least;
838          }
839          public double op() {
840 <            return ForkJoinWorkerThread.nextRandomDouble() * range + least;
840 >            return ThreadLocalRandom.current().nextDouble() * range + least;
841          }
842      }
843  
844      /**
845       * Returns a generator producing uniform random values with the
846 <     * same properties as {@link java.util.Random#nextLong} but
852 <     * operating independently across ForkJoinWorkerThreads and usable
853 <     * only within forkjoin computations.
846 >     * same properties as {@link java.util.Random#nextLong}.
847       */
848      public static LongGenerator longRandom() {
849          return LongRandomGenerator.generator;
# Line 859 | Line 852 | public class CommonOps {
852          static final LongRandomGenerator generator =
853              new LongRandomGenerator();
854          public long op() {
855 <            return ForkJoinWorkerThread.nextRandomLong();
855 >            return ThreadLocalRandom.current().nextLong();
856          }
857      }
858  
859      /**
860       * Returns a generator producing uniform random values with the
861 <     * same properties as {@link java.util.Random#nextInt(int)} but
869 <     * operating independently across ForkJoinWorkerThreads and usable
870 <     * only within forkjoin computations.
861 >     * same properties as {@link java.util.Random#nextInt(int)}.
862       * @param bound the upper bound (exclusive) of opd values
863       */
864      public static LongGenerator longRandom(long bound) {
# Line 879 | Line 870 | public class CommonOps {
870          final long bound;
871          LongBoundedRandomGenerator(long bound) { this.bound = bound; }
872          public long op() {
873 <            return ForkJoinWorkerThread.nextRandomLong(bound);
873 >            return ThreadLocalRandom.current().nextLong(bound);
874          }
875      }
876  
877      /**
878       * Returns a generator producing uniform random values between the
879 <     * given least value (inclusive) and bound (exclusive), operating
889 <     * independently across ForkJoinWorkerThreads and usable only
890 <     * within forkjoin computations.
879 >     * given least value (inclusive) and bound (exclusive).
880       * @param least the least value returned
881       * @param bound the upper bound (exclusive) of opd values
882       */
# Line 903 | Line 892 | public class CommonOps {
892              this.least = least; this.range = bound - least;
893          }
894          public long op() {
895 <            return ForkJoinWorkerThread.nextRandomLong(range) + least;
895 >            return ThreadLocalRandom.current().nextLong(range) + least;
896          }
897      }
898  
899      /**
900       * Returns a generator producing uniform random values with the
901 <     * same properties as {@link java.util.Random#nextInt} but
913 <     * operating independently across ForkJoinWorkerThreads and usable
914 <     * only within forkjoin computations.
901 >     * same properties as {@link java.util.Random#nextInt}.
902       */
903      public static IntGenerator intRandom() {
904          return IntRandomGenerator.generator;
# Line 920 | Line 907 | public class CommonOps {
907          static final IntRandomGenerator generator =
908              new IntRandomGenerator();
909          public int op() {
910 <            return ForkJoinWorkerThread.nextRandomInt();
910 >            return ThreadLocalRandom.current().nextInt();
911          }
912      }
913  
914      /**
915       * Returns a generator producing uniform random values with the
916 <     * same properties as {@link java.util.Random#nextInt(int)} but
930 <     * operating independently across ForkJoinWorkerThreads and usable
931 <     * only within forkjoin computations.
916 >     * same properties as {@link java.util.Random#nextInt(int)}.
917       * @param bound the upper bound (exclusive) of opd values
918       */
919      public static IntGenerator intRandom(int bound) {
# Line 940 | Line 925 | public class CommonOps {
925          final int bound;
926          IntBoundedRandomGenerator(int bound) { this.bound = bound; }
927          public int op() {
928 <            return ForkJoinWorkerThread.nextRandomInt(bound);
928 >            return ThreadLocalRandom.current().nextInt(bound);
929          }
930      }
931  
932      /**
933       * Returns a generator producing uniform random values between the
934 <     * given least value (inclusive) and bound (exclusive), operating
950 <     * independently across ForkJoinWorkerThreads and usable only
951 <     * within forkjoin computations.
934 >     * given least value (inclusive) and bound (exclusive).
935       * @param least the least value returned
936       * @param bound the upper bound (exclusive) of opd values
937       */
# Line 964 | Line 947 | public class CommonOps {
947              this.least = least; this.range = bound - least;
948          }
949          public int op() {
950 <            return ForkJoinWorkerThread.nextRandomInt(range) + least;
950 >            return ThreadLocalRandom.current().nextInt(range) + least;
951          }
952      }
953  
954      /**
955       * Returns a predicate evaluating to true if the
956 <     * first argument <tt>equals</tt> the second
956 >     * first argument {@code equals} the second.
957       */
958      public static BinaryPredicate<Object, Object> equalityPredicate() {
959          return EqualityPredicate.predicate;
# Line 985 | Line 968 | public class CommonOps {
968  
969      /**
970       * Returns a predicate evaluating to true if the
971 <     * first argument <tt>==</tt> the second
971 >     * first argument {@code ==} the second.
972       */
973      public static BinaryPredicate<Object, Object> identityPredicate() {
974          return IdentityPredicate.predicate;
# Line 1000 | Line 983 | public class CommonOps {
983  
984      /**
985       * Returns a predicate evaluating to true if the
986 <     * first argument <tt>==</tt> the second
986 >     * first argument {@code ==} the second.
987       */
988      public static BinaryIntPredicate intEqualityPredicate() {
989          return IntEqualityPredicate.predicate;
# Line 1015 | Line 998 | public class CommonOps {
998  
999      /**
1000       * Returns a predicate evaluating to true if the
1001 <     * first argument <tt>==</tt> the second
1001 >     * first argument {@code ==} the second.
1002       */
1003      public static BinaryLongPredicate longEqualityPredicate() {
1004          return LongEqualityPredicate.predicate;
# Line 1030 | Line 1013 | public class CommonOps {
1013  
1014      /**
1015       * Returns a predicate evaluating to true if the
1016 <     * first argument <tt>==</tt> the second
1016 >     * first argument {@code ==} the second.
1017       */
1018      public static BinaryDoublePredicate doubleEqualityPredicate() {
1019          return DoubleEqualityPredicate.predicate;
# Line 1046 | Line 1029 | public class CommonOps {
1029  
1030      /**
1031       * Returns a predicate evaluating to true if the
1032 <     * first argument <tt>!equals</tt> the second
1032 >     * first argument {@code !equals} the second.
1033       */
1034      public static BinaryPredicate<Object, Object> inequalityPredicate() {
1035          return InequalityPredicate.predicate;
# Line 1061 | Line 1044 | public class CommonOps {
1044  
1045      /**
1046       * Returns a predicate evaluating to true if the
1047 <     * first argument <tt>!=</tt> the second
1047 >     * first argument {@code !=} the second.
1048       */
1049      public static BinaryPredicate<Object, Object> nonidentityPredicate() {
1050          return NonidentityPredicate.predicate;
# Line 1076 | Line 1059 | public class CommonOps {
1059  
1060      /**
1061       * Returns a predicate evaluating to true if the
1062 <     * first argument <tt>!=</tt> the second
1062 >     * first argument {@code !=} the second.
1063       */
1064      public static BinaryIntPredicate intInequalityPredicate() {
1065          return IntInequalityPredicate.predicate;
# Line 1091 | Line 1074 | public class CommonOps {
1074  
1075      /**
1076       * Returns a predicate evaluating to true if the
1077 <     * first argument <tt>==</tt> the second
1077 >     * first argument {@code ==} the second.
1078       */
1079      public static BinaryLongPredicate longInequalityPredicate() {
1080          return LongInequalityPredicate.predicate;
# Line 1106 | Line 1089 | public class CommonOps {
1089  
1090      /**
1091       * Returns a predicate evaluating to true if the
1092 <     * first argument <tt>!=</tt> the second
1092 >     * first argument {@code !=} the second.
1093       */
1094      public static BinaryDoublePredicate doubleInequalityPredicate() {
1095          return DoubleInequalityPredicate.predicate;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines