Skip to content

Commit bdc2dfe

Browse files
committed
pmd fix: avoid assignment in operand
1 parent 7ebad51 commit bdc2dfe

File tree

8 files changed

+22
-11
lines changed

8 files changed

+22
-11
lines changed

commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ abstract class AbstractContinuousDistribution
8181
double getMedian() {
8282
double m = median;
8383
if (Double.isNaN(m)) {
84-
median = m = inverseCumulativeProbability(0.5);
84+
m = inverseCumulativeProbability(0.5);
85+
median = m;
8586
}
8687
return m;
8788
}

commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ abstract class AbstractDiscreteDistribution
5959
int getMedian() {
6060
long m = median;
6161
if (m == NO_MEDIAN) {
62-
median = m = inverseCumulativeProbability(0.5);
62+
m = inverseCumulativeProbability(0.5);
63+
median = m;
6364
}
6465
return (int) m;
6566
}

commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ private double[] getMidPoint() {
484484
x--;
485485
p1 = p0;
486486
}
487-
midpoint = v = new double[] {x, p1};
487+
v = new double[] {x, p1};
488+
midpoint = v;
488489
}
489490
return v;
490491
}

commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/KolmogorovSmirnovTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,22 +598,24 @@ public TwoResult test(double[] x, double[] y) {
598598
final double d2 = significantTies ? computeD(tiesD[1], n, m, gcd) : d;
599599

600600
final double p;
601-
double p2;
601+
final double p2;
602602

603603
// Allow bootstrap estimation of the p-value
604604
if (method == PValueMethod.ESTIMATE) {
605605
p = estimateP(sx, sy, dnm);
606606
p2 = Double.NaN;
607607
} else {
608608
final boolean exact = method == PValueMethod.EXACT;
609-
p = p2 = twoSampleP(dnm, n, m, gcd, d, exact);
609+
p = twoSampleP(dnm, n, m, gcd, d, exact);
610610
if (significantTies) {
611611
// Compute the upper bound on D.
612612
// The p-value is also computed. The alternative is to save the options
613613
// in the result with (upper dnm, n, m) and compute it on-demand.
614614
// Note detection of whether the exact P computation is possible is based on
615615
// n and m, thus this will use the same computation.
616616
p2 = twoSampleP(tiesD[1], n, m, gcd, d2, exact);
617+
} else {
618+
p2 = p;
617619
}
618620
}
619621
return new TwoResult(d, sign[0], p, significantTies, d2, p2);

commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/MannWhitneyUTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,17 @@ private static double[][][] getF(int m, int n, int k) {
561561
for (int x = 0; x < m1; x++) {
562562
f[x] = Arrays.copyOf(f[x], sn);
563563
for (int y = n1; y < sn; y++) {
564-
final double[] b = f[x][y] = new double[sk];
564+
final double[] b = new double[sk];
565+
f[x][y] = b;
565566
initialize(b);
566567
}
567568
}
568569
}
569570
if (growK) {
570571
for (int x = 0; x < m1; x++) {
571572
for (int y = 0; y < n1; y++) {
572-
final double[] b = f[x][y] = Arrays.copyOf(f[x][y], sk);
573+
final double[] b = Arrays.copyOf(f[x][y], sk);
574+
f[x][y] = b;
573575
for (int z = k1; z < sk; z++) {
574576
b[z] = UNSET;
575577
}
@@ -624,7 +626,8 @@ private static double fmnk(double[][][] f, int m, int n, int k) {
624626

625627
// Recursion from formula (3):
626628
// f(m, n, k) = f(m-1, n, k-n) + f(m, n-1, k)
627-
f[m][n][k] = fmnk = fmnk(f, m - 1, n, k - n) + fmnk(f, m, n - 1, k);
629+
fmnk = fmnk(f, m - 1, n, k - n) + fmnk(f, m, n - 1, k);
630+
f[m][n][k] = fmnk;
628631
}
629632
return fmnk;
630633
}

commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/UnconditionedExactTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ private static IntToDoubleFunction createLogBinomialCoefficients(int n) {
10841084
// ignore: binom(n, 0) == binom(n, n) == 1
10851085
int j = n - 1;
10861086
for (int i = 1; i <= j; i++, j--) {
1087-
binom[i] = binom[j] = LogBinomialCoefficient.value(n, i);
1087+
binom[i] = LogBinomialCoefficient.value(n, i);
1088+
binom[j] = binom[i];
10881089
}
10891090
return k -> binom[k];
10901091
}

commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/WilcoxonSignedRankTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ private static double computeCdf(int t, int n) {
640640
// Compute all u_n(t) up to t.
641641
final double[] u = new double[t + 1];
642642
// Initialize u_1(t) using base cases for recursion
643-
u[0] = u[1] = 1;
643+
u[0] = 1;
644+
u[1] = 1;
644645

645646
// Each u_n(t) is created using the current correct values for u_{n-1}(t)
646647
for (int nn = 2; nn < n + 1; nn++) {

commons-statistics-ranking/src/main/java/org/apache/commons/statistics/ranking/NaturalRanking.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ private IntUnaryOperator getRandomIntFunction() {
452452
IntUnaryOperator r = randomIntFunction;
453453
if (r == null) {
454454
// Default to a SplittableRandom
455-
randomIntFunction = r = new SplittableRandom()::nextInt;
455+
r = new SplittableRandom()::nextInt;
456+
randomIntFunction = r;
456457
}
457458
return r;
458459
}

0 commit comments

Comments
 (0)