commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raydeca...@apache.org
Subject [09/13] commons-numbers git commit: NUMBERS-6: Remove specialized exception from public API (contd). FractionParseException becomes package private and inherits from java.text.ParseException.
Date Mon, 06 Feb 2017 12:52:30 GMT
NUMBERS-6: Remove specialized exception from public API (contd).
FractionParseException becomes package private and inherits from java.text.ParseException.


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

Branch: refs/heads/master
Commit: ec826b0fc1ae6d731d3b848cf9f60f676c4bc261
Parents: 41e2f65
Author: Ray DeCampo <ray@decampo.org>
Authored: Tue Jan 31 20:26:59 2017 -0500
Committer: Ray DeCampo <ray@decampo.org>
Committed: Tue Jan 31 20:26:59 2017 -0500

----------------------------------------------------------------------
 .../numbers/fraction/BigFractionFormat.java      |  5 +++--
 .../commons/numbers/fraction/Fraction.java       |  4 ++--
 .../numbers/fraction/FractionException.java      | 17 ++++++++++++++++-
 .../commons/numbers/fraction/FractionFormat.java |  5 +++--
 .../numbers/fraction/FractionParseException.java |  2 +-
 .../numbers/fraction/BigFractionFormatTest.java  | 17 +++++++++--------
 .../numbers/fraction/FractionFormatTest.java     | 19 ++++++++++---------
 7 files changed, 44 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java
b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java
index aca674c..822e6a2 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
 import java.math.BigInteger;
 import java.text.FieldPosition;
 import java.text.NumberFormat;
+import java.text.ParseException;
 import java.text.ParsePosition;
 import java.util.Locale;
 
