This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/fraction-dev by this push:
     new ebb8e03  NUMBERS-91: Added ofInt() factory methods and made 
BigInteger-based constructor private
ebb8e03 is described below

commit ebb8e03f139b8cec84564b3e558fea39b71d2f24
Author: Eric Barnhill <[email protected]>
AuthorDate: Thu Dec 27 15:54:51 2018 -0800

    NUMBERS-91: Added ofInt() factory methods and made BigInteger-based
    constructor private
---
 .../commons/numbers/fraction/BigFraction.java      | 68 +++++++---------------
 1 file changed, 20 insertions(+), 48 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 a76eb45..1430051 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
@@ -29,53 +29,14 @@ public class BigFraction
     extends Number
     implements Comparable<BigFraction>, Serializable {
 
-    /** A fraction representing "2 / 1". */
-    public static final BigFraction TWO = new BigFraction(2);
-
-    /** A fraction representing "1". */
-    public static final BigFraction ONE = new BigFraction(1);
-
-    /** A fraction representing "0". */
-    public static final BigFraction ZERO = new BigFraction(0);
-
-    /** A fraction representing "-1 / 1". */
-    public static final BigFraction MINUS_ONE = new BigFraction(-1);
-
-    /** A fraction representing "4/5". */
-    public static final BigFraction FOUR_FIFTHS = new BigFraction(4, 5);
-
-    /** A fraction representing "1/5". */
-    public static final BigFraction ONE_FIFTH = new BigFraction(1, 5);
-
-    /** A fraction representing "1/2". */
-    public static final BigFraction ONE_HALF = new BigFraction(1, 2);
-
-    /** A fraction representing "1/4". */
-    public static final BigFraction ONE_QUARTER = new BigFraction(1, 4);
-
-    /** A fraction representing "1/3". */
-    public static final BigFraction ONE_THIRD = new BigFraction(1, 3);
-
-    /** A fraction representing "3/5". */
-    public static final BigFraction THREE_FIFTHS = new BigFraction(3, 5);
-
-    /** A fraction representing "3/4". */
-    public static final BigFraction THREE_QUARTERS = new BigFraction(3, 4);
-
-    /** A fraction representing "2/5". */
-    public static final BigFraction TWO_FIFTHS = new BigFraction(2, 5);
-
-    /** A fraction representing "2/4". */
-    public static final BigFraction TWO_QUARTERS = new BigFraction(2, 4);
-
-    /** A fraction representing "2/3". */
-    public static final BigFraction TWO_THIRDS = new BigFraction(2, 3);
-
     /** Serializable version identifier. */
     private static final long serialVersionUID = -5630213147331578515L;
+    
+    /** A fraction representing "0". */
+    public static final BigFraction ZERO = new BigFraction(0);
 
-    /** <code>BigInteger</code> representation of 100. */
-    private static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);
+    /** A fraction representing "1". */
+    public static final BigFraction ONE = new BigFraction(1);
 
     /** Parameter name for fraction (to satisfy checkstyle). */
     private static final String PARAM_NAME_FRACTION = "fraction";
@@ -98,8 +59,8 @@ public class BigFraction
      * @param num
      *            the numerator.
      */
-    public BigFraction(final BigInteger num) {
-        this(num, BigInteger.ONE);
+    public static BigFraction ofInt(final BigInteger num) {
+        return new BigFraction(num, BigInteger.ONE);
     }
 
     /**
@@ -110,7 +71,18 @@ public class BigFraction
      * @param den the denominator, must not be {@code null}.
      * @throws ArithmeticException if the denominator is zero.
      */
-    public BigFraction(BigInteger num, BigInteger den) {
+    public static BigFraction ofInt(BigInteger num, BigInteger den) {
+       return new BigFraction(num, den);
+    }
+    
+    /**
+     * Private constructor for BigFraction ofInt() factory methods.
+     *
+     * @param num the numerator, must not be {@code null}.
+     * @param den the denominator, must not be {@code null}.
+     * @throws ArithmeticException if the denominator is zero.
+     */
+    private BigFraction(BigInteger num, BigInteger den) {
         checkNotNull(num, "numerator");
         checkNotNull(den, "denominator");
         if (den.signum() == 0) {
@@ -456,7 +428,7 @@ public class BigFraction
         checkNotNull(bg, PARAM_NAME_BG);
 
         if (numerator.signum() == 0) {
-            return new BigFraction(bg);
+            return ofInt(bg);
         }
         if (bg.signum() == 0) {
             return this;

Reply via email to