Fix PMD errors in JMH examples code.
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/AbstractBenchmark.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/AbstractBenchmark.java
index bed7274..eb0d166 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/AbstractBenchmark.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/AbstractBenchmark.java
@@ -44,5 +44,12 @@
@Fork(value = 1, jvmArgs = { "-server", "-Xms128M", "-Xmx128M" })
@State(Scope.Benchmark)
public abstract class AbstractBenchmark {
+ /**
+ * Create a new instance.
+ */
+ protected AbstractBenchmark() {
+ // Hide public constructor to prevent instantiation
+ }
+
// Empty. Serves as an annotation placeholder.
}
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineGenerationPerformance.java
index 9fc0a8c..87f71fc 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineGenerationPerformance.java
@@ -78,7 +78,7 @@
* <p>This is the biggest prime number for an {@code int} (2147483629) to give a worst case
* run-time for the method.</p>
*/
- static final int NEXT_INT_LIMIT = 2147483629;
+ static final int NEXT_INT_LIMIT = 2_147_483_629;
/**
* The upper limit for testing {@link UniformRandomProvider#nextLong(long)}.
@@ -86,7 +86,7 @@
* <p>This is the biggest prime number for a {@code long} (9223372036854775783L) to
* give a worst case run-time for the method.</p>
*/
- static final long NEXT_LONG_LIMIT = 9223372036854775783L;
+ static final long NEXT_LONG_LIMIT = 9_223_372_036_854_775_783L;
/**
* The provider for testing {@link UniformRandomProvider#nextByte()} and
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineSources.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineSources.java
index 7a3a6e0..7961594 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineSources.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/BaselineSources.java
@@ -113,7 +113,7 @@
}
/** Instantiates generator. This need only be done once per set of iterations. */
- @Setup(value = Level.Trial)
+ @Setup(Level.Trial)
public void setup() {
if (BASELINE.equals(randomSourceName)) {
provider = createBaseline();
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java
index 9a75fa6..747c7e3 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ConstructionPerformance.java
@@ -32,6 +32,7 @@
import org.openjdk.jmh.infra.Blackhole;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@@ -217,10 +218,10 @@
*/
@Override
@SuppressWarnings("unchecked")
- @Setup(value = Level.Trial)
+ @Setup(Level.Trial)
public void setup() {
super.setup();
- RandomSource randomSource = getRandomSource();
+ final RandomSource randomSource = getRandomSource();
nativeSeeds = findNativeSeeds(randomSource);
// Truncate array seeds to length 1
@@ -793,10 +794,13 @@
*
* @param sources Source of randomness.
* @param bh Data sink.
- * @throws Exception If reflection failed.
+ * @throws InvocationTargetException If reflection failed.
+ * @throws IllegalAccessException If reflection failed.
+ * @throws InstantiationException If reflection failed.
*/
@Benchmark
- public void newInstance(Sources sources, Blackhole bh) throws Exception {
+ public void newInstance(Sources sources, Blackhole bh) throws InstantiationException,
+ IllegalAccessException, InvocationTargetException {
final Object[] nativeSeeds = sources.getNativeSeeds();
final Constructor<?> constructor = sources.getConstructor();
for (int i = 0; i < SEEDS; i++) {
@@ -809,10 +813,16 @@
*
* @param sources Source of randomness.
* @param bh Data sink.
- * @throws Exception If reflection failed.
+ * @throws InvocationTargetException If reflection failed.
+ * @throws IllegalAccessException If reflection failed.
+ * @throws InstantiationException If reflection failed.
+ * @throws SecurityException If reflection failed.
+ * @throws NoSuchMethodException If reflection failed.
+ * @throws IllegalArgumentException If reflection failed.
*/
@Benchmark
- public void lookupNewInstance(Sources sources, Blackhole bh) throws Exception {
+ public void lookupNewInstance(Sources sources, Blackhole bh) throws InstantiationException,
+ IllegalAccessException, InvocationTargetException, NoSuchMethodException {
final Object[] nativeSeeds = sources.getNativeSeeds();
final Class<?> implementingClass = sources.getImplementingClass();
for (int i = 0; i < SEEDS; i++) {
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java
index d3b423f..dfca59e 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java
@@ -27,6 +27,9 @@
* various source providers for {@link UniformRandomProvider#nextBoolean()}.
*/
public class NextBooleanGenerationPerformance extends AbstractBenchmark {
+ /** The value. Must NOT be final to prevent JVM optimisation! */
+ private boolean value;
+
/**
* The benchmark state (retrieve the various "RandomSource"s).
*/
@@ -39,9 +42,6 @@
}
}
- /** The value. Must NOT be final to prevent JVM optimisation! */
- private boolean value;
-
/**
* Baseline for a JMH method call with no return value.
*/
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java
index 7a6713a..b7d064c 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java
@@ -28,6 +28,12 @@
*/
public class NextBytesGenerationPerformance extends AbstractBenchmark {
/**
+ * The value. This is a pre-allocated array. Must NOT be final to prevent JVM
+ * optimisation!
+ */
+ private byte[] value = new byte[BaselineGenerationPerformance.NEXT_BYTES_SIZE];
+
+ /**
* The benchmark state (retrieve the various "RandomSource"s).
*/
@State(Scope.Benchmark)
@@ -40,12 +46,6 @@
}
/**
- * The value. This is a pre-allocated array. Must NOT be final to prevent JVM
- * optimisation!
- */
- private byte[] value = new byte[BaselineGenerationPerformance.NEXT_BYTES_SIZE];
-
- /**
* Baseline for a JMH method call with no return value.
*/
@Benchmark
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java
index 5a0df5b..df256b2 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java
@@ -27,6 +27,9 @@
* various source providers for {@link UniformRandomProvider#nextDouble()}.
*/
public class NextDoubleGenerationPerformance extends AbstractBenchmark {
+ /** The value. Must NOT be final to prevent JVM optimisation! */
+ private double value;
+
/**
* The benchmark state (retrieve the various "RandomSource"s).
*/
@@ -39,9 +42,6 @@
}
}
- /** The value. Must NOT be final to prevent JVM optimisation! */
- private double value;
-
/**
* Baseline for a JMH method call with no return value.
*/
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java
index dde6726..1f1b28b 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java
@@ -27,6 +27,9 @@
* various source providers for {@link UniformRandomProvider#nextFloat()}.
*/
public class NextFloatGenerationPerformance extends AbstractBenchmark {
+ /** The value. Must NOT be final to prevent JVM optimisation! */
+ private float value;
+
/**
* The benchmark state (retrieve the various "RandomSource"s).
*/
@@ -39,9 +42,6 @@
}
}
- /** The value. Must NOT be final to prevent JVM optimisation! */
- private float value;
-
/**
* Baseline for a JMH method call with no return value.
*/
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java
index bec9fd0..0e6be7d 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java
@@ -28,6 +28,9 @@
* {@link UniformRandomProvider#nextInt(int)}.
*/
public class NextIntGenerationPerformance extends AbstractBenchmark {
+ /** The value. Must NOT be final to prevent JVM optimisation! */
+ private int value;
+
/**
* The benchmark state (retrieve the various "RandomSource"s).
*/
@@ -40,9 +43,6 @@
}
}
- /** The value. Must NOT be final to prevent JVM optimisation! */
- private int value;
-
/**
* Baseline for a JMH method call with no return value.
*/
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java
index 2ae8189..a9b09a7 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java
@@ -28,6 +28,9 @@
* {@link UniformRandomProvider#nextLong(long)}.
*/
public class NextLongGenerationPerformance extends AbstractBenchmark {
+ /** The value. Must NOT be final to prevent JVM optimisation! */
+ private long value;
+
/**
* The benchmark state (retrieve the various "RandomSource"s).
*/
@@ -40,9 +43,6 @@
}
}
- /** The value. Must NOT be final to prevent JVM optimisation! */
- private long value;
-
/**
* Baseline for a JMH method call with no return value.
*/
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/RngNextIntInRangeBenchmark.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/RngNextIntInRangeBenchmark.java
index 3edae74..921c003 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/RngNextIntInRangeBenchmark.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/RngNextIntInRangeBenchmark.java
@@ -449,10 +449,10 @@
* @return the int
*/
@Benchmark
- @OperationsPerInvocation(65536)
+ @OperationsPerInvocation(65_536)
public int nextIntNloop65536(IntRange range, Source source) {
int sum = 0;
- for (int i = 0; i < 65536; i++) {
+ for (int i = 0; i < 65_536; i++) {
sum += source.getRng().nextInt(range.getN());
}
return sum;
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ThreadLocalPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ThreadLocalPerformance.java
index 2477127..11e8e43 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ThreadLocalPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/ThreadLocalPerformance.java
@@ -48,6 +48,11 @@
@State(Scope.Benchmark)
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class ThreadLocalPerformance {
+ /**
+ * Number of random values to generate.
+ */
+ @Param({"0", "1", "10", "100"})
+ private int numValues;
/**
* The benchmark state (to retrieve the various "RandomSource"s).
@@ -106,11 +111,6 @@
};
}
}
- /**
- * Number of random values to generate.
- */
- @Param({"0", "1", "10", "100"})
- private int numValues;
/**
* @return the result
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/AliasMethodDiscreteSamplerPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/AliasMethodDiscreteSamplerPerformance.java
index 32d8307..8d83a6f 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/AliasMethodDiscreteSamplerPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/AliasMethodDiscreteSamplerPerformance.java
@@ -47,6 +47,13 @@
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class AliasMethodDiscreteSamplerPerformance {
/**
+ * The value.
+ *
+ * <p>This must NOT be final!</p>
+ */
+ private int value;
+
+ /**
* The discrete probability distribution and a sampler. Used to test the sample speed and
* construction speed of different sized distributions.
*/
@@ -95,7 +102,7 @@
@Setup
public void setup() {
probabilities = createProbabilities(size);
- UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64);
+ final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64);
sampler = AliasMethodDiscreteSampler.of(rng, probabilities, alpha);
}
@@ -116,13 +123,6 @@
}
}
- /**
- * The value.
- *
- * <p>This must NOT be final!</p>
- */
- private int value;
-
// Benchmarks methods below.
/**
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/ContinuousSamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/ContinuousSamplersPerformance.java
index fea6cfa..d7ce277 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/ContinuousSamplersPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/ContinuousSamplersPerformance.java
@@ -56,6 +56,13 @@
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class ContinuousSamplersPerformance {
/**
+ * The value.
+ *
+ * <p>This must NOT be final!</p>
+ */
+ private double value;
+
+ /**
* The {@link ContinuousSampler} samplers to use for testing. Creates the sampler for each
* {@link org.apache.commons.rng.simple.RandomSource RandomSource} in the default
* {@link RandomSources}.
@@ -129,13 +136,6 @@
// Benchmarks methods below.
/**
- * The value.
- *
- * <p>This must NOT be final!</p>
- */
- private double value;
-
- /**
* Baseline for the JMH timing overhead for production of an {@code double} value.
*
* @return the {@code double} value
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteSamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteSamplersPerformance.java
index ef41587..257721f 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteSamplersPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteSamplersPerformance.java
@@ -55,6 +55,13 @@
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class DiscreteSamplersPerformance {
/**
+ * The value.
+ *
+ * <p>This must NOT be final!</p>
+ */
+ private int value;
+
+ /**
* The {@link DiscreteSampler} samplers to use for testing. Creates the sampler for each
* {@link org.apache.commons.rng.simple.RandomSource RandomSource} in the default
* {@link RandomSources}.
@@ -137,13 +144,6 @@
// Benchmarks methods below.
/**
- * The value.
- *
- * <p>This must NOT be final!</p>
- */
- private int value;
-
- /**
* Baseline for the JMH timing overhead for production of an {@code int} value.
*
* @return the {@code int} value
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteUniformSamplerGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteUniformSamplerGenerationPerformance.java
index d1ab8a7..ce1a7d0 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteUniformSamplerGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/DiscreteUniformSamplerGenerationPerformance.java
@@ -144,7 +144,7 @@
@Benchmark
public void nextIntBaseline(Blackhole bh, Sources source) {
int sum = 0;
- for (int i = samples; i-- != 0;) {
+ for (int i = 0; i < samples; i++) {
sum += source.getGenerator().nextInt();
}
bh.consume(sum);
@@ -159,7 +159,7 @@
public void nextIntRange(Blackhole bh, Sources source, IntRange range) {
final int n = range.getUpperBound();
int sum = 0;
- for (int i = samples; i-- != 0;) {
+ for (int i = 0; i < samples; i++) {
sum += source.getGenerator().nextInt(n);
}
bh.consume(sum);
@@ -176,7 +176,7 @@
final SharedStateDiscreteSampler sampler = DiscreteUniformSampler.of(
source.getGenerator(), 0, range.getUpperBound() - 1);
int sum = 0;
- for (int i = samples; i-- != 0;) {
+ for (int i = 0; i < samples; i++) {
sum += sampler.sample();
}
bh.consume(sum);
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/EnumeratedDistributionSamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/EnumeratedDistributionSamplersPerformance.java
index 40664cc..19ef181 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/EnumeratedDistributionSamplersPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/EnumeratedDistributionSamplersPerformance.java
@@ -56,6 +56,13 @@
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class EnumeratedDistributionSamplersPerformance {
/**
+ * The value for the baseline generation of an {@code int} value.
+ *
+ * <p>This must NOT be final!</p>
+ */
+ private int value;
+
+ /**
* The random sources to use for testing. This is a smaller list than all the possible
* random sources; the list is composed of generators of different speeds.
*/
@@ -102,18 +109,6 @@
@State(Scope.Benchmark)
public abstract static class SamplerSources extends LocalRandomSources {
/**
- * A factory for creating DiscreteSampler objects.
- */
- interface DiscreteSamplerFactory {
- /**
- * Creates the sampler.
- *
- * @return the sampler
- */
- DiscreteSampler create();
- }
-
- /**
* The sampler type.
*/
@Param({"BinarySearchDiscreteSampler",
@@ -140,6 +135,18 @@
private DiscreteSampler sampler;
/**
+ * A factory for creating DiscreteSampler objects.
+ */
+ interface DiscreteSamplerFactory {
+ /**
+ * Creates the sampler.
+ *
+ * @return the sampler
+ */
+ DiscreteSampler create();
+ }
+
+ /**
* Gets the sampler.
*
* @return the sampler.
@@ -315,8 +322,8 @@
final double mean2 = 20;
final IntegerDistribution dist1 = createPoissonDistribution(mean2);
final int max = dist1.inverseCumulativeProbability(CUMULATIVE_PROBABILITY_LIMIT);
- double[] p1 = createProbabilities(dist1, 0, max);
- double[] p2 = createProbabilities(createPoissonDistribution(mean1), 0, max);
+ final double[] p1 = createProbabilities(dist1, 0, max);
+ final double[] p2 = createProbabilities(createPoissonDistribution(mean1), 0, max);
for (int i = 0; i < p1.length; i++) {
p1[i] += p2[i];
}
@@ -347,8 +354,9 @@
*/
private static double[] createProbabilities(IntegerDistribution dist, int lower, int upper) {
double[] probabilities = new double[upper - lower + 1];
- for (int i = 0, x = lower; x <= upper; i++, x++) {
- probabilities[i] = dist.probability(x);
+ int index = 0;
+ for (int x = lower; x <= upper; x++) {
+ probabilities[index++] = dist.probability(x);
}
return probabilities;
}
@@ -490,13 +498,6 @@
}
}
- /**
- * The value for the baseline generation of an {@code int} value.
- *
- * <p>This must NOT be final!</p>
- */
- private int value;
-
// Benchmarks methods below.
/**
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/GeometricSamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/GeometricSamplersPerformance.java
index 954a3bd..8f6ad72 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/GeometricSamplersPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/GeometricSamplersPerformance.java
@@ -49,6 +49,13 @@
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class GeometricSamplersPerformance {
/**
+ * The value.
+ *
+ * <p>This must NOT be final!</p>
+ */
+ private int value;
+
+ /**
* The samplers's to use for testing. Defines the RandomSource, probability of success
* and the type of Geometric sampler.
*/
@@ -142,13 +149,6 @@
}
/**
- * The value.
- *
- * <p>This must NOT be final!</p>
- */
- private int value;
-
- /**
* Baseline for the JMH timing overhead for production of an {@code int} value.
*
* @return the {@code int} value
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplerCachePerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplerCachePerformance.java
index efe0113..ed947ec 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplerCachePerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplerCachePerformance.java
@@ -118,7 +118,7 @@
@Fork(value = 1, jvmArgs = { "-server", "-Xms128M", "-Xmx128M" })
public class PoissonSamplerCachePerformance {
/** Number of samples per run. */
- private static final int NUM_SAMPLES = 100000;
+ private static final int NUM_SAMPLES = 100_000;
/**
* Number of range samples.
*
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplersPerformance.java
index 4fab0a2..738c5e0 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplersPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/distribution/PoissonSamplersPerformance.java
@@ -49,6 +49,13 @@
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
public class PoissonSamplersPerformance {
/**
+ * The value for the baseline generation of an {@code int} value.
+ *
+ * <p>This must NOT be final!</p>
+ */
+ private int value;
+
+ /**
* The mean for the call to {@link Math#exp(double)}.
*/
@State(Scope.Benchmark)
@@ -86,18 +93,6 @@
@State(Scope.Benchmark)
public static class Sources {
/**
- * A factory for creating DiscreteSampler objects.
- */
- interface DiscreteSamplerFactory {
- /**
- * Creates the sampler.
- *
- * @return the sampler
- */
- DiscreteSampler create();
- }
-
- /**
* RNG providers.
*
* <p>Use different speeds.</p>
@@ -152,6 +147,18 @@
private DiscreteSampler sampler;
/**
+ * A factory for creating DiscreteSampler objects.
+ */
+ interface DiscreteSamplerFactory {
+ /**
+ * Creates the sampler.
+ *
+ * @return the sampler
+ */
+ DiscreteSampler create();
+ }
+
+ /**
* @return The RNG.
*/
public UniformRandomProvider getGenerator() {
@@ -1025,13 +1032,6 @@
}
}
- /**
- * The value for the baseline generation of an {@code int} value.
- *
- * <p>This must NOT be final!</p>
- */
- private int value;
-
// Benchmarks methods below.
/**
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/ListShuffleBenchmark.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/ListShuffleBenchmark.java
index 9487aab..aab41fb 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/ListShuffleBenchmark.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/ListShuffleBenchmark.java
@@ -213,7 +213,7 @@
*/
static final class SplitMix32RNG extends IntProvider {
/** The state. */
- protected long state;
+ private long state;
/**
* Create a new instance.
@@ -262,7 +262,7 @@
private static final long serialVersionUID = 1L;
/** The state. */
- protected long state;
+ private long state;
/**
* Create a new instance.
@@ -390,9 +390,9 @@
// Copy back. Use raw types.
final ListIterator it = list.listIterator();
- for (int i = 0; i < array.length; i++) {
+ for (final Object value : array) {
it.next();
- it.set(array[i]);
+ it.set(value);
}
}
}
@@ -426,9 +426,9 @@
// Copy back. Use raw types.
final ListIterator it = list.listIterator();
- for (int i = 0; i < array.length; i++) {
+ for (final Object value : array) {
it.next();
- it.set(array[i]);
+ it.set(value);
}
}