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 2019/11/09 00:03:19 UTC
[commons-numbers] 16/19: 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-numbers.git
commit 2d35bfc0a51741fb6cd825ae8b8e3d25abafcb88
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Nov 8 23:20:34 2019 +0000
Use final.
---
.../java/org/apache/commons/numbers/primes/Primes.java | 2 +-
.../org/apache/commons/numbers/primes/SmallPrimes.java | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java
index a971372..5c3ad73 100644
--- a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java
+++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java
@@ -51,7 +51,7 @@ public final class Primes {
return false;
}
- for (int p : SmallPrimes.PRIMES) {
+ for (final int p : SmallPrimes.PRIMES) {
if (0 == (n % p)) {
return n == p;
}
diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java
index 4097f32..f0fc950 100644
--- a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java
+++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java
@@ -107,20 +107,20 @@ final class SmallPrimes {
trial division is reduced to 480/(2*3*5*7*11), which is about 20.78%,
of all integers.
*/
- Set<Integer> primeNumbers = new HashSet<>();
+ final Set<Integer> primeNumbers = new HashSet<>();
primeNumbers.add(Integer.valueOf(2));
primeNumbers.add(Integer.valueOf(3));
primeNumbers.add(Integer.valueOf(5));
primeNumbers.add(Integer.valueOf(7));
primeNumbers.add(Integer.valueOf(11));
- int product = primeNumbers.stream().reduce(1, (a, b) -> a * b);
- int[] equivalenceClasses = new int[primeNumbers.stream().mapToInt(a -> a - 1).reduce(1, (a, b) -> a * b)];
+ final int product = primeNumbers.stream().reduce(1, (a, b) -> a * b);
+ final int[] equivalenceClasses = new int[primeNumbers.stream().mapToInt(a -> a - 1).reduce(1, (a, b) -> a * b)];
int equivalenceClassIndex = 0;
for (int i = 0; i < product; i++) {
boolean foundPrimeFactor = false;
- for (Integer prime : primeNumbers) {
+ for (final Integer prime : primeNumbers) {
if (i % prime == 0) {
foundPrimeFactor = true;
break;
@@ -150,7 +150,7 @@ final class SmallPrimes {
*/
static int smallTrialDivision(int n,
final List<Integer> factors) {
- for (int p : PRIMES) {
+ for (final int p : PRIMES) {
while (0 == n % p) {
n /= p;
factors.add(p);
@@ -172,7 +172,7 @@ final class SmallPrimes {
static int boundedTrialDivision(int n,
int maxFactor,
List<Integer> factors) {
- int minFactor = PRIMES_LAST + 2;
+ final int minFactor = PRIMES_LAST + 2;
/*
only trying integers of the form k*m + c, where k >= 0, m is the
@@ -180,7 +180,7 @@ final class SmallPrimes {
as prime factors, and c is an integer undivisible by all of those
prime numbers; in other words, skipping multiples of these primes
*/
- int m = PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES.getValue()
+ final int m = PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES.getValue()
[PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES.getValue().length - 1] + 1;
int km = m * (minFactor / m);
int currentEquivalenceClassIndex = Arrays.binarySearch(
@@ -196,7 +196,7 @@ final class SmallPrimes {
boolean done = false;
while (!done) {
// no check is done about n >= f
- int f = km + PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES.getValue()[currentEquivalenceClassIndex];
+ final int f = km + PRIME_NUMBERS_AND_COPRIME_EQUIVALENCE_CLASSES.getValue()[currentEquivalenceClassIndex];
if (f > maxFactor) {
done = true;
} else if (0 == n % f) {
@@ -273,7 +273,7 @@ final class SmallPrimes {
if ((1 != y) && (y != nMinus1)) {
int j = 1;
while ((j <= s - 1) && (nMinus1 != y)) {
- long square = ((long) y) * y;
+ final long square = ((long) y) * y;
y = (int) (square % n);
if (1 == y) {
return false;