From bb90869d6ea70841ee156617acd41f11da9c9684 Mon Sep 17 00:00:00 2001
From: "Vincent A. Cicirello"
Date: Thu, 13 May 2021 13:26:15 -0400
Subject: [PATCH 01/10] Create .muse.toml
#131
---
.muse.toml | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 .muse.toml
diff --git a/.muse.toml b/.muse.toml
new file mode 100644
index 00000000..72d0f660
--- /dev/null
+++ b/.muse.toml
@@ -0,0 +1,21 @@
+# don't run eslint... it is for js and will detect false positives
+# in javadoc directories.
+
+disableTools = ["eslint"]
+
+# Ignore warnings not relevant to this specific project:
+#
+# 1) FindSecBugs identifies our use of ThreadLocalRandom as predictable.
+# We make extensive use of this class for randomness. Our use of randomness
+# in this library is NOT at all security related, and rather, we simply need
+# a fast pseudorandom number generator since we need to generate large
+# numbers of random numbers. So ignore predictable random warnings.
+
+ignore = ["PREDICTABLE_RANDOM"]
+
+# Ignore results from these directories
+
+ignoreFiles = """
+docs/api/jquery/
+tests/
+"""
\ No newline at end of file
From f1e83b00c73a26d1c3699f57d4bcb51730620595 Mon Sep 17 00:00:00 2001
From: "Vincent A. Cicirello"
Date: Thu, 13 May 2021 13:30:11 -0400
Subject: [PATCH 02/10] removed unused variable
#131
---
src/org/cicirello/math/stats/Statistics.java | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/org/cicirello/math/stats/Statistics.java b/src/org/cicirello/math/stats/Statistics.java
index 7076ea61..7e81ab05 100644
--- a/src/org/cicirello/math/stats/Statistics.java
+++ b/src/org/cicirello/math/stats/Statistics.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2020 Vincent A. Cicirello, .
+ * Copyright 2018-2021 Vincent A. Cicirello, .
*
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
*
@@ -26,7 +26,7 @@
* Utility class of basic statistics.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
- * @version 09-18-2020
+ * @version 5.13.2021
*/
public final class Statistics {
@@ -39,11 +39,9 @@ private Statistics() {}
* @return the mean of the data.
*/
public static double mean(int[] data) {
- double mean = 0;
int sum = 0;
for (int e : data) sum = sum + e;
- mean = 1.0 * sum / data.length;
- return mean;
+ return 1.0 * sum / data.length;
}
/**
From fdba1bd2bc217ddd10a38f2db4dbb127ed693767 Mon Sep 17 00:00:00 2001
From: "Vincent A. Cicirello"
Date: Thu, 13 May 2021 13:41:47 -0400
Subject: [PATCH 03/10] explicitly used parens in place of implicit order of
ops
#131
---
src/org/cicirello/math/la/MatrixOps.java | 6 +++---
src/org/cicirello/math/rand/RandomIndexer.java | 8 ++++----
.../permutations/distance/KendallTauDistance.java | 4 ++--
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/org/cicirello/math/la/MatrixOps.java b/src/org/cicirello/math/la/MatrixOps.java
index 7d79f692..25af34b3 100644
--- a/src/org/cicirello/math/la/MatrixOps.java
+++ b/src/org/cicirello/math/la/MatrixOps.java
@@ -27,7 +27,7 @@
* represented as 2-D Java arrays.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
- * @version 2.13.2021
+ * @version 5.13.2021
*/
public final class MatrixOps {
@@ -235,7 +235,7 @@ public static double[][] difference(double[][] A, double[][] B) {
* @return A reference to the C matrix.
*/
public static int[][] product(int[][] A, int[][] B, int[][] C) {
- if (A.length == 0 && B.length > 0 || A.length > 0 && B.length == 0) {
+ if ((A.length == 0 && B.length > 0) || (A.length > 0 && B.length == 0)) {
throw new IllegalArgumentException("If either matrix has 0 rows, both must.");
} else if (A.length == 0) {
if (C==null) return new int[0][0];
@@ -267,7 +267,7 @@ public static int[][] product(int[][] A, int[][] B, int[][] C) {
* @return A reference to the C matrix.
*/
public static double[][] product(double[][] A, double[][] B, double[][] C) {
- if (A.length == 0 && B.length > 0 || A.length > 0 && B.length == 0) {
+ if ((A.length == 0 && B.length > 0) || (A.length > 0 && B.length == 0)) {
throw new IllegalArgumentException("If either matrix has 0 rows, both must.");
} else if (A.length == 0) {
if (C==null) return new double[0][0];
diff --git a/src/org/cicirello/math/rand/RandomIndexer.java b/src/org/cicirello/math/rand/RandomIndexer.java
index d20627a4..11d69060 100644
--- a/src/org/cicirello/math/rand/RandomIndexer.java
+++ b/src/org/cicirello/math/rand/RandomIndexer.java
@@ -33,7 +33,7 @@
* from the motivating case, the case of efficiently generating random indexes into an array.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
- * @version 2.13.2021
+ * @version 5.13.2021
*
*/
public final class RandomIndexer {
@@ -152,7 +152,7 @@ public static int nextInt(int bound, Random gen) {
*/
public static int nextBiasedInt(int bound) {
if (bound < 1) throw new IllegalArgumentException("bound must be positive");
- return (int)((long)(ThreadLocalRandom.current().nextInt() & 0x7fffffff) * (long)bound >> 31);
+ return (int)(((long)(ThreadLocalRandom.current().nextInt() & 0x7fffffff) * (long)bound) >> 31);
}
/**
@@ -178,7 +178,7 @@ public static int nextBiasedInt(int bound) {
*/
public static int nextBiasedInt(int bound, SplittableRandom gen) {
if (bound < 1) throw new IllegalArgumentException("bound must be positive");
- return (int)((long)(gen.nextInt() & 0x7fffffff) * (long)bound >> 31);
+ return (int)(((long)(gen.nextInt() & 0x7fffffff) * (long)bound) >> 31);
}
/**
@@ -211,7 +211,7 @@ public static int nextBiasedInt(int bound, SplittableRandom gen) {
*/
public static int nextBiasedInt(int bound, Random gen) {
if (bound < 1) throw new IllegalArgumentException("bound must be positive");
- return (int)((long)(gen.nextInt() & 0x7fffffff) * (long)bound >> 31);
+ return (int)(((long)(gen.nextInt() & 0x7fffffff) * (long)bound) >> 31);
}
diff --git a/src/org/cicirello/permutations/distance/KendallTauDistance.java b/src/org/cicirello/permutations/distance/KendallTauDistance.java
index 49ed5899..1233801c 100644
--- a/src/org/cicirello/permutations/distance/KendallTauDistance.java
+++ b/src/org/cicirello/permutations/distance/KendallTauDistance.java
@@ -48,7 +48,7 @@
* M. G. Kendall, "A new measure of rank correlation," Biometrika, vol. 30, no. 1/2, pp. 81–93, June 1938.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
- * @version 4.2.2021
+ * @version 5.13.2021
*
*/
public final class KendallTauDistance implements NormalizedPermutationDistanceMeasurer {
@@ -83,7 +83,7 @@ public int distance(Permutation p1, Permutation p2) {
@Override
public int max(int length) {
if (length <= 1) return 0;
- return length*(length - 1)>>1;
+ return (length*(length - 1))>>1;
}
private int countInversions(int[] array) {
From 5fa6964a73cedcb696901918ce529b7094e74501 Mon Sep 17 00:00:00 2001
From: "Vincent A. Cicirello"
Date: Thu, 13 May 2021 13:45:14 -0400
Subject: [PATCH 04/10] removed unneeded parens
#131
---
src/org/cicirello/permutations/distance/ReversalDistance.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/org/cicirello/permutations/distance/ReversalDistance.java b/src/org/cicirello/permutations/distance/ReversalDistance.java
index 8c8b5610..93676ce5 100644
--- a/src/org/cicirello/permutations/distance/ReversalDistance.java
+++ b/src/org/cicirello/permutations/distance/ReversalDistance.java
@@ -48,7 +48,7 @@
*
We have not used this for N > 10. Warning: time to construct distance measure increases factorially.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
-* @version 4.2.2021
+* @version 5.13.2021
*/
public final class ReversalDistance implements NormalizedPermutationDistanceMeasurer {
@@ -128,7 +128,7 @@ public int distance(Permutation p1, Permutation p2) {
for (int i = 0; i < inv1.length; i++) {
r2[i] = inv1[p2.get(i)];
}
- return dist[(new Permutation(r2)).toInteger()];
+ return dist[new Permutation(r2).toInteger()];
}
/**
From ebcb724055fdaed555ca172b5a84154550bc8d97 Mon Sep 17 00:00:00 2001
From: "Vincent A. Cicirello"
Date: Thu, 13 May 2021 13:58:06 -0400
Subject: [PATCH 05/10] Suppress false positives from Infer
#131
---
.../sequences/distance/KendallTauSequenceDistance.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java b/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java
index ab79aa45..6fb6d056 100644
--- a/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java
+++ b/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java
@@ -77,7 +77,7 @@
* Industrial Networks and Intelligent Systems, 7(23), Article e1, April 2020.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
- * @version 4.2.2021
+ * @version 5.13.2021
*/
public final class KendallTauSequenceDistance implements SequenceDistanceMeasurer {
@@ -333,6 +333,7 @@ private Bucket[][] bucketSortElements(int[][] relabeling, int numLabels) {
}
private int relabelElementsWithHash(Object[] s1, Object[] s2, int[][] relabeling) {
+ @SuppressWarnings("NULL_DEREFERENCE")
HashMap