Example usage for java.lang Number floatValue

List of usage examples for java.lang Number floatValue

Introduction

In this page you can find the example usage for java.lang Number floatValue.

Prototype

public abstract float floatValue();

Source Link

Document

Returns the value of the specified number as a float .

Usage

From source file:org.polymap.core.runtime.recordstore.lucene.NumericValueCoder.java

public Query searchQuery(QueryExpression exp) {
    // EQUALS//from  www. j  a v  a  2s .c  om
    if (exp instanceof QueryExpression.Equal) {
        Equal equalExp = (QueryExpression.Equal) exp;

        if (equalExp.value instanceof Number) {
            String key = equalExp.key;
            Number value = (Number) equalExp.value;

            if (equalExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, value.intValue(), value.intValue(), true, true);
            } else if (equalExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, value.longValue(), value.longValue(), true, true);
            } else if (equalExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, value.floatValue(), value.floatValue(), true, true);
            } else if (equalExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), value.doubleValue(), true,
                        true);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    }
    // GREATER
    else if (exp instanceof QueryExpression.Greater) {
        Greater greaterExp = (QueryExpression.Greater) exp;

        if (greaterExp.value instanceof Number) {
            String key = greaterExp.key;
            Number value = (Number) greaterExp.value;

            if (greaterExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, value.intValue(), null, false, false);
            } else if (greaterExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, value.longValue(), null, false, false);
            } else if (greaterExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, false, false);
            } else if (greaterExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, false, false);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    }
    // GREATER OR EQUAL
    else if (exp instanceof QueryExpression.GreaterOrEqual) {
        GreaterOrEqual greaterExp = (QueryExpression.GreaterOrEqual) exp;

        if (greaterExp.value instanceof Number) {
            String key = greaterExp.key;
            Number value = (Number) greaterExp.value;

            if (greaterExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, value.intValue(), null, true, false);
            } else if (greaterExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, value.longValue(), null, true, false);
            } else if (greaterExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, value.floatValue(), null, true, false);
            } else if (greaterExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, value.doubleValue(), null, true, false);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    }
    // LESS
    else if (exp instanceof QueryExpression.Less) {
        Less lessExp = (QueryExpression.Less) exp;

        if (lessExp.value instanceof Number) {
            String key = lessExp.key;
            Number value = (Number) lessExp.value;

            if (lessExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, false);
            } else if (lessExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, false);
            } else if (lessExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, false);
            } else if (lessExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, false);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    }
    // LESS or equal
    else if (exp instanceof QueryExpression.LessOrEqual) {
        LessOrEqual lessExp = (QueryExpression.LessOrEqual) exp;

        if (lessExp.value instanceof Number) {
            String key = lessExp.key;
            Number value = (Number) lessExp.value;

            if (lessExp.value instanceof Integer) {
                return NumericRangeQuery.newIntRange(key, null, value.intValue(), false, true);
            } else if (lessExp.value instanceof Long) {
                return NumericRangeQuery.newLongRange(key, null, value.longValue(), false, true);
            } else if (lessExp.value instanceof Float) {
                return NumericRangeQuery.newFloatRange(key, null, value.floatValue(), false, true);
            } else if (lessExp.value instanceof Double) {
                return NumericRangeQuery.newDoubleRange(key, null, value.doubleValue(), false, true);
            } else {
                throw new RuntimeException("Unknown Number type: " + value.getClass());
            }
        }
    }
    // MATCHES
    else if (exp instanceof QueryExpression.Match) {
        Match matchExp = (Match) exp;

        if (matchExp.value instanceof Number) {
            throw new UnsupportedOperationException("MATCHES not supported for Number values.");
        }
    }
    return null;
}

From source file:net.jofm.format.NumberFormat.java

private Object convert(Number result, Class<?> destinationClazz) {
    if (destinationClazz.equals(BigDecimal.class)) {
        return new BigDecimal(result.doubleValue());
    }//from  www .  j a  v a  2  s. c  o m
    if (destinationClazz.equals(Short.class) || destinationClazz.equals(short.class)) {
        return new Short(result.shortValue());
    }
    if (destinationClazz.equals(Integer.class) || destinationClazz.equals(int.class)) {
        return new Integer(result.intValue());
    }
    if (destinationClazz.equals(Long.class) || destinationClazz.equals(long.class)) {
        return new Long(result.longValue());
    }
    if (destinationClazz.equals(Float.class) || destinationClazz.equals(float.class)) {
        return new Float(result.floatValue());
    }
    if (destinationClazz.equals(Double.class) || destinationClazz.equals(double.class)) {
        return new Double(result.doubleValue());
    }

    throw new FixedMappingException("Unable to parse the data to type " + destinationClazz.getName() + " using "
            + this.getClass().getName());
}

From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java

