commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] branch master updated: Fixed checkstyle issues.
Date Mon, 16 Dec 2019 23:46:57 GMT
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


The following commit(s) were added to refs/heads/master by this push:
     new 18cb0db  Fixed checkstyle issues.
18cb0db is described below

commit 18cb0dbf90799be8157eb97f7fcc1b9271894c54
Author: Alex Herbert <aherbert@apache.org>
AuthorDate: Mon Dec 16 23:46:53 2019 +0000

    Fixed checkstyle issues.
---
 .../numbers/arrays/MultidimensionalCounter.java    | 31 +++++++++-----
 .../arrays/MultidimensionalCounterTest.java        | 50 +++++++++++-----------
 2 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/MultidimensionalCounter.java
b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/MultidimensionalCounter.java
index bf30849..301a0b1 100644
--- a/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/MultidimensionalCounter.java
+++ b/commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays/MultidimensionalCounter.java
@@ -38,7 +38,7 @@ import java.util.Arrays;
  *  <li>(1, 3, 2) corresponds to 23</li>
  * </ul>
  */
-public class MultidimensionalCounter {
+public final class MultidimensionalCounter {
     /**
      * Number of dimensions.
      */
@@ -67,13 +67,13 @@ public class MultidimensionalCounter {
      * @throws IllegalArgumentException if one of the sizes is negative
      * or zero.
      */
-    private MultidimensionalCounter(int ... size) {
+    private MultidimensionalCounter(int... size) {
         dimension = size.length;
         this.size = Arrays.copyOf(size, size.length);
 
         uniCounterOffset = new int[dimension];
 
-        last = dimension - 1; 
+        last = dimension - 1;
         uniCounterOffset[last] = 1;
 
         int tS = 1;
@@ -97,7 +97,7 @@ public class MultidimensionalCounter {
      * @throws IllegalArgumentException if one of the sizes is negative
      * or zero.
      */
-    public static MultidimensionalCounter of(int ... size) {
+    public static MultidimensionalCounter of(int... size) {
         return new MultidimensionalCounter(size);
     }
 
@@ -111,7 +111,7 @@ public class MultidimensionalCounter {
     }
 
     /**
-     * Converts to multidimensional counter.
+     * Converts to a multidimensional counter.
      *
      * @param index Index in unidimensional counter.
      * @return the multidimensional counts.
@@ -121,7 +121,7 @@ public class MultidimensionalCounter {
     public int[] toMulti(int index) {
         if (index < 0 ||
             index >= totalSize) {
-            throw new IndexOutOfBoundsException("Index out of bounds [0, " + (totalSize -
1) + "]: " + index);
+            throw new IndexOutOfBoundsException(createIndexOutOfBoundsMessage(totalSize,
index));
         }
 
         final int[] indices = new int[dimension];
@@ -145,7 +145,7 @@ public class MultidimensionalCounter {
     }
 
     /**
-     * Converts to unidimensional counter.
+     * Converts to a unidimensional counter.
      *
      * @param c Indices in multidimensional counter.
      * @return the index within the unidimensionl counter.
@@ -153,9 +153,9 @@ public class MultidimensionalCounter {
      * does not match the size of the array given in the constructor.
      * @throws IndexOutOfBoundsException if a value of {@code c} is not in
      * the range of the corresponding dimension, as defined in the
-     * {@link MultidimensionalCounter#MultidimensionalCounter(int...) constructor}.
+     * {@link MultidimensionalCounter#of(int...) constructor}.
      */
-    public int toUni(int ... c) {
+    public int toUni(int... c) {
         if (c.length != dimension) {
             throw new IllegalArgumentException("Wrong number of arguments: " + c.length +
                                                "(expected: " + dimension + ")");
@@ -165,7 +165,7 @@ public class MultidimensionalCounter {
             final int index = c[i];
             if (index < 0 ||
                 index >= size[i]) {
-                throw new IndexOutOfBoundsException("Index out of bounds [0, " + (size[i]
- 1) + "]: " + index);
+                throw new IndexOutOfBoundsException(createIndexOutOfBoundsMessage(size[i],
index));
             }
             count += uniCounterOffset[i] * index;
         }
@@ -195,4 +195,15 @@ public class MultidimensionalCounter {
     public String toString() {
         return Arrays.toString(size);
     }
+
+    /**
+     * Creates the message for the index out of bounds exception.
+     *
+     * @param size the size
+     * @param index the index
+     * @return the message
+     */
+    private static String createIndexOutOfBoundsMessage(int size, int index) {
+        return "Index out of bounds [0, " + (size - 1) + "]: " + index;
+    }
 }
diff --git a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/MultidimensionalCounterTest.java
b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/MultidimensionalCounterTest.java
index 746cfeb..c9730fc 100644
--- a/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/MultidimensionalCounterTest.java
+++ b/commons-numbers-arrays/src/test/java/org/apache/commons/numbers/arrays/MultidimensionalCounterTest.java
@@ -109,30 +109,30 @@ public class MultidimensionalCounterTest {
     public void testIterationConsistency() {
         final MultidimensionalCounter c = MultidimensionalCounter.of(2, 3, 4);
         final int[][] expected = new int[][] {
-            { 0, 0, 0 },
-            { 0, 0, 1 },
-            { 0, 0, 2 },
-            { 0, 0, 3 },
-            { 0, 1, 0 },
-            { 0, 1, 1 },
-            { 0, 1, 2 },
-            { 0, 1, 3 },
-            { 0, 2, 0 },
-            { 0, 2, 1 },
-            { 0, 2, 2 },
-            { 0, 2, 3 },
-            { 1, 0, 0 },
-            { 1, 0, 1 },
-            { 1, 0, 2 },
-            { 1, 0, 3 },
-            { 1, 1, 0 },
-            { 1, 1, 1 },
-            { 1, 1, 2 },
-            { 1, 1, 3 },
-            { 1, 2, 0 },
-            { 1, 2, 1 },
-            { 1, 2, 2 },
-            { 1, 2, 3 }
+            {0, 0, 0},
+            {0, 0, 1},
+            {0, 0, 2},
+            {0, 0, 3},
+            {0, 1, 0},
+            {0, 1, 1},
+            {0, 1, 2},
+            {0, 1, 3},
+            {0, 2, 0},
+            {0, 2, 1},
+            {0, 2, 2},
+            {0, 2, 3},
+            {1, 0, 0},
+            {1, 0, 1},
+            {1, 0, 2},
+            {1, 0, 3},
+            {1, 1, 0},
+            {1, 1, 1},
+            {1, 1, 2},
+            {1, 1, 3},
+            {1, 2, 0},
+            {1, 2, 1},
+            {1, 2, 2},
+            {1, 2, 3}
         };
 
         final int totalSize = c.getSize();
@@ -153,7 +153,7 @@ public class MultidimensionalCounterTest {
 
     @Test
     public void testToString() {
-        final int[] sizes = new int[] { 7, 5, 3, 1 };
+        final int[] sizes = new int[] {7, 5, 3, 1};
         final MultidimensionalCounter c = MultidimensionalCounter.of(sizes);
         Assertions.assertEquals(Arrays.toString(sizes), c.toString());
     }


Mime
View raw message