You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2024/01/12 22:32:48 UTC

(commons-statistics) 01/02: Use final

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit a4f37f785b8742245a9411359c305139be919941
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Jan 12 22:24:00 2024 +0000

    Use final
---
 .../statistics/descriptive/BaseDoubleStatisticTest.java    | 10 +++++-----
 .../statistics/descriptive/BaseIntStatisticTest.java       | 10 +++++-----
 .../statistics/descriptive/BaseLongStatisticTest.java      | 10 +++++-----
 .../commons/statistics/descriptive/BaseStatisticTest.java  |  2 +-
 .../statistics/descriptive/DoubleStatisticsTest.java       |  6 +++---
 .../apache/commons/statistics/descriptive/IntMathTest.java | 12 ++++++------
 .../commons/statistics/descriptive/IntStatisticsTest.java  |  6 +++---
 .../commons/statistics/descriptive/LongStatisticsTest.java |  6 +++---
 .../statistics/descriptive/StandardDeviationTest.java      |  2 +-
 .../statistics/descriptive/SumOfCubedDeviationsTest.java   |  2 +-
 .../statistics/descriptive/SumOfFourthDeviationsTest.java  |  2 +-
 .../apache/commons/statistics/descriptive/TestHelper.java  | 14 +++++++-------
 .../commons/statistics/descriptive/VarianceTest.java       |  2 +-
 .../statistics/examples/jmh/descriptive/Int128.java        |  2 +-
 .../examples/jmh/descriptive/IntMomentPerformance.java     | 14 +++++++-------
 .../examples/jmh/descriptive/MomentPerformance.java        |  4 ++--
 .../statistics/examples/jmh/descriptive/UInt128.java       |  2 +-
 .../statistics/examples/jmh/descriptive/UInt192.java       |  6 +++---
 .../statistics/examples/jmh/descriptive/IntMathTest.java   |  8 ++++----
 19 files changed, 60 insertions(+), 60 deletions(-)

diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
index 8de8b44..94d64ec 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
@@ -906,7 +906,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
      * @return the set of arrays
      */
     private static double[][] cut(double[] data, int... sizes) {
-        ArrayList<double[]> set = new ArrayList<>();
+        final ArrayList<double[]> set = new ArrayList<>();
         int from = 0;
         for (final int size : sizes) {
             final int to = Math.min(data.length, from + size);
@@ -1132,7 +1132,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
             while (repeat++ < RANDOM_PERMUTATIONS) {
                 testAccept(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1152,7 +1152,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
             while (repeat++ < RANDOM_PERMUTATIONS) {
                 testArray(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1175,7 +1175,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
                 TestHelper.unconcatenate(allValues, values);
                 testAcceptAndCombine(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1198,7 +1198,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
                 TestHelper.unconcatenate(allValues, values);
                 testArrayAndCombine(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
index 19644e9..ed51ade 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
@@ -780,7 +780,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
      * @return the set of arrays
      */
     private static int[][] cut(int[] data, int... sizes) {
-        ArrayList<int[]> set = new ArrayList<>();
+        final ArrayList<int[]> set = new ArrayList<>();
         int from = 0;
         for (final int size : sizes) {
             final int to = Math.min(data.length, from + size);
@@ -1022,7 +1022,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
             while (repeat++ < RANDOM_PERMUTATIONS) {
                 testAccept(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1042,7 +1042,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
             while (repeat++ < RANDOM_PERMUTATIONS) {
                 testArray(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1065,7 +1065,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
                 TestHelper.unconcatenate(allValues, values);
                 testAcceptAndCombine(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1088,7 +1088,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
                 TestHelper.unconcatenate(allValues, values);
                 testArrayAndCombine(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
index 29e8976..1988202 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
@@ -798,7 +798,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
      * @return the set of arrays
      */
     private static long[][] cut(long[] data, int... sizes) {
-        ArrayList<long[]> set = new ArrayList<>();
+        final ArrayList<long[]> set = new ArrayList<>();
         int from = 0;
         for (final int size : sizes) {
             final int to = Math.min(data.length, from + size);
@@ -1022,7 +1022,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
             while (repeat++ < RANDOM_PERMUTATIONS) {
                 testAccept(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1042,7 +1042,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
             while (repeat++ < RANDOM_PERMUTATIONS) {
                 testArray(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1065,7 +1065,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
                 TestHelper.unconcatenate(allValues, values);
                 testAcceptAndCombine(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
@@ -1088,7 +1088,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
                 TestHelper.unconcatenate(allValues, values);
                 testArrayAndCombine(TestHelper.shuffle(rng, values), expected, tol);
             }
-        } catch (AssertionError e) {
+        } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseStatisticTest.java
index ef28f72..5ea1f24 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseStatisticTest.java
@@ -326,7 +326,7 @@ abstract class BaseStatisticTest {
             default:
                 break;
             }
-        } catch (Throwable t) {
+        } catch (final Throwable t) {
             return MARKER_OBJECT;
         }
         throw new IllegalStateException("Unrecognised result type: " + getResultType());
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java
index 69fc8fb..ac3f97d 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/DoubleStatisticsTest.java
@@ -413,7 +413,7 @@ class DoubleStatisticsTest {
 
     @Test
     void testIsSupportedWithNull() {
-        DoubleStatistics s = DoubleStatistics.of(Statistic.MIN);
+        final DoubleStatistics s = DoubleStatistics.of(Statistic.MIN);
         Assertions.assertThrows(NullPointerException.class, () -> s.isSupported(null));
     }
 
@@ -422,8 +422,8 @@ class DoubleStatisticsTest {
     void testIncompatibleCombineThrows(EnumSet<Statistic> stat1, EnumSet<Statistic> stat2) {
         final double[] v1 = {1, 2, 3.5, 6};
         final double[] v2 = {3, 4, 5};
-        DoubleStatistics statistics = DoubleStatistics.of(stat1, v1);
-        DoubleStatistics other = DoubleStatistics.of(stat2, v2);
+        final DoubleStatistics statistics = DoubleStatistics.of(stat1, v1);
+        final DoubleStatistics other = DoubleStatistics.of(stat2, v2);
         // Store values
         final double[] values = stat1.stream().mapToDouble(statistics::getAsDouble).toArray();
         Assertions.assertThrows(IllegalArgumentException.class, () -> statistics.combine(other),
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMathTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMathTest.java
index b16baff..f6efb10 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMathTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntMathTest.java
@@ -130,16 +130,16 @@ class IntMathTest {
         final Stream.Builder<Arguments> builder = Stream.builder();
         for (int i = 0; i < 100; i++) {
             long a = rng.nextLong();
-            long b = rng.nextLong();
+            final long b = rng.nextLong();
             builder.accept(Arguments.of(a, b));
             builder.accept(Arguments.of(0, b));
             // Edge cases where trailing bits are required for rounding.
             // Create a 55-bit number. Ensure the highest bit is set.
             a = (a << 9) | Long.MIN_VALUE;
             // Shift right and carry bits down.
-            int shift = rng.nextInt(1, 64);
-            long c = a >>> shift;
-            long d = a << -shift;
+            final int shift = rng.nextInt(1, 64);
+            final long c = a >>> shift;
+            final long d = a << -shift;
             // Check
             Assertions.assertEquals(Long.bitCount(a), Long.bitCount(c) + Long.bitCount(d));
             builder.accept(Arguments.of(c, d));
@@ -175,7 +175,7 @@ class IntMathTest {
             Integer i = null;
             try {
                 i = Math.toIntExact(Math.round(y));
-            } catch (Throwable t) {
+            } catch (final Throwable t) {
                 Assertions.assertThrowsExactly(t.getClass(), () -> IntMath.toIntExact(y), intMsg);
             }
             if (i != null) {
@@ -185,7 +185,7 @@ class IntMathTest {
     }
 
     static DoubleStream testToIntExact() {
-        DoubleStream.Builder builder = DoubleStream.builder();
+        final DoubleStream.Builder builder = DoubleStream.builder();
         for (double x = 0; x < 3.5; x += 0.25) {
             builder.accept(x);
         }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java
index fae8307..958191b 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/IntStatisticsTest.java
@@ -466,7 +466,7 @@ class IntStatisticsTest {
 
     @Test
     void testIsSupportedWithNull() {
-        IntStatistics s = IntStatistics.of(Statistic.MIN);
+        final IntStatistics s = IntStatistics.of(Statistic.MIN);
         Assertions.assertThrows(NullPointerException.class, () -> s.isSupported(null));
     }
 
@@ -475,8 +475,8 @@ class IntStatisticsTest {
     void testIncompatibleCombineThrows(EnumSet<Statistic> stat1, EnumSet<Statistic> stat2) {
         final int[] v1 = {1, 2, 4, 6};
         final int[] v2 = {3, 4, 5};
-        IntStatistics statistics = IntStatistics.of(stat1, v1);
-        IntStatistics other = IntStatistics.of(stat2, v2);
+        final IntStatistics statistics = IntStatistics.of(stat1, v1);
+        final IntStatistics other = IntStatistics.of(stat2, v2);
         // Store values
         final double[] values = stat1.stream().mapToDouble(statistics::getAsDouble).toArray();
         Assertions.assertThrows(IllegalArgumentException.class, () -> statistics.combine(other),
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java
index 4ea1ba6..6fee0f3 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/LongStatisticsTest.java
@@ -466,7 +466,7 @@ class LongStatisticsTest {
 
     @Test
     void testIsSupportedWithNull() {
-        LongStatistics s = LongStatistics.of(Statistic.MIN);
+        final LongStatistics s = LongStatistics.of(Statistic.MIN);
         Assertions.assertThrows(NullPointerException.class, () -> s.isSupported(null));
     }
 
@@ -475,8 +475,8 @@ class LongStatisticsTest {
     void testIncompatibleCombineThrows(EnumSet<Statistic> stat1, EnumSet<Statistic> stat2) {
         final long[] v1 = {1, 2, 4, 6};
         final long[] v2 = {3, 4, 5};
-        LongStatistics statistics = LongStatistics.of(stat1, v1);
-        LongStatistics other = LongStatistics.of(stat2, v2);
+        final LongStatistics statistics = LongStatistics.of(stat1, v1);
+        final LongStatistics other = LongStatistics.of(stat2, v2);
         // Store values
         final double[] values = stat1.stream().mapToDouble(statistics::getAsDouble).toArray();
         Assertions.assertThrows(IllegalArgumentException.class, () -> statistics.combine(other),
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StandardDeviationTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StandardDeviationTest.java
index dd35ecd..dc24949 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StandardDeviationTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/StandardDeviationTest.java
@@ -146,7 +146,7 @@ final class StandardDeviationTest extends BaseDoubleStatisticTest<StandardDeviat
      * @return Standard deviation of values
      */
     private static double computeExpectedStandardDeviation(double[] values) {
-        long n = values.length;
+        final long n = values.length;
         if (n == 0) {
             return Double.NaN;
         }
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfCubedDeviationsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfCubedDeviationsTest.java
index 531e587..4acb46d 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfCubedDeviationsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfCubedDeviationsTest.java
@@ -108,7 +108,7 @@ final class SumOfCubedDeviationsTest extends BaseDoubleStatisticTest<SumOfCubedD
         // Round mean to nearest double
         final BigDecimal mu = new BigDecimal(xbar);
         double sum = 0;
-        for (double value : values) {
+        for (final double value : values) {
             BigDecimal bdDiff = new BigDecimal(value);
             bdDiff = bdDiff.subtract(mu);
             bdDiff = bdDiff.pow(3);
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
index c6c3e4d..bf44a6b 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
@@ -128,7 +128,7 @@ final class SumOfFourthDeviationsTest extends BaseDoubleStatisticTest<SumOfFourt
         // Round mean to nearest double
         final BigDecimal mu = new BigDecimal(mean.doubleValue());
         BigDecimal bd = BigDecimal.ZERO;
-        for (double value : values) {
+        for (final double value : values) {
             BigDecimal bdDiff = new BigDecimal(value);
             bdDiff = bdDiff.subtract(mu);
             bdDiff = bdDiff.pow(4);
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java
index 11485c2..8cf1dc6 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java
@@ -166,7 +166,7 @@ final class TestHelper {
      */
     static BigDecimal computeExpectedMean(double[] values) {
         BigDecimal bd = BigDecimal.ZERO;
-        for (double value : values) {
+        for (final double value : values) {
             bd = bd.add(new BigDecimal(value));
         }
         return bd.divide(BigDecimal.valueOf(values.length), MathContext.DECIMAL128);
@@ -184,7 +184,7 @@ final class TestHelper {
      * @return sum-of-square deviations
      */
     static BigDecimal computeExpectedSumOfSquaredDeviations(double[] values, BigDecimal[] mean) {
-        long n = values.length;
+        final long n = values.length;
         if (n <= 1) {
             return BigDecimal.ZERO;
         }
@@ -193,7 +193,7 @@ final class TestHelper {
             mean[0] = m;
         }
         BigDecimal ss = BigDecimal.ZERO;
-        for (double value : values) {
+        for (final double value : values) {
             // Note: The mean is returned in DECIMAL128 precision.
             // Truncate the double value to the same precision.
             // This avoids round-off issues with extreme values such as Double.MAX_VALUE
@@ -431,7 +431,7 @@ final class TestHelper {
         Integer i = null;
         try {
             i = expected.getAsInt();
-        } catch (Throwable t) {
+        } catch (final Throwable t) {
             Assertions.assertThrowsExactly(t.getClass(), () -> actual.getAsInt(), intMsg);
         }
         if (i != null) {
@@ -455,7 +455,7 @@ final class TestHelper {
         Long l = null;
         try {
             l = expected.getAsLong();
-        } catch (Throwable t) {
+        } catch (final Throwable t) {
             Assertions.assertThrowsExactly(t.getClass(), () -> actual.getAsLong(), longMsg);
         }
         if (l != null) {
@@ -485,7 +485,7 @@ final class TestHelper {
         Double d = null;
         try {
             d = expected.getAsDouble();
-        } catch (Throwable t) {
+        } catch (final Throwable t) {
             Assertions.assertThrowsExactly(t.getClass(), () -> actual.getAsDouble(), doubleMsg);
         }
         if (d != null) {
@@ -521,7 +521,7 @@ final class TestHelper {
         BigInteger b = null;
         try {
             b = expected.getAsBigInteger();
-        } catch (Throwable t) {
+        } catch (final Throwable t) {
             Assertions.assertThrowsExactly(t.getClass(), () -> actual.get(), bigMsg);
         }
         if (b != null) {
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
index 59d95fa..a529e33 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
@@ -113,7 +113,7 @@ final class VarianceTest extends BaseDoubleStatisticTest<Variance> {
      * @return Variance of values
      */
     static double computeExpectedVariance(double[] values, BigDecimal[] mean) {
-        long n = values.length;
+        final long n = values.length;
         if (n == 0) {
             return Double.NaN;
         }
diff --git a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/Int128.java b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/Int128.java
index 66c9e92..002ecba 100644
--- a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/Int128.java
+++ b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/Int128.java
@@ -126,7 +126,7 @@ final class Int128 {
         // (-,-) -> +
         // Branchless.
         // Extract sign bit.
-        long signMask = ((y ^ r) & (x ^ r)) >> 63;
+        final long signMask = ((y ^ r) & (x ^ r)) >> 63;
         // Carry using [0/1] * [+1/-1]
         hi += signMask & (1 - ((x >>> 62) & 0x2));
         lo = r;
diff --git a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMomentPerformance.java b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMomentPerformance.java
index 260e526..36e05df 100644
--- a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMomentPerformance.java
+++ b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMomentPerformance.java
@@ -1049,7 +1049,7 @@ public class IntMomentPerformance {
             // sum(x^2) * n will be OK when the upper 32-bits are zero.
             // Both are safe when n < 2^32.
             if ((n >>> Integer.SIZE) == 0) {
-                DD diff = sumSq.unsignedMultiply((int) n).subtract(sum.squareLow()).toDD();
+                final DD diff = sumSq.unsignedMultiply((int) n).subtract(sum.squareLow()).toDD();
                 // Divisor is an exact double
                 if (n < (1L << 26)) {
                     // n0*n is safe as a long
@@ -1057,7 +1057,7 @@ public class IntMomentPerformance {
                 }
                 return diff.divide(DD.of(n).multiply(DD.of(n0))).doubleValue();
             }
-            BigInteger diff = sumSq.toBigInteger().multiply(BigInteger.valueOf(n)).subtract(square(sum.toBigInteger()));
+            final BigInteger diff = sumSq.toBigInteger().multiply(BigInteger.valueOf(n)).subtract(square(sum.toBigInteger()));
             // Compute the divide in double precision
             return diff.doubleValue() / ((double) n0 * n);
         }
@@ -1087,7 +1087,7 @@ public class IntMomentPerformance {
             // sum(x^2) * n will be OK when the upper 32-bits are zero.
             // Both are safe when n < 2^32.
             if ((n >>> Integer.SIZE) == 0) {
-                DD diff = sumSq.unsignedMultiply((int) n).subtract(sum.squareLow()).toDD();
+                final DD diff = sumSq.unsignedMultiply((int) n).subtract(sum.squareLow()).toDD();
                 // Divisor is an exact double
                 if (n < (1L << 26)) {
                     // n0*n is safe as a long
@@ -1095,7 +1095,7 @@ public class IntMomentPerformance {
                 }
                 return diff.divide(DD.of(n).multiply(DD.of(n0))).doubleValue();
             }
-            BigInteger diff = sumSq.toBigInteger().multiply(BigInteger.valueOf(n)).subtract(square(sum.toBigInteger()));
+            final BigInteger diff = sumSq.toBigInteger().multiply(BigInteger.valueOf(n)).subtract(square(sum.toBigInteger()));
             // Assume n is big to overflow the sum(x)
             // Compute the divide in double-double precision
             return DD.of(diff.doubleValue()).divide(DD.of(n).multiply(DD.of(n0))).doubleValue();
@@ -1402,7 +1402,7 @@ public class IntMomentPerformance {
             if ("128bitAdd".equals(name)) {
                 function = x -> {
                     final Int128 s = Int128.create();
-                    for (long y : x) {
+                    for (final long y : x) {
                         s.add(y);
                     }
                     return s.hi64();
@@ -1410,7 +1410,7 @@ public class IntMomentPerformance {
             } else if ("128bitAdd2".equals(name)) {
                 function = x -> {
                     final Int128 s = Int128.create();
-                    for (long y : x) {
+                    for (final long y : x) {
                         s.add2(y);
                     }
                     return s.hi64();
@@ -1418,7 +1418,7 @@ public class IntMomentPerformance {
             } else if ("64bitSum".equals(name)) {
                 function = x -> {
                     long s = 0;
-                    for (long y : x) {
+                    for (final long y : x) {
                         s += y;
                     }
                     return s;
diff --git a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/MomentPerformance.java b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/MomentPerformance.java
index ae4ba27..2e8eb70 100644
--- a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/MomentPerformance.java
+++ b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/MomentPerformance.java
@@ -419,7 +419,7 @@ public class MomentPerformance {
      */
     static class NumbersSum implements DoubleConsumer, DoubleSupplier {
         /** Sum of values that have been added. */
-        private Sum sum = Sum.create();
+        private final Sum sum = Sum.create();
 
         @Override
         public void accept(double value) {
@@ -438,7 +438,7 @@ public class MomentPerformance {
      */
     static class NumbersSum2 implements DoubleConsumer, DoubleSupplier {
         /** Sum of values that have been added. */
-        private Sum sum = Sum.create();
+        private final Sum sum = Sum.create();
 
         /** Non-finite result. This is the sum of non-finite values. */
         private double nonFiniteValue;
diff --git a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt128.java b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt128.java
index 5f6b5f3..7cd76c0 100644
--- a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt128.java
+++ b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt128.java
@@ -207,7 +207,7 @@ final class UInt128 {
     BigInteger toBigInteger() {
         // Test if we have more than 63-bits
         if (ab != 0 || c < 0) {
-            ByteBuffer bb = ByteBuffer.allocate(Integer.BYTES * 4)
+            final ByteBuffer bb = ByteBuffer.allocate(Integer.BYTES * 4)
                 .putLong(ab)
                 .putInt(c)
                 .putInt(d);
diff --git a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt192.java b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt192.java
index 7dd3de2..9c705c7 100644
--- a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt192.java
+++ b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/UInt192.java
@@ -234,9 +234,9 @@ final class UInt192 {
      * @return the value
      */
     double toDouble() {
-        long h = hi64();
-        long m = mid64();
-        long l = lo64();
+        final long h = hi64();
+        final long m = mid64();
+        final long l = lo64();
         if (h == 0) {
             return IntMath.uin128ToDouble(m, l);
         }
diff --git a/commons-statistics-examples/examples-jmh/src/test/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMathTest.java b/commons-statistics-examples/examples-jmh/src/test/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMathTest.java
index d1bc9cf..2f52e69 100644
--- a/commons-statistics-examples/examples-jmh/src/test/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMathTest.java
+++ b/commons-statistics-examples/examples-jmh/src/test/java/org/apache/commons/statistics/examples/jmh/descriptive/IntMathTest.java
@@ -124,16 +124,16 @@ class IntMathTest {
         final Stream.Builder<Arguments> builder = Stream.builder();
         for (int i = 0; i < 100; i++) {
             long a = rng.nextLong();
-            long b = rng.nextLong();
+            final long b = rng.nextLong();
             builder.accept(Arguments.of(a, b));
             builder.accept(Arguments.of(0, b));
             // Edge cases where trailing bits are required for rounding.
             // Create a 55-bit number. Ensure the highest bit is set.
             a = (a << 9) | Long.MIN_VALUE;
             // Shift right and carry bits down.
-            int shift = rng.nextInt(1, 64);
-            long c = a >>> shift;
-            long d = a << -shift;
+            final int shift = rng.nextInt(1, 64);
+            final long c = a >>> shift;
+            final long d = a << -shift;
             // Check
             Assertions.assertEquals(Long.bitCount(a), Long.bitCount(c) + Long.bitCount(d));
             builder.accept(Arguments.of(c, d));