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:com.mobicage.rogerthat.plugins.messaging.widgets.SingleSliderWidget.java

@Override
public FloatWidgetResultTO getWidgetResult() {
    FloatWidgetResultTO r = new FloatWidgetResultTO();
    Number value = (Number) mWidgetMap.get("value");
    r.value = value.floatValue();
    return r;// w w  w  .  j  av a2s  . c o m
}

From source file:com.glaf.core.util.GetterUtils.java

public static float get(Object value, float defaultValue) {
    if (value == null) {
        return defaultValue;
    }//  w  ww.ja  v a2  s . co m

    if (value instanceof String) {
        return get((String) value, defaultValue);
    }

    Class<?> clazz = value.getClass();

    if (Float.class.isAssignableFrom(clazz)) {
        return (Float) value;
    }

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

        return number.floatValue();
    }

    return defaultValue;
}

From source file:com.haulmont.cuba.gui.backgroundwork.BackgroundWorkProgressWindow.java

protected void showProgress(Number processedValue) {
    float value = processedValue.floatValue() / totalProgress.floatValue();

    taskProgressBar.setValue(value);// w w w  .  j  ava2s . com

    if (!percentProgress) {
        progressText.setValue(
                formatMessage("backgroundWorkProgress.progressTextFormat", processedValue, totalProgress));
    } else {
        int percentValue = (int) Math.ceil(value * 100);
        progressText.setValue(formatMessage("backgroundWorkProgress.progressPercentFormat", percentValue));
    }
}

From source file:org.webguitoolkit.ui.controls.util.conversion.SelectFloatConverter.java

/**
 * does the actualyy pparsing into the target type, you ca
 * override this method to parse into other type.
 * Note this is neccessary because of a bug in BeanUtils, which will be solved with
 * version 1.8.0 when it is released./*from w ww  .  j  a v  a2s  .c  o m*/
 * @param textRep
 * @return
 * @throws ParseException
 */
protected Object parse2Type(String textRep) throws ParseException {
    Number num = formatter.parse(textRep);
    if (num instanceof Float)
        return num;

    return new Float(num.floatValue());
}

From source file:org.caleydo.core.view.opengl.layout2.manage.GLElementFactoryContext.java

public float getFloat(String key, float default_) {
    Number r = get(key, Number.class, default_);
    return r == null ? default_ : r.floatValue();
}

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

private static AbstractInsnNode getFloatInsnNode(final Number newNumber) {
    if (newNumber.longValue() == 0) {
        return new InsnNode(Opcodes.FCONST_0);
    } else if (newNumber.floatValue() == 1) {
        return new InsnNode(Opcodes.FCONST_1);
    } else if (newNumber.floatValue() == 2) {
        return new InsnNode(Opcodes.FCONST_2);
    } else {/*from   w ww.j av  a2  s.c  om*/
        return new LdcInsnNode(newNumber);
    }
}

From source file:org.batoo.common.reflect.ReflectHelper.java

/**
 * Converts the number into number Type//w  w  w.  java  2 s.  c  o  m
 * 
 * @param value
 *            the number value
 * @param numberType
 *            the number type
 * @return the converted number value
 * 
 * @since 2.0.1
 */
public static Number convertNumber(Number value, Class<?> numberType) {
    if (value == null) {
        return null;
    }

    if (numberType.isAssignableFrom(value.getClass())) {
        return value;
    }

    if ((numberType == Integer.class) || (numberType == Integer.TYPE)) {
        return value.intValue();
    }

    if ((numberType == Long.class) || (numberType == Long.TYPE)) {
        return value.longValue();
    }

    if ((numberType == Short.class) || (numberType == Short.TYPE)) {
        return value.shortValue();
    }

    if ((numberType == Byte.class) || (numberType == Byte.TYPE)) {
        return value.byteValue();
    }

    if ((numberType == Float.class) || (numberType == Float.TYPE)) {
        return value.floatValue();
    }

    if ((numberType == Double.class) || (numberType == Double.TYPE)) {
        return value.doubleValue();
    }

    if (numberType == BigDecimal.class) {
        return BigDecimal.valueOf(value.doubleValue());
    }

    if (numberType == BigInteger.class) {
        return BigInteger.valueOf(value.longValue());
    }

    throw new IllegalArgumentException(numberType + " not supported");
}

From source file:org.amanzi.awe.statistics.ui.table.StatisticsLabelProvider.java

@Override
public String getColumnText(final Object element, int columnIndex) {
    if (columnIndex == 0) {
        return StringUtils.EMPTY;
    } else {//from  w w  w . j av a 2s.co  m
        columnIndex--;
    }

    if (element instanceof IStatisticsRow) {
        final IStatisticsRow statisticsRow = (IStatisticsRow) element;

        if (!statisticsRow.equals(previousRow)) {
            initializeCellList(statisticsRow);

            previousRow = statisticsRow;
        }

        switch (columnIndex) {
        case 0:
            return statisticsRow.getStatisticsGroup().getPropertyValue();
        case 1:
            return getStatisticsRowName(statisticsRow);
        default:
            final Number value = cellList.get(columnIndex - 2).getValue();
            if (value != null) {
                final float floatValue = value.floatValue();
                final BigDecimal bd = new BigDecimal(floatValue).setScale(DECIMAL_SIZE, RoundingMode.HALF_EVEN);
                return bd.toString();
            }
        }
    }

    return StringUtils.EMPTY;
}

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 *
 * @param number      the number to convert
 * @param targetClass the target class to convert to
 * @return the converted number//from ww w  .  ja v a  2 s . c o  m
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte
 * @see java.lang.Short
 * @see java.lang.Integer
 * @see java.lang.Long
 * @see java.math.BigInteger
 * @see java.lang.Float
 * @see java.lang.Double
 * @see java.math.BigDecimal
 */
public static Number convertNumberToTargetClass(Number number, Class targetClass)
        throws IllegalArgumentException {

    if (targetClass.isInstance(number)) {
        return number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return 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 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 number.intValue();
    } else if (targetClass.equals(Long.class)) {
        return number.longValue();
    } else if (targetClass.equals(Float.class)) {
        return number.floatValue();
    } else if (targetClass.equals(Double.class)) {
        return number.doubleValue();
    } else if (targetClass.equals(BigInteger.class)) {
        return BigInteger.valueOf(number.longValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return 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:net.myrrix.common.collection.FastByIDFloatMapTest.java

@Test
public void testVersusHashMap() {
    FastByIDFloatMap actual = new FastByIDFloatMap();
    Map<Long, Float> expected = Maps.newHashMapWithExpectedSize(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
        double d = r.nextDouble();
        Long key = (long) r.nextInt(100);
        if (d < 0.4) {
            Number expectedValue = expected.get(key);
            float actualValue = actual.get(key);
            if (expectedValue == null) {
                assertNaN(actualValue);/*from w  w w .ja  va2 s  .co  m*/
            } else {
                assertEquals(expectedValue.floatValue(), actualValue);
            }
        } else {
            if (d < 0.7) {
                expected.put(key, 3.0f);
                actual.put(key, 3.0f);
            } else {
                expected.remove(key);
                actual.remove(key);
            }
            assertEquals(expected.size(), actual.size());
            assertEquals(expected.isEmpty(), actual.isEmpty());
        }
    }
}