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 2019/11/08 14:47:43 UTC

[commons-numbers] branch master updated: NUMBERS-126: Removed null checks.

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


The following commit(s) were added to refs/heads/master by this push:
     new ddfdbce  NUMBERS-126: Removed null checks.
ddfdbce is described below

commit ddfdbce4ffb6e4cd2cfd8d280f5942639b521d6e
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Fri Nov 8 15:39:23 2019 +0100

    NUMBERS-126: Removed null checks.
---
 .../commons/numbers/fraction/BigFraction.java      | 24 ----------------------
 .../apache/commons/numbers/fraction/Fraction.java  | 11 ----------
 2 files changed, 35 deletions(-)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index fd1ff52..a10af09 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -64,8 +64,6 @@ public class BigFraction
      * @throws ArithmeticException if the denominator is zero.
      */
     private BigFraction(BigInteger num, BigInteger den) {
-        checkNotNull(num, "numerator");
-        checkNotNull(den, "denominator");
         if (den.signum() == 0) {
             throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
         }
@@ -403,8 +401,6 @@ public class BigFraction
      * @return a <code>BigFraction</code> instance with the resulting values.
      */
     public BigFraction add(final BigInteger bg) {
-        checkNotNull(bg, PARAM_NAME_BG);
-
         if (numerator.signum() == 0) {
             return of(bg);
         }
@@ -454,7 +450,6 @@ public class BigFraction
      * @return a {@link BigFraction} instance with the resulting values.
      */
     public BigFraction add(final BigFraction fraction) {
-        checkNotNull(fraction, PARAM_NAME_FRACTION);
         if (fraction.numerator.signum() == 0) {
             return this;
         }
@@ -569,7 +564,6 @@ public class BigFraction
      * @throws ArithmeticException if the fraction to divide by is zero
      */
     public BigFraction divide(final BigInteger bg) {
-        checkNotNull(bg, PARAM_NAME_BG);
         if (bg.signum() == 0) {
             throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
         }
@@ -618,7 +612,6 @@ public class BigFraction
      * @throws ArithmeticException if the fraction to divide by is zero
      */
     public BigFraction divide(final BigFraction fraction) {
-        checkNotNull(fraction, PARAM_NAME_FRACTION);
         if (fraction.numerator.signum() == 0) {
             throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
         }
@@ -1000,7 +993,6 @@ public class BigFraction
      * @return a {@code BigFraction} instance with the resulting values.
      */
     public BigFraction multiply(final BigInteger bg) {
-        checkNotNull(bg, PARAM_NAME_BG);
         if (numerator.signum() == 0 || bg.signum() == 0) {
             return ZERO;
         }
@@ -1053,7 +1045,6 @@ public class BigFraction
      * @return a {@link BigFraction} instance with the resulting values.
      */
     public BigFraction multiply(final BigFraction fraction) {
-        checkNotNull(fraction, PARAM_NAME_FRACTION);
         if (numerator.signum() == 0 ||
             fraction.numerator.signum() == 0) {
             return ZERO;
@@ -1208,7 +1199,6 @@ public class BigFraction
      * @return a {@code BigFraction} instance with the resulting values.
      */
     public BigFraction subtract(final BigInteger bg) {
-        checkNotNull(bg, PARAM_NAME_BG);
         if (bg.signum() == 0) {
             return this;
         }
@@ -1255,7 +1245,6 @@ public class BigFraction
      * @return a {@link BigFraction} instance with the resulting values
      */
     public BigFraction subtract(final BigFraction fraction) {
-        checkNotNull(fraction, PARAM_NAME_FRACTION);
         if (fraction.numerator.signum() == 0) {
             return this;
         }
@@ -1331,17 +1320,4 @@ public class BigFraction
             return of(num, denom);
         }
     }
-
-
-    /**
-     * Check that the argument is not null and throw a NullPointerException
-     * if it is.
-     * @param arg     the argument to check
-     * @param argName the name of the argument
-     */
-    private static void checkNotNull(Object arg, String argName) {
-        if (arg == null) {
-            throw new NullPointerException(argName);
-        }
-    }
 }
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 1f99079..d33a63e 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
@@ -474,10 +474,6 @@ public class Fraction
      * cannot be represented in an {@code int}.
      */
     private Fraction addSub(Fraction fraction, boolean isAdd) {
-        if (fraction == null) {
-            throw new NullPointerException(PARAM_NAME_FRACTION);
-        }
-
         // Zero is identity for addition.
         if (numerator == 0) {
             return isAdd ? fraction : fraction.negate();
@@ -530,10 +526,6 @@ public class Fraction
      * exceeds {@code Integer.MAX_VALUE}
      */
     public Fraction multiply(Fraction fraction) {
-        if (fraction == null) {
-            throw new NullPointerException(PARAM_NAME_FRACTION);
-        }
-
         if (numerator == 0 ||
             fraction.numerator == 0) {
             return ZERO;
@@ -567,9 +559,6 @@ public class Fraction
      * {@code Integer.MAX_VALUE}
      */
     public Fraction divide(Fraction fraction) {
-        if (fraction == null) {
-            throw new NullPointerException(PARAM_NAME_FRACTION);
-        }
         if (fraction.numerator == 0) {
             throw new FractionException("the fraction to divide by must not be zero: {0}/{1}",
                                         fraction.numerator, fraction.denominator);