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
This commit is contained in:
Luc Maisonobe 2009-03-29 13:11:13 +00:00
parent 17f0dd2da5
commit 2fa13fe8c5
1 changed files with 13 additions and 41 deletions

View File

@ -28,7 +28,7 @@ import org.apache.commons.math.MathRuntimeException;
* @version $Revision$ $Date$
* @since 2.0
*/
public class BigFraction extends Number implements Comparable<BigFraction>, Cloneable {
public class BigFraction extends Number implements Comparable<BigFraction> {
/** A fraction representing "1". */
public static final BigFraction ONE = new BigFraction(1, 1);
@ -573,30 +573,6 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Clon
return new BigDecimal(numerator).divide(new BigDecimal(denominator), scale, roundingMode);
}
/**
* <p>
* Clones this object. The result {@link BigFraction} isn't reduced and is
* exactly the same as the original.
* </p>
*
* @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;
}
/**
* <p>
* Compares this object to another based on size.
@ -1058,14 +1034,12 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Clon
* if the fraction is <code>null</code>.
*/
public BigFraction subtract(final BigFraction fraction) {
BigFraction ret = null;
if (ZERO.equals(fraction)) {
ret = clone();
} else {
return this;
}
BigInteger num = null;
BigInteger den = null;
if (denominator.equals(fraction.denominator)) {
num = numerator.subtract(fraction.numerator);
den = denominator;
@ -1073,10 +1047,8 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Clon
num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
den = denominator.multiply(fraction.denominator);
}
ret = new BigFraction(num, den);
}
return new BigFraction(num, den);
return ret;
}
/**