commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-numbers] 03/03: Removed "ComplexParsingException".
Date Thu, 05 Dec 2019 01:48:03 GMT
This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 4cb87cfe9d6b3e899165a5f4bf28b667bed417e0
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
AuthorDate: Thu Dec 5 02:46:37 2019 +0100

    Removed "ComplexParsingException".
    
    It was almost a synonym for the standard "NumberFormatException".
---
 .../apache/commons/numbers/complex/Complex.java    | 38 +++++-----------------
 .../commons/numbers/complex/ComplexTest.java       | 10 +++---
 2 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
index e5b9ca8..ab48a20 100644
--- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
+++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java
@@ -183,31 +183,33 @@ public final class Complex implements Serializable  {
     public static Complex parse(String s) {
         final int startParen = s.indexOf(FORMAT_START);
         if (startParen != 0) {
-            throw new ComplexParsingException("Expected start string: " + FORMAT_START);
+            throw new NumberFormatException("Expected start string: " + FORMAT_START);
         }
         final int len = s.length();
         final int endParen = s.indexOf(FORMAT_END);
         if (endParen != len - 1) {
-            throw new ComplexParsingException("Expected end string: " + FORMAT_END);
+            throw new NumberFormatException("Expected end string: " + FORMAT_END);
         }
         final String[] elements = s.substring(1, s.length() - 1).split(FORMAT_SEP);
         if (elements.length != TWO_ELEMENTS) {
-            throw new ComplexParsingException("Incorrect number of parts: Expected 2 but
was " +
-                                              elements.length +
-                                              " (separator is '" + FORMAT_SEP + "')");
+            throw new NumberFormatException("Incorrect number of parts: Expected 2 but was
" +
+                                            elements.length +
+                                            " (separator is '" + FORMAT_SEP + "')");
         }
 
         final double re;
         try {
             re = Double.parseDouble(elements[0]);
         } catch (final NumberFormatException ex) {
-            throw new ComplexParsingException("Could not parse real part" + elements[0],
ex);
+            throw new NumberFormatException("Could not parse real part (" + elements[0] +
"): " +
+                                            ex.getMessage());
         }
         final double im;
         try {
             im = Double.parseDouble(elements[1]);
         } catch (final NumberFormatException ex) {
-            throw new ComplexParsingException("Could not parse imaginary part" + elements[1],
ex);
+            throw new NumberFormatException("Could not parse imaginary part (" + elements[1]
+ "): " +
+                                            ex.getMessage());
         }
 
         return ofCartesian(re, im);
@@ -1818,26 +1820,4 @@ public final class Complex implements Serializable  {
     private static Complex ofCartesianConjugate(double real, double imaginary) {
         return new Complex(real, -imaginary);
     }
-
-     /** See {@link #parse(String)}. */
-    private static class ComplexParsingException extends NumberFormatException {
-        /** Serializable version identifier. */
-        private static final long serialVersionUID = 20180430L;
-
-        /**
-         * @param msg Error message.
-         */
-        ComplexParsingException(String msg) {
-            super(msg);
-        }
-
-        /**
-         * @param msg Error message.
-         * @param cause Cause.
-         */
-        ComplexParsingException(String msg, Throwable cause) {
-            super(msg);
-            initCause(cause);
-        }
-    }
 }
diff --git a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
index b10f80e..b62a649 100644
--- a/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
+++ b/commons-numbers-complex/src/test/java/org/apache/commons/numbers/complex/ComplexTest.java
@@ -1215,7 +1215,7 @@ public class ComplexTest {
     public void testParseWrongStart() {
         final String re = "1.234";
         final String im = "5.678";
-        Assertions.assertThrows(IllegalArgumentException.class,
+        Assertions.assertThrows(NumberFormatException.class,
             () -> Complex.parse(re + "," + im + ")")
         );
     }
@@ -1224,7 +1224,7 @@ public class ComplexTest {
     public void testParseWrongEnd() {
         final String re = "1.234";
         final String im = "5.678";
-        Assertions.assertThrows(IllegalArgumentException.class,
+        Assertions.assertThrows(NumberFormatException.class,
             () -> Complex.parse("(" + re + "," + im)
         );
     }
@@ -1233,7 +1233,7 @@ public class ComplexTest {
     public void testParseMissingSeparator() {
         final String re = "1.234";
         final String im = "5.678";
-        Assertions.assertThrows(IllegalArgumentException.class,
+        Assertions.assertThrows(NumberFormatException.class,
             () -> Complex.parse("(" + re + " " + im + ")")
         );
     }
@@ -1242,7 +1242,7 @@ public class ComplexTest {
     public void testParseInvalidRe() {
         final String re = "I.234";
         final String im = "5.678";
-        Assertions.assertThrows(IllegalArgumentException.class,
+        Assertions.assertThrows(NumberFormatException.class,
             () -> Complex.parse("(" + re + "," + im + ")")
         );
     }
@@ -1251,7 +1251,7 @@ public class ComplexTest {
     public void testParseInvalidIm() {
         final String re = "1.234";
         final String im = "5.G78";
-        Assertions.assertThrows(IllegalArgumentException.class,
+        Assertions.assertThrows(NumberFormatException.class,
             () -> Complex.parse("(" + re + "," + im + ")")
         );
     }


Mime
View raw message