Example usage for org.apache.commons.math3.exception NotANumberException NotANumberException

List of usage examples for org.apache.commons.math3.exception NotANumberException NotANumberException

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception NotANumberException NotANumberException.

Prototype

public NotANumberException() 

Source Link

Document

Construct the exception.

Usage

From source file:gda.data.scan.datawriter.scannablewriter.NumberComponentWriter.java

@Override
protected double[] getComponentSlab(final Object pos) {
    if (!(pos instanceof Number)) {
        throw new NotANumberException();
    }/*w  w  w . j  ava  2  s  . c om*/
    return new double[] { ((Number) pos).doubleValue() };
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

/**
 * Gets the value.//from w w w.  j a v a2s .c  om
 * 
 * @param node
 *          the node
 * @return the value
 * @throws NotANumberException
 *           if node is not a number-Node
 */
public static Number getNumberValue(final AbstractInsnNode node) throws NotANumberException {
    if (node == null) {
        throw new NotANumberException();
    }
    AbstractInsnNode checkNode = node;
    if (isCast(node)) {
        checkNode = node.getPrevious();
    }
    if (isIconst(checkNode)) {
        return cast(Integer.valueOf(checkNode.getOpcode() - Opcodes.ICONST_0), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.LCONST_0) {
        return cast(Long.valueOf(0), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.LCONST_1) {
        return cast(Long.valueOf(1), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.FCONST_0) {
        return cast(Float.valueOf(0), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.FCONST_1) {
        return cast(Float.valueOf(1), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.FCONST_2) {
        return cast(Float.valueOf(1), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.DCONST_0) {
        return cast(Double.valueOf(0), checkNode, node);
    }
    if (checkNode.getOpcode() == Opcodes.DCONST_1) {
        return cast(Double.valueOf(1), checkNode, node);
    }
    if (checkNode instanceof IntInsnNode) {
        return cast(Integer.valueOf(((IntInsnNode) checkNode).operand), checkNode, node);
    }
    return cast(getConstantValue(checkNode, Number.class), checkNode, node);
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

private static <T> T getConstantValue(final AbstractInsnNode node, final Class<T> clazz)
        throws NotANumberException {
    if (node == null) {
        throw new NotANumberException();
    }/*from   w ww  .jav a2 s .  c o  m*/
    if (node.getOpcode() == ACONST_NULL) {
        return null;
    }
    if (!(node instanceof LdcInsnNode)) {
        throw new NotANumberException();
    }
    try {
        final Object value = ((LdcInsnNode) node).cst;
        return clazz.cast(value);
    } catch (final ClassCastException cce) {
        throw new NotANumberException();
    }
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

/**
 * Gets the boolean value./*from   ww w  . ja va  2 s.c  om*/
 * 
 * @param node
 *          the node
 * @return the boolean value
 * @throws NotANumberException
 *           the not a number exception
 */
public static boolean getBooleanValue(final AbstractInsnNode node) throws NotANumberException {
    if (node == null) {
        throw new NotANumberException();
    }
    final Number numberValue = getNumberValue(node);
    if (numberValue == null) {
        throw new NotANumberException();
    }
    final int bool = numberValue.intValue();
    return Boolean.valueOf(bool == 1);
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

/**
 * Gets the char value./*from  w  w  w  .j a v  a 2 s .  c o  m*/
 * 
 * @param node
 *          the node
 * @return the char value
 * @throws NotANumberException
 *           the not a number exception
 */
public static char getCharValue(final AbstractInsnNode node) throws NotANumberException {
    if (node == null) {
        throw new NotANumberException();
    }
    final Number numberValue = getNumberValue(node);
    if (numberValue == null) {
        throw new NotANumberException();
    }
    final int charValue = numberValue.intValue();
    return Character.valueOf((char) charValue);
}

From source file:ummisco.gaml.extensions.maths.ode.utils.solver.Solver.java

public void solve(final IScope scope, final SystemOfEquationsStatement eq, final double initialTime,
        final double finalTime, final GamaMap<String, IList<Double>> integrationValues) {

    eq.executeInScope(scope, () -> {//from w w w .  j  a  v  a2 s  . c o m
        final Map<Integer, IAgent> equationAgents = eq.getEquationAgents(scope);
        /*
         * prepare initial value of variables 1. loop through variables expression 2. if its equaAgents != null, it
         * mean variable of external equation, set current scope to this agent scope 3. get value 4. return to
         * previous scope
         */

        final double[] y = new double[eq.variables_diff.size()];
        // final ArrayList<IExpression> equationValues = new
        // ArrayList<IExpression>(eq.variables_diff.values());
        int i = 0;
        final int n = eq.variables_diff.size();
        for (i = 0; i < n; i++) {
            final IAgent a = equationAgents.get(i);
            final String eqkeyname = a + eq.variables_diff.get(i).toString();
            if (integrationValues.get(eqkeyname) == null) {
                integrationValues.put(eqkeyname, GamaListFactory.create(Double.class));
            }
            if (!a.dead()) {
                final boolean pushed = scope.push(a);
                try {
                    y[i] = Cast.asFloat(scope, eq.variables_diff.get(i).value(scope));
                    if (Double.isInfinite(y[i])) {
                        GAMA.reportAndThrowIfNeeded(scope,
                                GamaRuntimeException.create(new NotANumberException(), scope), true);
                    }
                } catch (final Exception ex1) {
                    scope.getGui().debug(ex1.getMessage());
                } finally {
                    if (pushed) {
                        scope.pop(a);
                    }
                }
            }

        }
        if (integrationValues.get(scope.getAgent() + eq.variable_time.getName()) == null) {
            integrationValues.put(scope.getAgent() + eq.variable_time.getName(),
                    GamaListFactory.create(Double.class));
        }

        if (scope.getClock().getCycle() == 0) {
            storeValues(initialTime, y, integrationValues);
        }
        if (y.length > 0) {
            try {
                integrator.integrate(eq, initialTime, y, finalTime, y);
            } catch (final Exception ex) {
                DEBUG.ERR(ex.toString());
            }
        }
        eq.assignValue(scope, finalTime * step, y);
        storeValues(finalTime, y, integrationValues);
    });

}