RandomGeneratorRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$).* as compiler argument.

Table of contents
  1. RandomGeneratorNextDouble
  2. RandomGeneratorNextInt
  3. RandomGeneratorNextLong

RandomGeneratorNextDouble

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextDouble") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextDouble).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Double> testRandomGeneratorNextDouble() {
   return ImmutableSet.of(
-      new Random().nextDouble() * 1,
-      2L * new SplittableRandom().nextDouble(),
-      new SecureRandom().nextDouble() * 3.0);
+      new Random().nextDouble(1),
+      new SplittableRandom().nextDouble(2L),
+      new SecureRandom().nextDouble(3.0));
 }

RandomGeneratorNextInt

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextInt") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextInt).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Integer> testRandomGeneratorNextInt() {
-  return ImmutableSet.of(
-      (int) new Random().nextDouble(1), (int) Math.round(new SplittableRandom().nextDouble(2)));
+  return ImmutableSet.of(new Random().nextInt(1), new SplittableRandom().nextInt(2));
 }

RandomGeneratorNextLong

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("RandomGeneratorNextLong") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!RandomGeneratorRules\$RandomGeneratorNextLong).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Long> testRandomGeneratorNextLong() {
   return ImmutableSet.of(
-      (long) new Random().nextDouble((double) 1L),
-      Math.round(new SplittableRandom().nextDouble((double) 2L)),
-      (long) new SecureRandom().nextDouble(3L),
-      Math.round(ThreadLocalRandom.current().nextDouble(4L)));
+      new Random().nextLong(1L),
+      new SplittableRandom().nextLong(2L),
+      new SecureRandom().nextLong(3L),
+      ThreadLocalRandom.current().nextLong(4L));
 }

Copyright © 2017-2024 Picnic Technologies BV