本文整理汇总了Java中org.apache.commons.math.MathRuntimeException.createNullPointerException方法的典型用法代码示例。如果您正苦于以下问题:Java MathRuntimeException.createNullPointerException方法的具体用法?Java MathRuntimeException.createNullPointerException怎么用?Java MathRuntimeException.createNullPointerException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.MathRuntimeException
的用法示例。
在下文中一共展示了MathRuntimeException.createNullPointerException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BigFraction
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* <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;
}
}
示例2: BigFraction
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* <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;
}
}
示例3: BigFraction
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* <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;
}
}