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:07 UTC
[commons-numbers] 04/19: Fixed checkstyle for arrays.
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 b5fedf92a41dbab2940144ce8bd819d06cbb5cd5
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Nov 8 20:50:54 2019 +0000
Fixed checkstyle for arrays.
---
.../apache/commons/numbers/arrays/CosAngle.java | 2 +-
.../commons/numbers/arrays/LinearCombination.java | 2 +-
.../apache/commons/numbers/arrays/SafeNorm.java | 2 +-
.../commons/numbers/arrays/CosAngleTest.java | 43 +++++++------
.../numbers/arrays/LinearCombinationTest.java | 75 +++++++++++-----------
.../commons/numbers/arrays/SafeNormTest.java | 37 ++++++-----
.../checkstyle/checkstyle-suppressions.xml | 1 +
7 files changed, 86 insertions(+), 76 deletions(-)
diff --git a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/CosAngle.java b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/CosAngle.java
index 5d17b0f..dbddbbc 100644
--- a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/CosAngle.java
+++ b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/CosAngle.java
@@ -19,7 +19,7 @@ package org.apache.commons.numbers.arrays;
/**
* Computes the cosine of the angle between two vectors.
*/
-public class CosAngle {
+public final class CosAngle {
/** Private constructor. */
private CosAngle() {
diff --git a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/LinearCombination.java b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/LinearCombination.java
index aa53abd..052857c 100644
--- a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/LinearCombination.java
+++ b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/LinearCombination.java
@@ -28,7 +28,7 @@ package org.apache.commons.numbers.arrays;
* Accurate Sum and Dot Product</a> by Takeshi Ogita, Siegfried M. Rump,
* and Shin'ichi Oishi published in <em>SIAM J. Sci. Comput</em>.
*/
-public class LinearCombination {
+public final class LinearCombination {
/*
* Caveat:
*
diff --git a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/SafeNorm.java b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/SafeNorm.java
index d62a035..e7fcf7e 100644
--- a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/SafeNorm.java
+++ b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/SafeNorm.java
@@ -21,7 +21,7 @@ package org.apache.commons.numbers.arrays;
* Translation of the <a href="http://www.netlib.org/minpack">minpack</a>
* "enorm" subroutine.
*/
-public class SafeNorm {
+public final class SafeNorm {
/** Constant. */
private static final double R_DWARF = 3.834e-20;
/** Constant. */
diff --git a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/CosAngleTest.java b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/CosAngleTest.java
index 7a7c730..ffef55c 100644
--- a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/CosAngleTest.java
+++ b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/CosAngleTest.java
@@ -1,15 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.commons.numbers.arrays;
@@ -24,24 +27,24 @@ public class CosAngleTest {
public void testCosAngle2D() {
double expected;
- final double[] v1 = { 1, 0 };
+ final double[] v1 = {1, 0};
expected = 1;
Assertions.assertEquals(expected, CosAngle.value(v1, v1), 0d);
- final double[] v2 = { 0, 1 };
+ final double[] v2 = {0, 1};
expected = 0;
Assertions.assertEquals(expected, CosAngle.value(v1, v2), 0d);
- final double[] v3 = { 7, 7 };
+ final double[] v3 = {7, 7};
expected = Math.sqrt(2) / 2;
Assertions.assertEquals(expected, CosAngle.value(v1, v3), 1e-15);
Assertions.assertEquals(expected, CosAngle.value(v3, v2), 1e-15);
- final double[] v4 = { -5, 0 };
+ final double[] v4 = {-5, 0};
expected = -1;
Assertions.assertEquals(expected, CosAngle.value(v1, v4), 0);
- final double[] v5 = { -100, 100 };
+ final double[] v5 = {-100, 100};
expected = 0;
Assertions.assertEquals(expected, CosAngle.value(v3, v5), 0);
}
@@ -50,11 +53,11 @@ public class CosAngleTest {
public void testCosAngle3D() {
double expected;
- final double[] v1 = { 1, 1, 0 };
+ final double[] v1 = {1, 1, 0};
expected = 1;
Assertions.assertEquals(expected, CosAngle.value(v1, v1), 1e-15);
- final double[] v2 = { 1, 1, 1 };
+ final double[] v2 = {1, 1, 1};
expected = Math.sqrt(2) / Math.sqrt(3);
Assertions.assertEquals(expected, CosAngle.value(v1, v2), 1e-15);
}
@@ -64,13 +67,13 @@ public class CosAngleTest {
double expected;
final double tiny = 1e-200;
- final double[] v1 = { tiny, tiny };
+ final double[] v1 = {tiny, tiny};
final double big = 1e200;
- final double[] v2 = { -big, -big };
+ final double[] v2 = {-big, -big};
expected = -1;
Assertions.assertEquals(expected, CosAngle.value(v1, v2), 1e-15);
- final double[] v3 = { big, -big };
+ final double[] v3 = {big, -big};
expected = 0;
Assertions.assertEquals(expected, CosAngle.value(v1, v3), 1e-15);
}
diff --git a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/LinearCombinationTest.java b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/LinearCombinationTest.java
index 5891fbb..6edcb1c 100644
--- a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/LinearCombinationTest.java
+++ b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/LinearCombinationTest.java
@@ -1,15 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.commons.numbers.arrays;
@@ -19,7 +22,7 @@ import org.junit.jupiter.api.Test;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;
import org.apache.commons.numbers.fraction.BigFraction;
-
+
/**
* Test cases for the {@link LinearCombination} class.
*/
@@ -27,14 +30,14 @@ public class LinearCombinationTest {
// MATH-1005
@Test
public void testSingleElementArray() {
- final double[] a = { 1.23456789 };
- final double[] b = { 98765432.1 };
+ final double[] a = {1.23456789};
+ final double[] b = {98765432.1};
Assertions.assertEquals(a[0] * b[0], LinearCombination.value(a, b), 0d);
}
@Test
- public void testTwoSums() {
+ public void testTwoSums() {
final BigFraction[] aF = new BigFraction[] {
BigFraction.of(-1321008684645961L, 268435456L),
BigFraction.of(-5774608829631843L, 268435456L),
@@ -92,20 +95,20 @@ public class LinearCombinationTest {
// One sum.
sInline = LinearCombination.value(u1, v1, u2, v2);
- sArray = LinearCombination.value(new double[] { u1, u2 },
- new double[] { v1, v2 });
+ sArray = LinearCombination.value(new double[] {u1, u2},
+ new double[] {v1, v2});
Assertions.assertEquals(sInline, sArray, 0);
// Two sums.
sInline = LinearCombination.value(u1, v1, u2, v2, u3, v3);
- sArray = LinearCombination.value(new double[] { u1, u2, u3 },
- new double[] { v1, v2, v3 });
+ sArray = LinearCombination.value(new double[] {u1, u2, u3},
+ new double[] {v1, v2, v3});
Assertions.assertEquals(sInline, sArray, 0);
// Three sums.
sInline = LinearCombination.value(u1, v1, u2, v2, u3, v3, u4, v4);
- sArray = LinearCombination.value(new double[] { u1, u2, u3, u4 },
- new double[] { v1, v2, v3, v4 });
+ sArray = LinearCombination.value(new double[] {u1, u2, u3, u4},
+ new double[] {v1, v2, v3, v4});
Assertions.assertEquals(sInline, sArray, 0);
}
}
@@ -146,24 +149,24 @@ public class LinearCombinationTest {
@Test
public void testInfinite() {
final double[][] a = new double[][] {
- { 1, 2, 3, 4 },
- { 1, Double.POSITIVE_INFINITY, 3, 4 },
- { 1, 2, Double.POSITIVE_INFINITY, 4 },
- { 1, Double.POSITIVE_INFINITY, 3, Double.NEGATIVE_INFINITY },
- { 1, 2, 3, 4 },
- { 1, 2, 3, 4 },
- { 1, 2, 3, 4 },
- { 1, 2, 3, 4 }
+ {1, 2, 3, 4},
+ {1, Double.POSITIVE_INFINITY, 3, 4},
+ {1, 2, Double.POSITIVE_INFINITY, 4},
+ {1, Double.POSITIVE_INFINITY, 3, Double.NEGATIVE_INFINITY},
+ {1, 2, 3, 4},
+ {1, 2, 3, 4},
+ {1, 2, 3, 4},
+ {1, 2, 3, 4}
};
final double[][] b = new double[][] {
- { 1, -2, 3, 4 },
- { 1, -2, 3, 4 },
- { 1, -2, 3, 4 },
- { 1, -2, 3, 4 },
- { 1, Double.POSITIVE_INFINITY, 3, 4 },
- { 1, -2, Double.POSITIVE_INFINITY, 4 },
- { 1, Double.POSITIVE_INFINITY, 3, Double.NEGATIVE_INFINITY },
- { Double.NaN, -2, 3, 4 }
+ {1, -2, 3, 4},
+ {1, -2, 3, 4},
+ {1, -2, 3, 4},
+ {1, -2, 3, 4},
+ {1, Double.POSITIVE_INFINITY, 3, 4},
+ {1, -2, Double.POSITIVE_INFINITY, 4},
+ {1, Double.POSITIVE_INFINITY, 3, Double.NEGATIVE_INFINITY},
+ {Double.NaN, -2, 3, 4}
};
Assertions.assertEquals(-3,
diff --git a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
index 4e3d324..294f35c 100644
--- a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
+++ b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/SafeNormTest.java
@@ -1,15 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.commons.numbers.arrays;
@@ -24,34 +27,34 @@ public class SafeNormTest {
@Test
public void testTiny() {
final double s = 1e-320;
- final double[] v = new double[] { s, s };
+ final double[] v = new double[] {s, s};
Assertions.assertEquals(Math.sqrt(2) * s, SafeNorm.value(v), 0d);
}
@Test
public void testBig() {
final double s = 1e300;
- final double[] v = new double[] { s, s };
+ final double[] v = new double[] {s, s};
Assertions.assertEquals(Math.sqrt(2) * s, SafeNorm.value(v), 0d);
}
@Test
public void testOne3D() {
final double s = 1;
- final double[] v = new double[] { s, s, s };
+ final double[] v = new double[] {s, s, s};
Assertions.assertEquals(Math.sqrt(3), SafeNorm.value(v), 0d);
}
@Test
public void testUnit3D() {
- Assertions.assertEquals(1, SafeNorm.value(new double[] { 1, 0, 0 }), 0d);
- Assertions.assertEquals(1, SafeNorm.value(new double[] { 0, 1, 0 }), 0d);
- Assertions.assertEquals(1, SafeNorm.value(new double[] { 0, 0, 1 }), 0d);
+ Assertions.assertEquals(1, SafeNorm.value(new double[] {1, 0, 0}), 0d);
+ Assertions.assertEquals(1, SafeNorm.value(new double[] {0, 1, 0}), 0d);
+ Assertions.assertEquals(1, SafeNorm.value(new double[] {0, 0, 1}), 0d);
}
@Test
public void testSimple() {
- final double[] v = new double[] { -0.9, 8.7, -6.5, -4.3, -2.1, 0, 1.2, 3.4, -5.6, 7.8, 9.0 };
+ final double[] v = new double[] {-0.9, 8.7, -6.5, -4.3, -2.1, 0, 1.2, 3.4, -5.6, 7.8, 9.0};
double n = 0;
for (int i = 0; i < v.length; i++) {
n += v[i] * v[i];
diff --git a/src/main/resources/checkstyle/checkstyle-suppressions.xml b/src/main/resources/checkstyle/checkstyle-suppressions.xml
index 958bc9f..f7dd45a 100644
--- a/src/main/resources/checkstyle/checkstyle-suppressions.xml
+++ b/src/main/resources/checkstyle/checkstyle-suppressions.xml
@@ -20,6 +20,7 @@
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="Indentation" files=".*/combinatorics/Factorial" />
+ <suppress checks="ParameterNumber" files=".*/arrays/LinearCombination" />
<!-- Be more lenient on tests. -->
<suppress checks="Javadoc" files=".*[/\\]test[/\\].*" />