You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2018/11/30 14:00:23 UTC

[3/8] commons-numbers git commit: NUMBERS-76 Make "Quaternion" a VALJO - Fix Checkstyle issues

NUMBERS-76 Make "Quaternion" a VALJO - Fix Checkstyle issues


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e9e0164f
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e9e0164f
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e9e0164f

Branch: refs/heads/master
Commit: e9e0164fbb9676034a6c3597d2e63d2505295346
Parents: 2f33d38
Author: Steve Bosman <St...@gmail.com>
Authored: Fri Nov 30 00:28:19 2018 +0000
Committer: Steve Bosman <St...@gmail.com>
Committed: Fri Nov 30 00:28:19 2018 +0000

----------------------------------------------------------------------
 .../commons/numbers/quaternion/Quaternion.java  | 79 ++++++++++----------
 1 file changed, 41 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e9e0164f/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
----------------------------------------------------------------------
diff --git a/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java b/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
index 5007ef4..785b7e0 100644
--- a/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
+++ b/commons-numbers-quaternion/src/main/java/org/apache/commons/numbers/quaternion/Quaternion.java
@@ -61,11 +61,14 @@ public final class Quaternion implements Serializable {
      * @param c Second vector component.
      * @param d Third vector component.
      */
-    public static Quaternion of(final double a,
-                                final double b,
-                                final double c,
-                                final double d) {
-        return new Quaternion(a, b, c, d);
+    private Quaternion(final double a,
+                      final double b,
+                      final double c,
+                      final double d) {
+        q0 = a;
+        q1 = b;
+        q2 = c;
+        q3 = d;
     }
 
     /**
@@ -76,19 +79,16 @@ public final class Quaternion implements Serializable {
      *
      * @throws IllegalArgumentException if the array length is not 3.
      */
-    public static Quaternion of(final double scalar,
-                                final double[] v) {
-        return new Quaternion(scalar, v);
-    }
+    private Quaternion(final double scalar,
+                      final double[] v) {
+        if (v.length != 3) {
+            throw new IllegalArgumentException("Size of array must be 3");
+        }
 
-    /**
-     * Builds a pure quaternion from a vector (assuming that the scalar
-     * part is zero).
-     *
-     * @param v Components of the vector part of the pure quaternion.
-     */
-    public static Quaternion of(final double[] v) {
-        return new Quaternion(0, v);
+        q0 = scalar;
+        q1 = v[0];
+        q2 = v[1];
+        q3 = v[2];
     }
 
     /**
@@ -98,15 +98,13 @@ public final class Quaternion implements Serializable {
      * @param b First vector component.
      * @param c Second vector component.
      * @param d Third vector component.
+     * @return a quaternion instance
      */
-    private Quaternion(final double a,
-                      final double b,
-                      final double c,
-                      final double d) {
-        q0 = a;
-        q1 = b;
-        q2 = c;
-        q3 = d;
+    public static Quaternion of(final double a,
+                                final double b,
+                                final double c,
+                                final double d) {
+        return new Quaternion(a, b, c, d);
     }
 
     /**
@@ -114,19 +112,24 @@ public final class Quaternion implements Serializable {
      *
      * @param scalar Scalar part of the quaternion.
      * @param v Components of the vector part of the quaternion.
+     * @return a quaternion instance
      *
      * @throws IllegalArgumentException if the array length is not 3.
      */
-    private Quaternion(final double scalar,
-                      final double[] v) {
-        if (v.length != 3) {
-            throw new IllegalArgumentException("Size of array must be 3");
-        }
+    public static Quaternion of(final double scalar,
+                                final double[] v) {
+        return new Quaternion(scalar, v);
+    }
 
-        q0 = scalar;
-        q1 = v[0];
-        q2 = v[1];
-        q3 = v[2];
+    /**
+     * Builds a pure quaternion from a vector (assuming that the scalar
+     * part is zero).
+     *
+     * @param v Components of the vector part of the pure quaternion.
+     * @return a quaternion instance
+     */
+    public static Quaternion of(final double[] v) {
+        return new Quaternion(0, v);
     }
 
     /**
@@ -511,25 +514,25 @@ public final class Quaternion implements Serializable {
         final double q1;
         try {
             q1 = Double.parseDouble(elements[0]);
-        } catch (Exception ex) {
+        } catch (NumberFormatException ex) {
             throw new QuaternionParsingException("Could not parse scalar part" + elements[0]);
         }
         final double q2;
         try {
             q2 = Double.parseDouble(elements[1]);
-        } catch (Exception ex) {
+        } catch (NumberFormatException ex) {
             throw new QuaternionParsingException("Could not parse i part" + elements[1]);
         }
         final double q3;
         try {
             q3 = Double.parseDouble(elements[2]);
-        } catch (Exception ex) {
+        } catch (NumberFormatException ex) {
             throw new QuaternionParsingException("Could not parse j part" + elements[2]);
         }
         final double q4;
         try {
             q4 = Double.parseDouble(elements[3]);
-        } catch (Exception ex) {
+        } catch (NumberFormatException ex) {
             throw new QuaternionParsingException("Could not parse k part" + elements[3]);
         }