@@ -177,11 +178,11 @@ public class BigFractionFormat extends AbstractFormat implements Serializable
{
      * Parses a string to produce a {@link BigFraction} object.
      * @param source the string to parse
      * @return the parsed {@link BigFraction} object.
-     * @exception FractionParseException if the beginning of the specified string
+     * @exception ParseException if the beginning of the specified string
      *            cannot be parsed.
      */
     @Override
-    public BigFraction parse(final String source) throws FractionParseException {
+    public BigFraction parse(final String source) throws ParseException {
         final ParsePosition parsePosition = new ParsePosition(0);
         final BigFraction result = parse(source, parsePosition);
         if (parsePosition.getIndex() == 0) {

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
index 31abd17..bfd7734 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
@@ -257,7 +257,7 @@ public class Fraction
         if (den < 0) {
             if (num == Integer.MIN_VALUE ||
                 den == Integer.MIN_VALUE) {
-                throw new FractionException("overflow in fraction {0}/{1}, cannot negate",
num, den);
+                throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, num,
den);
             }
             num = -num;
             den = -den;
@@ -617,7 +617,7 @@ public class Fraction
         if (denominator < 0) {
             if (numerator==Integer.MIN_VALUE ||
                     denominator==Integer.MIN_VALUE) {
-                throw new FractionException("overflow in fraction {0}/{1}, cannot negate",
numerator, denominator);
+                throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, numerator,
denominator);
             }
             numerator = -numerator;
             denominator = -denominator;

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
index d5fb6df..c2283ad 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
@@ -16,8 +16,10 @@
  */
 package org.apache.commons.numbers.fraction;
 
+import java.text.MessageFormat;
+
 /**
- * Base class for all exceptions thrown in the module.
+ * Package private exception class with constants for frequently used messages.
  */
 class FractionException extends ArithmeticException {
 
@@ -34,9 +36,22 @@ class FractionException extends ArithmeticException {
     public FractionException() {
     }
 
+    /**
+     * Create an exception where the message is constructed by applying
+     * the {@code format()} method from {@code java.text.MessageFormat}.
+     *
+     * @param message  the exception message with replaceable parameters
+     * @param formatArguments the arguments for formatting the message
+     */
     public FractionException(String message, Object... formatArguments) {
         super(message);
         this.formatArguments = formatArguments;
     }
 
+    @Override
+    public String getMessage() {
+        return MessageFormat.format(super.getMessage(), formatArguments);
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
index be6c8a2..cc34cac 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
@@ -19,6 +19,7 @@ package org.apache.commons.numbers.fraction;
 
 import java.text.FieldPosition;
 import java.text.NumberFormat;
+import java.text.ParseException;
 import java.text.ParsePosition;
 import java.util.Locale;
 
@@ -183,11 +184,11 @@ public class FractionFormat extends AbstractFormat {
      * Parses a string to produce a {@link Fraction} object.
      * @param source the string to parse
      * @return the parsed {@link Fraction} object.
-     * @exception FractionParseException if the beginning of the specified string
+     * @exception ParseException if the beginning of the specified string
      *            cannot be parsed.
      */
     @Override
-    public Fraction parse(final String source) throws FractionParseException {
+    public Fraction parse(final String source) throws ParseException {
         final ParsePosition parsePosition = new ParsePosition(0);
         final Fraction result = parse(source, parsePosition);
         if (parsePosition.getIndex() == 0) {

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
index e48441d..815a57d 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
@@ -23,7 +23,7 @@ import java.text.ParseException;
 /**
  * Error thrown when a string cannot be parsed into a fraction.
  */
-public class FractionParseException extends ParseException {
+class FractionParseException extends ParseException {
 
     /** Serializable version identifier. */
     private static final long serialVersionUID = 201701181879L;

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
index b69663e..7998986 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
@@ -20,6 +20,7 @@ package org.apache.commons.numbers.fraction;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.text.NumberFormat;
+import java.text.ParseException;
 import java.util.Locale;
 
 import org.junit.Assert;
@@ -141,13 +142,13 @@ public class BigFractionFormatTest {
         try {
             properFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
         try {
             improperFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -159,13 +160,13 @@ public class BigFractionFormatTest {
         try {
             properFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
         try {
             improperFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -212,7 +213,7 @@ public class BigFractionFormatTest {
         try {
             improperFormat.parse(source);
             Assert.fail("invalid improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -230,7 +231,7 @@ public class BigFractionFormatTest {
         try {
             improperFormat.parse(source);
             Assert.fail("invalid improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -241,14 +242,14 @@ public class BigFractionFormatTest {
         try {
             properFormat.parse(source);
             Assert.fail("invalid minus in improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // expected
         }
         source = "2 2 / -3";
         try {
             properFormat.parse(source);
             Assert.fail("invalid minus in improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // expected
         }
     }

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
index af1f462..1cb3d6d 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
@@ -18,6 +18,7 @@
 package org.apache.commons.numbers.fraction;
 
 import java.text.NumberFormat;
+import java.text.ParseException;
 import java.util.Locale;
 
 import org.junit.Assert;
@@ -112,7 +113,7 @@ public class FractionFormatTest {
             Assert.assertNotNull(c);
             Assert.assertEquals(1, c.getNumerator());
             Assert.assertEquals(2, c.getDenominator());
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             Assert.fail(ex.getMessage());
         }
     }
@@ -179,13 +180,13 @@ public class FractionFormatTest {
         try {
             properFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
         try {
             improperFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -197,13 +198,13 @@ public class FractionFormatTest {
         try {
             properFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
         try {
             improperFormat.parse(source);
             Assert.fail(msg);
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -250,7 +251,7 @@ public class FractionFormatTest {
         try {
             improperFormat.parse(source);
             Assert.fail("invalid improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -268,7 +269,7 @@ public class FractionFormatTest {
         try {
             improperFormat.parse(source);
             Assert.fail("invalid improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // success
         }
     }
@@ -279,14 +280,14 @@ public class FractionFormatTest {
         try {
             properFormat.parse(source);
             Assert.fail("invalid minus in improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // expected
         }
         source = "2 2 / -3";
         try {
             properFormat.parse(source);
             Assert.fail("invalid minus in improper fraction.");
-        } catch (FractionParseException ex) {
+        } catch (ParseException ex) {
             // expected
         }
     }


Mime
View raw message