From 2fa13fe8c5065ced944d0d0edccab744aed86547 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 29 Mar 2009 13:11:13 +0000 Subject: [PATCH] removed BigFraction.clone() as the class is guaranteed to be immutable git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@759677 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/fraction/BigFraction.java | 54 +++++-------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/src/java/org/apache/commons/math/fraction/BigFraction.java b/src/java/org/apache/commons/math/fraction/BigFraction.java index 323892e41..c3a109600 100644 --- a/src/java/org/apache/commons/math/fraction/BigFraction.java +++ b/src/java/org/apache/commons/math/fraction/BigFraction.java @@ -28,7 +28,7 @@ import org.apache.commons.math.MathRuntimeException; * @version $Revision$ $Date$ * @since 2.0 */ -public class BigFraction extends Number implements Comparable, Cloneable { +public class BigFraction extends Number implements Comparable { /** A fraction representing "1". */ public static final BigFraction ONE = new BigFraction(1, 1); @@ -573,30 +573,6 @@ public class BigFraction extends Number implements Comparable, Clon return new BigDecimal(numerator).divide(new BigDecimal(denominator), scale, roundingMode); } - /** - *

- * Clones this object. The result {@link BigFraction} isn't reduced and is - * exactly the same as the original. - *

- * - * @return an exact copy of this {@link BigFraction}. - * @see java.lang.Object#clone() - */ - @Override - public BigFraction clone() { - // don't need to clone numerator and denominator because the object is - // immutable - BigFraction clone = null; - - try { - clone = (BigFraction) super.clone(); - } catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - - return clone; - } - /** *

* Compares this object to another based on size. @@ -1058,25 +1034,21 @@ public class BigFraction extends Number implements Comparable, Clon * if the fraction is null. */ public BigFraction subtract(final BigFraction fraction) { - BigFraction ret = null; - if (ZERO.equals(fraction)) { - ret = clone(); - } else { - BigInteger num = null; - BigInteger den = null; - - if (denominator.equals(fraction.denominator)) { - num = numerator.subtract(fraction.numerator); - den = denominator; - } else { - num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator)); - den = denominator.multiply(fraction.denominator); - } - ret = new BigFraction(num, den); + return this; } - return ret; + BigInteger num = null; + BigInteger den = null; + if (denominator.equals(fraction.denominator)) { + num = numerator.subtract(fraction.numerator); + den = denominator; + } else { + num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator)); + den = denominator.multiply(fraction.denominator); + } + return new BigFraction(num, den); + } /**