本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION属性的具体用法?Java LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION怎么用?Java LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
/**
* Formats an object and appends the result to a StringBuffer.
* <code>obj</code> must be either a {@link BigFraction} object or a
* {@link BigInteger} object or a {@link Number} object. Any other type of
* object will result in an {@link IllegalArgumentException} being thrown.
*
* @param obj the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
* 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 MathIllegalArgumentException if <code>obj</code> is not a valid type.
*/
@Override
public StringBuffer format(final Object obj,
final StringBuffer toAppendTo, final FieldPosition pos) {
final StringBuffer ret;
if (obj instanceof BigFraction) {
ret = format((BigFraction) obj, toAppendTo, pos);
} else if (obj instanceof BigInteger) {
ret = format(new BigFraction((BigInteger) obj), toAppendTo, pos);
} else if (obj instanceof Number) {
ret = format(new BigFraction(((Number) obj).doubleValue()),
toAppendTo, pos);
} else {
throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION);
}
return ret;
}
示例2: format
/**
* Formats an object and appends the result to a StringBuffer. <code>obj</code> must be either a
* {@link Fraction} object or a {@link Number} object. Any other type of
* object will result in an {@link IllegalArgumentException} being thrown.
*
* @param obj the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
* 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 FractionConversionException if the number cannot be converted to a fraction
* @throws MathIllegalArgumentException if <code>obj</code> is not a valid type.
*/
@Override
public StringBuffer format(final Object obj,
final StringBuffer toAppendTo, final FieldPosition pos)
throws FractionConversionException, MathIllegalArgumentException {
StringBuffer ret = null;
if (obj instanceof Fraction) {
ret = format((Fraction) obj, toAppendTo, pos);
} else if (obj instanceof Number) {
ret = format(new Fraction(((Number) obj).doubleValue()), toAppendTo, pos);
} else {
throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION);
}
return ret;
}