Java Code Examples for org.apache.commons.math.MathRuntimeException#createNullPointerException()

The following examples show how to use org.apache.commons.math.MathRuntimeException#createNullPointerException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 2
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 3
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 4
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 5
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 6
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 7
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 8
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 * 
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 9
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 * 
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 10
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 * 
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException("denominator must be different from 0");
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 11
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}
 
Example 12
Source File: BigFraction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Create a {@link BigFraction} given the numerator and denominator as
 * <code>BigInteger</code>. The {@link BigFraction} is reduced to lowest terms.
 * </p>
 *
 * @param num
 *            the numerator, must not be <code>null</code>.
 * @param den
 *            the denominator, must not be <code>null</code>.
 * @throws ArithmeticException
 *             if the denominator is <code>zero</code>.
 * @throws NullPointerException
 *             if the numerator or the denominator is <code>zero</code>.
 */
public BigFraction(BigInteger num, BigInteger den) {
    if (num == null) {
        throw MathRuntimeException.createNullPointerException("numerator is null");
    }
    if (den == null) {
        throw MathRuntimeException.createNullPointerException("denominator is null");
    }
    if (BigInteger.ZERO.equals(den)) {
        throw MathRuntimeException.createArithmeticException(FORBIDDEN_ZERO_DENOMINATOR);
    }
    if (BigInteger.ZERO.equals(num)) {
        numerator   = BigInteger.ZERO;
        denominator = BigInteger.ONE;
    } else {

        // reduce numerator and denominator by greatest common denominator
        final BigInteger gcd = num.gcd(den);
        if (BigInteger.ONE.compareTo(gcd) < 0) {
            num = num.divide(gcd);
            den = den.divide(gcd);
        }

        // move sign to numerator
        if (BigInteger.ZERO.compareTo(den) > 0) {
            num = num.negate();
            den = den.negate();
        }

        // store the values in the final fields
        numerator   = num;
        denominator = den;

    }
}