Skip to content

Commit ff9062c

Browse files
authored
Merge pull request #132 from cicirello/code-improvements
Resolved warnings generated by initial run of MuseDev static analysis
2 parents 5e9d106 + dccb000 commit ff9062c

File tree

8 files changed

+51
-32
lines changed

8 files changed

+51
-32
lines changed

.muse.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# don't run eslint... it is for js and will detect false positives
2+
# in javadoc directories.
3+
4+
disableTools = ["eslint"]
5+
6+
# Ignore warnings not relevant to this specific project:
7+
#
8+
# 1) FindSecBugs identifies our use of ThreadLocalRandom as predictable.
9+
# We make extensive use of this class for randomness. Our use of randomness
10+
# in this library is NOT at all security related, and rather, we simply need
11+
# a fast pseudorandom number generator since we need to generate large
12+
# numbers of random numbers. So ignore predictable random warnings.
13+
14+
ignore = ["PREDICTABLE_RANDOM"]
15+
16+
# Ignore results from these directories
17+
18+
ignoreFiles = """
19+
docs/api/jquery/
20+
tests/
21+
"""

src/org/cicirello/math/MathFunctions.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* MathFunctions is a class of utility methods that implement various mathematical functions.
2727
*
2828
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
29-
* @version 2.12.2021
29+
* @version 5.13.2021
3030
*
3131
*/
3232
public final class MathFunctions {
@@ -92,7 +92,7 @@ public static double logGamma(double n) {
9292
// This check doesn't seem to be necessary given addition of first check in block.
9393
// if (z == 0.0) return Double.POSITIVE_INFINITY;
9494
// ln(PI)
95-
final double LOG_PI = 1.14472988584940017414;
95+
final double LOG_PI = 1.1447298858494002;
9696
return LOG_PI - Math.log(z) - logGamma(n);
9797
} else if (n < 13.0) {
9898
double z = 1.0;
@@ -117,13 +117,13 @@ public static double logGamma(double n) {
117117
n * evaluatePolynomial(n, POLY_APPROX_2) / evaluatePolynomial(n, POLY_APPROX_3);
118118
} else {
119119
// ln(sqrt(2pi))
120-
final double LOG_SQRT_PI2 = 0.91893853320467274178;
120+
final double LOG_SQRT_PI2 = 0.9189385332046727;
121121
double q = (n - 0.5) * Math.log(n) - n + LOG_SQRT_PI2;
122122
if (n > 1.0e8) return q;
123123
double p = 1.0 / (n * n);
124124
if (n >= 1000.0) {
125-
q = q + ((7.9365079365079365079365e-4 * p - 2.7777777777777777777778e-3)
126-
* p + 0.0833333333333333333333) / n;
125+
q = q + ((7.936507936507937E-4 * p - 0.002777777777777778)
126+
* p + 0.08333333333333333) / n;
127127
} else {
128128
q += evaluatePolynomial(p, STIRLING_EXPANSION_LN_GAMMA) / n;
129129
}
@@ -142,21 +142,22 @@ private static double evaluatePolynomial(double x, double polynomial[]) {
142142
}
143143

144144
private static final double[] STIRLING_EXPANSION_LN_GAMMA = {
145-
8.11614167470508450300E-4, -5.95061904284301438324E-4,
146-
7.93650340457716943945E-4, -2.77777777730099687205E-3,
147-
8.33333333333331927722E-2
145+
8.116141674705085E-4, -5.950619042843014E-4,
146+
7.936503404577169E-4, -0.002777777777300997,
147+
0.08333333333333319
148148
};
149149

150150
private static final double[] POLY_APPROX_2 = {
151-
-1.37825152569120859100E3, -3.88016315134637840924E4,
152-
-3.31612992738871184744E5, -1.16237097492762307383E6,
153-
-1.72173700820839662146E6, -8.53555664245765465627E5
151+
-1378.2515256912086, -38801.631513463784,
152+
-331612.9927388712, -1162370.974927623,
153+
-1721737.0082083966, -853555.6642457654
154154
};
155155

156156
private static final double[] POLY_APPROX_3 = {
157-
1.0, -3.51815701436523470549E2, -1.70642106651881159223E4,
158-
-2.20528590553854454839E5, -1.13933444367982507207E6,
159-
-2.53252307177582951285E6, -2.01889141433532773231E6
157+
1.0,
158+
-351.81570143652345, -17064.210665188115,
159+
-220528.59055385445, -1139334.4436798252,
160+
-2532523.0717758294, -2018891.4143353277,
160161
};
161162

162163
// HELPERS FOR logGamma END HERE

src/org/cicirello/math/la/MatrixOps.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* represented as 2-D Java arrays.
2828
*
2929
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
30-
* @version 2.13.2021
30+
* @version 5.13.2021
3131
*/
3232
public final class MatrixOps {
3333

@@ -235,7 +235,7 @@ public static double[][] difference(double[][] A, double[][] B) {
235235
* @return A reference to the C matrix.
236236
*/
237237
public static int[][] product(int[][] A, int[][] B, int[][] C) {
238-
if (A.length == 0 && B.length > 0 || A.length > 0 && B.length == 0) {
238+
if ((A.length == 0 && B.length > 0) || (A.length > 0 && B.length == 0)) {
239239
throw new IllegalArgumentException("If either matrix has 0 rows, both must.");
240240
} else if (A.length == 0) {
241241
if (C==null) return new int[0][0];
@@ -267,7 +267,7 @@ public static int[][] product(int[][] A, int[][] B, int[][] C) {
267267
* @return A reference to the C matrix.
268268
*/
269269
public static double[][] product(double[][] A, double[][] B, double[][] C) {
270-
if (A.length == 0 && B.length > 0 || A.length > 0 && B.length == 0) {
270+
if ((A.length == 0 && B.length > 0) || (A.length > 0 && B.length == 0)) {
271271
throw new IllegalArgumentException("If either matrix has 0 rows, both must.");
272272
} else if (A.length == 0) {
273273
if (C==null) return new double[0][0];

src/org/cicirello/math/rand/RandomIndexer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* from the motivating case, the case of efficiently generating random indexes into an array.
3434
*
3535
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
36-
* @version 2.13.2021
36+
* @version 5.13.2021
3737
*
3838
*/
3939
public final class RandomIndexer {
@@ -152,7 +152,7 @@ public static int nextInt(int bound, Random gen) {
152152
*/
153153
public static int nextBiasedInt(int bound) {
154154
if (bound < 1) throw new IllegalArgumentException("bound must be positive");
155-
return (int)((long)(ThreadLocalRandom.current().nextInt() & 0x7fffffff) * (long)bound >> 31);
155+
return (int)(((long)(ThreadLocalRandom.current().nextInt() & 0x7fffffff) * (long)bound) >> 31);
156156
}
157157

158158
/**
@@ -178,7 +178,7 @@ public static int nextBiasedInt(int bound) {
178178
*/
179179
public static int nextBiasedInt(int bound, SplittableRandom gen) {
180180
if (bound < 1) throw new IllegalArgumentException("bound must be positive");
181-
return (int)((long)(gen.nextInt() & 0x7fffffff) * (long)bound >> 31);
181+
return (int)(((long)(gen.nextInt() & 0x7fffffff) * (long)bound) >> 31);
182182
}
183183

184184
/**
@@ -211,7 +211,7 @@ public static int nextBiasedInt(int bound, SplittableRandom gen) {
211211
*/
212212
public static int nextBiasedInt(int bound, Random gen) {
213213
if (bound < 1) throw new IllegalArgumentException("bound must be positive");
214-
return (int)((long)(gen.nextInt() & 0x7fffffff) * (long)bound >> 31);
214+
return (int)(((long)(gen.nextInt() & 0x7fffffff) * (long)bound) >> 31);
215215
}
216216

217217

src/org/cicirello/math/stats/Statistics.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2020 Vincent A. Cicirello, <https://www.cicirello.org/>.
2+
* Copyright 2018-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
33
*
44
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
55
*
@@ -26,7 +26,7 @@
2626
* Utility class of basic statistics.
2727
*
2828
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
29-
* @version 09-18-2020
29+
* @version 5.13.2021
3030
*/
3131
public final class Statistics {
3232

@@ -39,11 +39,9 @@ private Statistics() {}
3939
* @return the mean of the data.
4040
*/
4141
public static double mean(int[] data) {
42-
double mean = 0;
4342
int sum = 0;
4443
for (int e : data) sum = sum + e;
45-
mean = 1.0 * sum / data.length;
46-
return mean;
44+
return 1.0 * sum / data.length;
4745
}
4846

4947
/**

src/org/cicirello/permutations/distance/KendallTauDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* M. G. Kendall, "A new measure of rank correlation," Biometrika, vol. 30, no. 1/2, pp. 81–93, June 1938.</p>
4949
*
5050
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
51-
* @version 4.2.2021
51+
* @version 5.13.2021
5252
*
5353
*/
5454
public final class KendallTauDistance implements NormalizedPermutationDistanceMeasurer {
@@ -83,7 +83,7 @@ public int distance(Permutation p1, Permutation p2) {
8383
@Override
8484
public int max(int length) {
8585
if (length <= 1) return 0;
86-
return length*(length - 1)>>1;
86+
return (length*(length - 1))>>1;
8787
}
8888

8989
private int countInversions(int[] array) {

src/org/cicirello/permutations/distance/ReversalDistance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* <p>We have not used this for N &gt; 10. Warning: time to construct distance measure increases factorially.</p>
4949
*
5050
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
51-
* @version 4.2.2021
51+
* @version 5.13.2021
5252
*/
5353
public final class ReversalDistance implements NormalizedPermutationDistanceMeasurer {
5454

@@ -128,7 +128,7 @@ public int distance(Permutation p1, Permutation p2) {
128128
for (int i = 0; i < inv1.length; i++) {
129129
r2[i] = inv1[p2.get(i)];
130130
}
131-
return dist[(new Permutation(r2)).toInteger()];
131+
return dist[new Permutation(r2).toInteger()];
132132
}
133133

134134
/**

src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
package org.cicirello.sequences.distance;
2222

23-
2423
import java.util.Arrays;
2524
import java.util.HashMap;
2625
import java.util.List;
@@ -77,7 +76,7 @@
7776
* Industrial Networks and Intelligent Systems, 7(23), Article e1, April 2020.</p>
7877
*
7978
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
80-
* @version 4.2.2021
79+
* @version 5.13.2021
8180
*/
8281
public final class KendallTauSequenceDistance implements SequenceDistanceMeasurer {
8382

0 commit comments

Comments
 (0)