Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#CANNOT_FORMAT_OBJECT_TO_FRACTION

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#CANNOT_FORMAT_OBJECT_TO_FRACTION . 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: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: BigFractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: FractionFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}