You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2017/02/02 23:59:12 UTC
commons-numbers git commit: NUMBERS-6: Fix checkstyle issues.
Repository: commons-numbers
Updated Branches:
refs/heads/fraction__NUMBERS-6 16352312b -> 985d44fca
NUMBERS-6: Fix checkstyle issues.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/985d44fc
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/985d44fc
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/985d44fc
Branch: refs/heads/fraction__NUMBERS-6
Commit: 985d44fca746154042730c3b2743678f5df934ae
Parents: 1635231
Author: Ray DeCampo <ra...@decampo.org>
Authored: Thu Feb 2 18:58:44 2017 -0500
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Thu Feb 2 18:58:44 2017 -0500
----------------------------------------------------------------------
.../commons/numbers/fraction/BigFraction.java | 32 ++++++++++++++------
.../commons/numbers/fraction/Fraction.java | 13 +++++---
.../numbers/fraction/FractionException.java | 20 ++++++------
.../fraction/FractionParseException.java | 2 +-
4 files changed, 42 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/985d44fc/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
----------------------------------------------------------------------
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 eae82ea..eab9b7f 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
@@ -77,6 +77,12 @@ public class BigFraction
/** <code>BigInteger</code> representation of 100. */
private static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);
+ /** Parameter name for fraction (to satisfy checkstyle). */
+ private static final String PARAM_NAME_FRACTION = "fraction";
+
+ /** Parameter name for BigIntegers (to satisfy checkstyle). */
+ private static final String PARAM_NAME_BG = "bg";
+
/** The numerator. */
private final BigInteger numerator;
@@ -248,7 +254,7 @@ public class BigFraction
* maximum denominator value allowed.
* @param maxIterations
* maximum number of convergents.
- * @throws FractionConversionException
+ * @throws ArithmeticException
* if the continued fraction failed to converge.
*/
private BigFraction(final double value, final double epsilon,
@@ -446,8 +452,8 @@ public class BigFraction
* the {@link BigInteger} to add, must'nt be <code>null</code>.
* @return a <code>BigFraction</code> instance with the resulting values.
*/
- public BigFraction add(final BigInteger bg) throws NullPointerException {
- checkNotNull(bg, "bg");
+ public BigFraction add(final BigInteger bg) {
+ checkNotNull(bg, PARAM_NAME_BG);
if (numerator.signum() == 0) {
return new BigFraction(bg);
@@ -498,7 +504,7 @@ public class BigFraction
* @return a {@link BigFraction} instance with the resulting values.
*/
public BigFraction add(final BigFraction fraction) {
- checkNotNull(fraction, "fraction");
+ checkNotNull(fraction, PARAM_NAME_FRACTION);
if (fraction.numerator.signum() == 0) {
return this;
}
@@ -618,7 +624,7 @@ public class BigFraction
* @throws ArithmeticException if the fraction to divide by is zero
*/
public BigFraction divide(final BigInteger bg) {
- checkNotNull(bg, "bg");
+ checkNotNull(bg, PARAM_NAME_BG);
if (bg.signum() == 0) {
throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
}
@@ -667,7 +673,7 @@ public class BigFraction
* @throws ArithmeticException if the fraction to divide by is zero
*/
public BigFraction divide(final BigFraction fraction) {
- checkNotNull(fraction, "fraction");
+ checkNotNull(fraction, PARAM_NAME_FRACTION);
if (fraction.numerator.signum() == 0) {
throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
}
@@ -871,7 +877,7 @@ public class BigFraction
* @return a {@code BigFraction} instance with the resulting values.
*/
public BigFraction multiply(final BigInteger bg) {
- checkNotNull(bg, "bg");
+ checkNotNull(bg, PARAM_NAME_BG);
if (numerator.signum() == 0 || bg.signum() == 0) {
return ZERO;
}
@@ -924,7 +930,7 @@ public class BigFraction
* @return a {@link BigFraction} instance with the resulting values.
*/
public BigFraction multiply(final BigFraction fraction) {
- checkNotNull(fraction, "fraction");
+ checkNotNull(fraction, PARAM_NAME_FRACTION);
if (numerator.signum() == 0 ||
fraction.numerator.signum() == 0) {
return ZERO;
@@ -1089,7 +1095,7 @@ public class BigFraction
* @return a {@code BigFraction} instance with the resulting values.
*/
public BigFraction subtract(final BigInteger bg) {
- checkNotNull(bg, "bg");
+ checkNotNull(bg, PARAM_NAME_BG);
if (bg.signum() == 0) {
return this;
}
@@ -1136,7 +1142,7 @@ public class BigFraction
* @return a {@link BigFraction} instance with the resulting values
*/
public BigFraction subtract(final BigFraction fraction) {
- checkNotNull(fraction, "fraction");
+ checkNotNull(fraction, PARAM_NAME_FRACTION);
if (fraction.numerator.signum() == 0) {
return this;
}
@@ -1179,6 +1185,12 @@ public class BigFraction
return str;
}
+ /**
+ * 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);
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/985d44fc/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
----------------------------------------------------------------------
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 93c84fa..673d0d5 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
@@ -74,6 +74,9 @@ public class Fraction
/** Serializable version identifier */
private static final long serialVersionUID = 3698073679419233275L;
+ /** Parameter name for fraction (to satisfy checkstyle). */
+ private static final String PARAM_NAME_FRACTION = "fraction";
+
/** The default epsilon used for convergence. */
private static final double DEFAULT_EPSILON = 1e-5;
@@ -101,7 +104,7 @@ public class Fraction
* <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
* Continued Fraction</a> equations (11) and (22)-(26)</li>
* </ul>
- *
+ *
* @param value the double value to convert to a fraction.
* @param epsilon maximum error allowed. The resulting fraction is within
* {@code epsilon} of {@code value}, in absolute terms.
@@ -122,7 +125,7 @@ public class Fraction
* <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
* Continued Fraction</a> equations (11) and (22)-(26)</li>
* </ul>
- *
+ *
* @param value the double value to convert to a fraction.
* @param maxDenominator The maximum allowed value for denominator
* @throws IllegalArgumentException if the continued fraction failed to
@@ -471,7 +474,7 @@ public class Fraction
*/
private Fraction addSub(Fraction fraction, boolean isAdd) {
if (fraction == null) {
- throw new NullPointerException("fraction");
+ throw new NullPointerException(PARAM_NAME_FRACTION);
}
// zero is identity for addition.
if (numerator == 0) {
@@ -528,7 +531,7 @@ public class Fraction
*/
public Fraction multiply(Fraction fraction) {
if (fraction == null) {
- throw new NullPointerException("fraction");
+ throw new NullPointerException(PARAM_NAME_FRACTION);
}
if (numerator == 0 || fraction.numerator == 0) {
return ZERO;
@@ -562,7 +565,7 @@ public class Fraction
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
- throw new NullPointerException("fraction");
+ throw new NullPointerException(PARAM_NAME_FRACTION);
}
if (fraction.numerator == 0) {
throw new FractionException("the fraction to divide by must not be zero: {0}/{1}",
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/985d44fc/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
index c2283ad..1eea0d6 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java
@@ -23,19 +23,21 @@ import java.text.MessageFormat;
*/
class FractionException extends ArithmeticException {
+ /** Error message for overflow during conversion. */
+ static final String ERROR_CONVERSION_OVERFLOW = "Overflow trying to convert {0} to fraction ({1}/{2})";
+ /** Error message when iterative conversion fails. */
+ static final String ERROR_CONVERSION = "Unable to convert {0} to fraction after {1} iterations";
+ /** Error message for overflow by negation. */
+ static final String ERROR_NEGATION_OVERFLOW = "overflow in fraction {0}/{1}, cannot negate";
+ /** Error message for zero-valued denominator. */
+ static final String ERROR_ZERO_DENOMINATOR = "denominator must be different from 0";
+
/** Serializable version identifier. */
private static final long serialVersionUID = 201701191744L;
- public static final String ERROR_CONVERSION_OVERFLOW = "Overflow trying to convert {0} to fraction ({1}/{2})";
- public static final String ERROR_CONVERSION = "Unable to convert {0} to fraction after {1} iterations";
- public static final String ERROR_NEGATION_OVERFLOW = "overflow in fraction {0}/{1}, cannot negate";
- public static final String ERROR_ZERO_DENOMINATOR = "denominator must be different from 0";
-
+ /** Arguments for formatting the message. */
protected Object[] formatArguments;
- public FractionException() {
- }
-
/**
* Create an exception where the message is constructed by applying
* the {@code format()} method from {@code java.text.MessageFormat}.
@@ -43,7 +45,7 @@ class FractionException extends ArithmeticException {
* @param message the exception message with replaceable parameters
* @param formatArguments the arguments for formatting the message
*/
- public FractionException(String message, Object... formatArguments) {
+ FractionException(String message, Object... formatArguments) {
super(message);
this.formatArguments = formatArguments;
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/985d44fc/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
index 815a57d..08886e0 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
@@ -35,7 +35,7 @@ class FractionParseException extends ParseException {
* @param position position of error
* @param type type of target object
*/
- public FractionParseException(String source, int position, Class<?> type) {
+ FractionParseException(String source, int position, Class<?> type) {
super(MessageFormat.format("string \"{0}\" unparseable (from position {1}) as an object of type {2}",
source, position, type),
position);