@Override
public IComplexNumber rdivi(Number v, IComplexNumber result) {
    float d = realComponent().floatValue() * realComponent().floatValue()
            + imaginaryComponent().floatValue() * imaginaryComponent().floatValue();
    return result.set(v.floatValue() * realComponent().floatValue() / d,
            -v.floatValue() * imaginaryComponent().floatValue() / d);
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInliner.java

private Number calculateOparator(final AbstractInsnNode node1, final Number op1, final Number op2) {
    Number newNumber = op1;//from w w  w  .  jav  a 2s .co  m
    if (isCompare(node1)) {
        switch (node1.getOpcode()) {
        case Opcodes.DCMPG:
        case Opcodes.DCMPL:
            newNumber = Double.valueOf(op2.doubleValue() - op1.doubleValue());
            break;
        case Opcodes.FCMPG:
        case Opcodes.FCMPL:
            newNumber = Float.valueOf(op2.floatValue() - op1.floatValue());
            break;
        case Opcodes.LCMP:
            newNumber = Long.valueOf(op2.longValue() - op1.longValue());
            break;
        default:
            newNumber = op1;
        }
    }
    return newNumber;
}

From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java

@Override
public IComplexNumber set(Number real, Number imag) {
    super.set(real.floatValue(), imag.floatValue());
    return this;
}

From source file:org.richfaces.renderkit.AbstractProgressBarRenderer.java

/**
 * Converts value attr to number value/*  ww  w. j ava 2  s.c  o  m*/
 * 
 * @param v -
 *            value attr
 * @return result
 */
public Number getNumber(Object v) {
    Number result = null;
    if (v != null) {
        try {
            if (v instanceof String) {
                result = Double.parseDouble((String) v);
            } else {
                Number n = (Number) v;
                if (n instanceof BigDecimal || n instanceof Double || n instanceof Float) {
                    result = n.floatValue();
                } else if (n instanceof Integer || n instanceof Long) {
                    result = n.longValue();
                }
            }
        } catch (Exception e) {
            // no action
        }
        return result;
    }
    return new Integer(0);
}

From source file:com.krawler.br.nodes.Activity.java

/**
 * converts the given object value to the given primitive type's wrapper class
 * if possible (if it is a <tt>Number</tt>)
 *
 * @param type the premitive type name, may be:
 * <ul>/*from w ww. j a va2s .com*/
 * <li><tt>byte</tt>
 * <li><tt>char</tt>
 * <li><tt>short</tt>
 * <li><tt>int</tt>
 * <li><tt>long</tt>
 * <li><tt>float</tt>
 * <li><tt>double</tt>
 * </ul>
 * @param value the original value
 * @return the converted value
 */
private Object convert(String type, Object value) {
    Object val = value;

    if (value instanceof Number) {
        Number num = (Number) value;

        if (Byte.class.getCanonicalName().equals(type))
            val = new Byte(num.byteValue());
        else if (Character.class.getCanonicalName().equals(type))
            val = new Character((char) num.intValue());
        else if (Short.class.getCanonicalName().equals(type))
            val = new Short(num.shortValue());
        else if (Integer.class.getCanonicalName().equals(type))
            val = new Integer(num.intValue());
        else if (Long.class.getCanonicalName().equals(type))
            val = new Long(num.longValue());
        else if (Float.class.getCanonicalName().equals(type))
            val = new Float(num.floatValue());
        else if (Double.class.getCanonicalName().equals(type))
            val = new Double(num.doubleValue());
    }
    return val;
}

From source file:org.camunda.spin.impl.json.jackson.JacksonJsonNode.java

public SpinJsonNode prop(String name, Number newProperty) {
    ObjectNode node = (ObjectNode) jsonNode;

    // Numbers magic because Jackson has no native .put(Number value)
    if (newProperty instanceof Long) {
        node.put(name, newProperty.longValue());
    } else if (newProperty instanceof Integer) {
        node.put(name, newProperty.intValue());
    } else if (newProperty instanceof Float) {
        node.put(name, newProperty.floatValue());
    } else {/*w ww.ja v a 2s .com*/
        // convert any other sub class of Number into Float
        node.put(name, newProperty.floatValue());
    }

    return this;
}

From source file:org.mule.util.NumberUtils.java

@SuppressWarnings("unchecked")
public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass)
        throws IllegalArgumentException {

    if (targetClass.isInstance(number)) {
        return (T) number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }//from   ww w.  j a  va  2 s . co m
        return (T) new Byte(number.byteValue());
    } else if (targetClass.equals(Short.class)) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Short(number.shortValue());
    } else if (targetClass.equals(Integer.class)) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Integer(number.intValue());
    } else if (targetClass.equals(Long.class)) {
        return (T) new Long(number.longValue());
    } else if (targetClass.equals(BigInteger.class)) {
        if (number instanceof BigDecimal) {
            // do not lose precision - use BigDecimal's own conversion
            return (T) ((BigDecimal) number).toBigInteger();
        } else {
            // original value is not a Big* number - use standard long conversion
            return (T) BigInteger.valueOf(number.longValue());
        }
    } else if (targetClass.equals(Float.class)) {
        return (T) new Float(number.floatValue());
    } else if (targetClass.equals(Double.class)) {
        return (T) new Double(number.doubleValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // always use BigDecimal(String) here to avoid unpredictability of
        // BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return (T) new BigDecimal(number.toString());
    } else {
        throw new IllegalArgumentException("Could not convert number [" + number + "] of type ["
                + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]");
    }
}

From source file:org.nd4j.linalg.cpu.complex.ComplexFloat.java

@Override
public IComplexNumber subi(Number a, IComplexNumber result) {
    return result.set(result.realComponent().floatValue() - a.floatValue(),
            result.imaginaryComponent().floatValue());
}