Return-Path:
obj
must be either a
+ * Formats a object to produce a string. {@code obj} must be either a
* {@link Complex} object or a {@link Number} object. Any other type of
* object will result in an {@link IllegalArgumentException} being thrown.
*
@@ -179,7 +181,7 @@ public class ComplexFormat extends Compo
* offsets of the alignment field
* @return the value passed in as toAppendTo.
* @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
- * @throws IllegalArgumentException is obj
is not a valid type.
+ * @throws IllegalArgumentException is {@code obj} is not a valid type.
*/
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo,
@@ -193,9 +195,8 @@ public class ComplexFormat extends Compo
ret = format( new Complex(((Number)obj).doubleValue(), 0.0),
toAppendTo, pos);
} else {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_COMPLEX,
- obj.getClass().getName());
+ throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_INSTANCE_AS_COMPLEX,
+ obj.getClass().getName());
}
return ret;
@@ -345,13 +346,17 @@ public class ComplexFormat extends Compo
/**
* Modify the imaginaryCharacter.
* @param imaginaryCharacter The new imaginaryCharacter value.
- * @throws IllegalArgumentException if imaginaryCharacter
is
- * null
or an empty string.
+ * @throws NullArgumentException if {@code imaginaryCharacter} is
+ * {@code null}.
+ * @throws NoDataException if {@code imaginaryCharacter} is an
+ * empty string.
*/
public void setImaginaryCharacter(String imaginaryCharacter) {
- if (imaginaryCharacter == null || imaginaryCharacter.length() == 0) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.EMPTY_STRING_FOR_IMAGINARY_CHARACTER);
+ if (imaginaryCharacter == null) {
+ throw new NullArgumentException();
+ }
+ if (imaginaryCharacter.length() == 0) {
+ throw new NoDataException();
}
this.imaginaryCharacter = imaginaryCharacter;
}
@@ -379,5 +384,4 @@ public class ComplexFormat extends Compo
}
this.realFormat = realFormat;
}
-
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Fri Dec 10 00:50:50 2010
@@ -20,7 +20,6 @@ import java.io.Serializable;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.UnivariateRealFunction;
-import org.apache.commons.math.analysis.solvers.BrentSolver;
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
import org.apache.commons.math.exception.MathUserException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java Fri Dec 10 00:50:50 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.distribu
import java.io.Serializable;
import org.apache.commons.math.MathException;
-import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**
@@ -51,18 +51,17 @@ public abstract class AbstractDistributi
* @param x0 the (inclusive) lower bound
* @param x1 the (inclusive) upper bound
* @return the probability that a random variable with this distribution
- * will take a value between x0
and x1
,
+ * will take a value between {@code x0} and {@code x1},
* including the endpoints.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
- * @throws IllegalArgumentException if x0 > x1
+ * @throws NumberIsTooLargeException if {@code x0 > x1}
*/
public double cumulativeProbability(double x0, double x1)
throws MathException {
if (x0 > x1) {
- throw MathRuntimeException.createIllegalArgumentException(
- LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
- x0, x1);
+ throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
+ x0, x1, true);
}
return cumulativeProbability(x1) - cumulativeProbability(x0);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java Fri Dec 10 00:50:50 2010
@@ -86,7 +86,7 @@ public abstract class AbstractIntegerDis
throws MathException {
if (x1 < x0) {
throw new NumberIsTooSmallException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
- x0, x1, true);
+ x1, x0, true);
}
if (FastMath.floor(x0) < x0) {
return cumulativeProbability(((int) FastMath.floor(x0)) + 1,
@@ -143,7 +143,7 @@ public abstract class AbstractIntegerDis
public double cumulativeProbability(int x0, int x1) throws MathException {
if (x1 < x0) {
throw new NumberIsTooSmallException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
- x0, x1, true);
+ x1, x0, true);
}
return cumulativeProbability(x1) - cumulativeProbability(x0 - 1);
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java Fri Dec 10 00:50:50 2010
@@ -122,11 +122,10 @@ public class NormalDistributionImpl exte
*/
public double cumulativeProbability(double x) throws MathException {
final double dev = x - mean;
- if (FastMath.abs(dev) > 40 * standardDeviation) {
+ if (FastMath.abs(dev) > 40 * standardDeviation) {
return dev < 0 ? 0.0d : 1.0d;
}
- return 0.5 * (1.0 + Erf.erf((dev) /
- (standardDeviation * FastMath.sqrt(2.0))));
+ return 0.5 * (1 + Erf.erf(dev / (standardDeviation * FastMath.sqrt(2))));
}
/**
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java Fri Dec 10 00:50:50 2010
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
@@ -32,21 +28,11 @@ import org.apache.commons.math.exception
* @since 3.0
* @version $Revision$ $Date$
*/
-public class MathArithmeticException extends ArithmeticException {
-
+public class MathArithmeticException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param args Arguments.
*/
public MathArithmeticException(Object ... args) {
@@ -59,33 +45,6 @@ public class MathArithmeticException ext
*/
public MathArithmeticException(Localizable specific,
Object ... args) {
- this.specific = specific;
- arguments = ArgUtils.flatten(args);
- }
-
- /**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- *
- * @return the localized message.
- */
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale,
- specific,
- LocalizedFormats.UNSUPPORTED_OPERATION,
- arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
+ super(null, specific, LocalizedFormats.ARITHMETIC_EXCEPTION, args);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java Fri Dec 10 00:50:50 2010
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
/**
@@ -32,25 +28,11 @@ import org.apache.commons.math.exception
* @since 2.2
* @version $Revision$ $Date$
*/
-public class MathIllegalArgumentException extends IllegalArgumentException implements MathThrowable {
-
+public class MathIllegalArgumentException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Pattern used to build the message (general problem description).
- */
- private final Localizable general;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param specific Message pattern providing the specific context of
* the error.
* @param general Message pattern explaining the cause of the error.
@@ -59,9 +41,7 @@ public class MathIllegalArgumentExceptio
public MathIllegalArgumentException(Localizable specific,
Localizable general,
Object ... args) {
- this.specific = specific;
- this.general = general;
- arguments = ArgUtils.flatten(args);
+ super(null, specific, general, args);
}
/**
* @param general Message pattern explaining the cause of the error.
@@ -71,41 +51,4 @@ public class MathIllegalArgumentExceptio
Object ... args) {
this(null, general, args);
}
-
- /** {@inheritDoc} */
- public Localizable getSpecificPattern() {
- return specific;
- }
-
- /** {@inheritDoc} */
- public Localizable getGeneralPattern() {
- return general;
- }
-
- /** {@inheritDoc} */
- public Object[] getArguments() {
- return arguments.clone();
- }
-
- /**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- * @return the localized message.
- */
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale, specific, general, arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
- }
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java Fri Dec 10 00:50:50 2010
@@ -16,11 +16,8 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
+import org.apache.commons.math.exception.util.LocalizedFormats;
/**
* Base class for all exceptions that signal a mismatch between the
@@ -29,25 +26,11 @@ import org.apache.commons.math.exception
* @since 2.2
* @version $Revision$ $Date$
*/
-public class MathIllegalStateException extends IllegalStateException implements MathThrowable {
-
+public class MathIllegalStateException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Pattern used to build the message (general problem description).
- */
- private final Localizable general;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param specific Message pattern providing the specific context of
* the error.
* @param general Message pattern explaining the cause of the error.
@@ -56,55 +39,20 @@ public class MathIllegalStateException e
public MathIllegalStateException(Localizable specific,
Localizable general,
Object ... args) {
- this.specific = specific;
- this.general = general;
- arguments = ArgUtils.flatten(args);
+ super(null, specific, general, args);
}
/**
- * @param general Message pattern explaining the cause of the error.
+ * @param specific Message pattern explaining the cause of the error.
* @param args Arguments.
*/
- public MathIllegalStateException(Localizable general,
+ public MathIllegalStateException(Localizable specific,
Object ... args) {
- this(null, general, args);
- }
-
- /** {@inheritDoc} */
- public Localizable getSpecificPattern() {
- return specific;
- }
-
- /** {@inheritDoc} */
- public Localizable getGeneralPattern() {
- return general;
+ this(specific, LocalizedFormats.ILLEGAL_STATE, args);
}
-
- /** {@inheritDoc} */
- public Object[] getArguments() {
- return arguments.clone();
- }
-
/**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- *
- * @return the localized message.
+ * @param args Arguments.
*/
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale, specific, general, arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
+ public MathIllegalStateException(Object ... args) {
+ this(null, args);
}
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
- }
-
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java Fri Dec 10 00:50:50 2010
@@ -23,9 +23,10 @@ import org.apache.commons.math.exception
import org.apache.commons.math.exception.util.MessageFactory;
/**
- * This class is intended as a base class for exceptions that must wrap
- * low-level exceptions in order to propagate an exception that better
- * corresponds to the high-level action that triggered the problem.
+ * This class is primarily intended as a base class for exceptions
+ * that must wrap low-level exceptions in order to propagate an
+ * exception that better corresponds to the high-level action that
+ * triggered the problem.
*
* @since 3.0
* @version $Revision$ $Date$
@@ -48,7 +49,7 @@ public class MathRuntimeException extend
private final Object[] arguments;
/**
- * Builds an exception from two patterns (specific and general) and
+ * Build an exception from two patterns (specific and general) and
* an argument list.
*
* @param cause Cause of the error (may be null).
@@ -57,16 +58,25 @@ public class MathRuntimeException extend
* @param arguments Format arguments. They will be substituted in
* both the {@code general} and {@code specific} format specifiers.
*/
- protected MathRuntimeException(final Throwable cause,
- final Localizable specific,
- final Localizable general,
- final Object ... arguments) {
+ public MathRuntimeException(final Throwable cause,
+ final Localizable specific,
+ final Localizable general,
+ final Object ... arguments) {
super(cause);
this.specific = specific;
this.general = general;
this.arguments = ArgUtils.flatten(arguments);
}
+ /**
+ * Wrap an exception.
+ *
+ * @param cause Cause of the error (may be null).
+ */
+ public MathRuntimeException(final Throwable cause) {
+ this(cause, null, null);
+ }
+
/** {@inheritDoc} */
public Localizable getSpecificPattern() {
return specific;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java Fri Dec 10 00:50:50 2010
@@ -16,10 +16,6 @@
*/
package org.apache.commons.math.exception;
-import java.util.Locale;
-
-import org.apache.commons.math.exception.util.ArgUtils;
-import org.apache.commons.math.exception.util.MessageFactory;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
@@ -32,21 +28,11 @@ import org.apache.commons.math.exception
* @since 2.2
* @version $Revision$ $Date$
*/
-public class MathUnsupportedOperationException extends UnsupportedOperationException implements MathThrowable {
-
+public class MathUnsupportedOperationException extends MathRuntimeException {
/** Serializable version Id. */
private static final long serialVersionUID = -6024911025449780478L;
/**
- * Pattern used to build the message (specific context).
- */
- private final Localizable specific;
- /**
- * Arguments used to build the message.
- */
- private final Object[] arguments;
-
- /**
* @param args Arguments.
*/
public MathUnsupportedOperationException(Object ... args) {
@@ -59,48 +45,6 @@ public class MathUnsupportedOperationExc
*/
public MathUnsupportedOperationException(Localizable specific,
Object ... args) {
- this.specific = specific;
- arguments = ArgUtils.flatten(args);
- }
-
- /** {@inheritDoc} */
- public Localizable getSpecificPattern() {
- return specific;
- }
-
- /** {@inheritDoc} */
- public Localizable getGeneralPattern() {
- return LocalizedFormats.UNSUPPORTED_OPERATION;
- }
-
- /** {@inheritDoc} */
- public Object[] getArguments() {
- return arguments.clone();
- }
-
- /**
- * Get the message in a specified locale.
- *
- * @param locale Locale in which the message should be translated.
- *
- * @return the localized message.
- */
- public String getMessage(final Locale locale) {
- return MessageFactory.buildMessage(locale,
- specific,
- LocalizedFormats.UNSUPPORTED_OPERATION,
- arguments);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return getMessage(Locale.US);
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return getMessage(Locale.getDefault());
+ super(null, specific, LocalizedFormats.UNSUPPORTED_OPERATION, args);
}
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/LocalizedFormats.java Fri Dec 10 00:50:50 2010
@@ -304,6 +304,8 @@ public enum LocalizedFormats implements
UNPARSEABLE_REAL_VECTOR("unparseable real vector: \"{0}\""),
UNSUPPORTED_EXPANSION_MODE("unsupported expansion mode {0}, supported modes are {1} ({2}) and {3} ({4})"),
UNSUPPORTED_OPERATION("unsupported operation"), /* keep */
+ ARITHMETIC_EXCEPTION("arithmetic exception"), /* keep */
+ ILLEGAL_STATE("illegal state"), /* keep */
USER_EXCEPTION("exception generated in user code"), /* keep */
URL_CONTAINS_NO_DATA("URL {0} contains no data"),
VALUES_ADDED_BEFORE_CONFIGURING_STATISTIC("{0} values have been added before statistic is configured"),
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java?rev=1044186&r1=1044185&r2=1044186&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java Fri Dec 10 00:50:50 2010
@@ -20,8 +20,8 @@ import java.io.Serializable;
import java.math.BigInteger;
import org.apache.commons.math.FieldElement;
-import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.MathArithmeticException;
import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.util.MathUtils;
import org.apache.commons.math.util.FastMath;
@@ -110,7 +110,7 @@ public class Fraction
*
epsilon
of value
, in absolute terms.
+ * {@code epsilon} of {@code value}, in absolute terms.
* @param maxIterations maximum number of convergents
* @throws FractionConversionException if the continued fraction failed to
* converge.
@@ -166,7 +166,7 @@ public class Fraction
*
* @param value the double value to convert to a fraction.
* @param epsilon maximum error allowed. The resulting fraction is within
- * epsilon
of value
, in absolute terms.
+ * {@code epsilon} of {@code value}, in absolute terms.
* @param maxDenominator maximum denominator value allowed.
* @param maxIterations maximum number of convergents
* @throws FractionConversionException if the continued fraction failed to
@@ -251,17 +251,18 @@ public class Fraction
* reduced to lowest terms.
* @param num the numerator.
* @param den the denominator.
- * @throws ArithmeticException if the denominator is zero
+ * @throws MathArithmeticException if the denominator is {@code zero}
*/
public Fraction(int num, int den) {
if (den == 0) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION, num, den);
+ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
+ num, den);
}
if (den < 0) {
- if (num == Integer.MIN_VALUE || den == Integer.MIN_VALUE) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.OVERFLOW_IN_FRACTION, num, den);
+ if (num == Integer.MIN_VALUE ||
+ den == Integer.MIN_VALUE) {
+ throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
+ num, den);
}
num = -num;
den = -den;
@@ -403,8 +404,7 @@ public class Fraction
*/
public Fraction negate() {
if (numerator==Integer.MIN_VALUE) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator);
+ throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator);
}
return new Fraction(-numerator, denominator);
}
@@ -421,11 +421,11 @@ public class Fraction
* Adds the value of this fraction to another, returning the result in reduced form. * The algorithm follows Knuth, 4.5.1.
* - * @param fraction the fraction to add, must not benull
- * @return a Fraction
instance with the resulting values
- * @throws IllegalArgumentException if the fraction is null
- * @throws ArithmeticException if the resulting numerator or denominator exceeds
- * Integer.MAX_VALUE
+ * @param fraction the fraction to add, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator exceeds
+ * {@code Integer.MAX_VALUE}
*/
public Fraction add(Fraction fraction) {
return addSub(fraction, true /* add */);
@@ -444,11 +444,11 @@ public class Fraction
* Subtracts the value of another fraction from the value of this one, * returning the result in reduced form.
* - * @param fraction the fraction to subtract, must not benull
- * @return a Fraction
instance with the resulting values
- * @throws IllegalArgumentException if the fraction is null
- * @throws ArithmeticException if the resulting numerator or denominator
- * cannot be represented in an int
.
+ * @param fraction the fraction to subtract, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator
+ * cannot be represented in an {@code int}.
*/
public Fraction subtract(Fraction fraction) {
return addSub(fraction, false /* subtract */);
@@ -466,12 +466,12 @@ public class Fraction
/**
* Implement add and subtract using algorithm described in Knuth 4.5.1.
*
- * @param fraction the fraction to subtract, must not be null
+ * @param fraction the fraction to subtract, must not be {@code null}
* @param isAdd true to add, false to subtract
- * @return a Fraction
instance with the resulting values
- * @throws IllegalArgumentException if the fraction is null
- * @throws ArithmeticException if the resulting numerator or denominator
- * cannot be represented in an int
.
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator
+ * cannot be represented in an {@code int}.
*/
private Fraction addSub(Fraction fraction, boolean isAdd) {
if (fraction == null) {
@@ -512,8 +512,8 @@ public class Fraction
// result is (t/d2) / (u'/d1)(v'/d2)
BigInteger w = t.divide(BigInteger.valueOf(d2));
if (w.bitLength() > 31) {
- throw MathRuntimeException.createArithmeticException(LocalizedFormats.NUMERATOR_OVERFLOW_AFTER_MULTIPLY,
- w);
+ throw new MathArithmeticException(LocalizedFormats.NUMERATOR_OVERFLOW_AFTER_MULTIPLY,
+ w);
}
return new Fraction (w.intValue(),
MathUtils.mulAndCheck(denominator/d1,
@@ -524,11 +524,11 @@ public class Fraction
* Multiplies the value of this fraction by another, returning the * result in reduced form.
* - * @param fraction the fraction to multiply by, must not benull
- * @return a Fraction
instance with the resulting values
- * @throws IllegalArgumentException if the fraction is null
- * @throws ArithmeticException if the resulting numerator or denominator exceeds
- * Integer.MAX_VALUE
+ * @param fraction the fraction to multiply by, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws NullArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the resulting numerator or denominator exceeds
+ * {@code Integer.MAX_VALUE}
*/
public Fraction multiply(Fraction fraction) {
if (fraction == null) {
@@ -558,21 +558,20 @@ public class Fraction
/**
* Divide the value of this fraction by another.
* - * @param fraction the fraction to divide by, must not benull
- * @return a Fraction
instance with the resulting values
- * @throws IllegalArgumentException if the fraction is null
- * @throws ArithmeticException if the fraction to divide by is zero
- * @throws ArithmeticException if the resulting numerator or denominator exceeds
- * Integer.MAX_VALUE
+ * @param fraction the fraction to divide by, must not be {@code null}
+ * @return a {@code Fraction} instance with the resulting values
+ * @throws IllegalArgumentException if the fraction is {@code null}
+ * @throws MathArithmeticException if the fraction to divide by is zero
+ * @throws MathArithmeticException if the resulting numerator or denominator exceeds
+ * {@code Integer.MAX_VALUE}
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
throw new NullArgumentException(LocalizedFormats.FRACTION);
}
if (fraction.numerator == 0) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY,
- fraction.numerator, fraction.denominator);
+ throw new MathArithmeticException(LocalizedFormats.ZERO_FRACTION_TO_DIVIDE_BY,
+ fraction.numerator, fraction.denominator);
}
return multiply(fraction.reciprocal());
}
@@ -587,7 +586,7 @@ public class Fraction
}
/**
- * Creates a Fraction
instance with the 2 parts
+ *
Creates a {@code Fraction} instance with the 2 parts * of a fraction Y/Z.
* *Any negative signs are resolved to be on the numerator.
@@ -595,12 +594,12 @@ public class Fraction * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance, with the numerator and denominator reduced - * @throws ArithmeticException if the denominator iszero
+ * @throws MathArithmeticException if the denominator is {@code zero}
*/
public static Fraction getReducedFraction(int numerator, int denominator) {
if (denominator == 0) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION, numerator, denominator);
+ throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
+ numerator, denominator);
}
if (numerator==0) {
return ZERO; // normalize zero.
@@ -612,8 +611,8 @@ public class Fraction
if (denominator < 0) {
if (numerator==Integer.MIN_VALUE ||
denominator==Integer.MIN_VALUE) {
- throw MathRuntimeException.createArithmeticException(
- LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator);
+ throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
+ numerator, denominator);
}
numerator = -numerator;
denominator = -denominator;
@@ -627,7 +626,7 @@ public class Fraction
/**
*
- * Returns the String
representing this fraction, ie
+ * Returns the {@code String} representing this fraction, ie
* "num / dem" or just "num" if the denominator is one.
*