Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#OBJECT_TRANSFORMATION

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#OBJECT_TRANSFORMATION . 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: DefaultTransformer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param o  the object that gets transformed.
 * @return a double primitive representation of the Object o.
 * @throws MathException if it cannot successfully be transformed.
 * @throws NullArgumentException if is {@code null}.
 * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html">Commons Collections Transformer</a>
 */
public double transform(Object o) throws MathException {
    if (o == null) {
        throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION);
    }

    if (o instanceof Number) {
        return ((Number)o).doubleValue();
    }

    try {
        return Double.valueOf(o.toString()).doubleValue();
    } catch (NumberFormatException e) {
        throw new MathException(e,
                                LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, e.getMessage());
    }
}
 
Example 2
Source File: DefaultTransformer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param o  the object that gets transformed.
 * @return a double primitive representation of the Object o.
 * @throws MathException if it cannot successfully be transformed.
 * @throws NullArgumentException if is {@code null}.
 * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html"/>
 */
public double transform(Object o) throws MathException {
    if (o == null) {
        throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION);
    }

    if (o instanceof Number) {
        return ((Number)o).doubleValue();
    }

    try {
        return Double.valueOf(o.toString()).doubleValue();
    } catch (NumberFormatException e) {
        throw new MathException(e,
                                LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, e.getMessage());
    }
}
 
Example 3
Source File: DefaultTransformer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param o  the object that gets transformed.
 * @return a double primitive representation of the Object o.
 * @throws MathException if it cannot successfully be transformed.
 * @throws NullArgumentException if is {@code null}.
 * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html">Commons Collections Transformer</a>
 */
public double transform(Object o) throws MathException {
    if (o == null) {
        throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION);
    }

    if (o instanceof Number) {
        return ((Number)o).doubleValue();
    }

    try {
        return Double.valueOf(o.toString()).doubleValue();
    } catch (NumberFormatException e) {
        throw new MathException(e,
                                LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, e.getMessage());
    }
}
 
Example 4
Source File: DefaultTransformer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param o  the object that gets transformed.
 * @return a double primitive representation of the Object o.
 * @throws MathException if it cannot successfully be transformed.
 * @throws NullArgumentException if is {@code null}.
 * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html">Commons Collections Transformer</a>
 */
public double transform(Object o) throws MathException {
    if (o == null) {
        throw new NullArgumentException(LocalizedFormats.OBJECT_TRANSFORMATION);
    }

    if (o instanceof Number) {
        return ((Number)o).doubleValue();
    }

    try {
        return Double.valueOf(o.toString()).doubleValue();
    } catch (NumberFormatException e) {
        throw new MathException(e,
                                LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, e.getMessage());
    }
}