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:MutableFloat.java

/**
 * Adds a value./*from w  w w .  j  a  v  a  2s.  c  o m*/
 * 
 * @param operand
 *            the value to add
 * @throws NullPointerException
 *             if the object is null
 *
 * @since Commons Lang 2.2
 */
public void add(Number operand) {
    this.value += operand.floatValue();
}

From source file:MutableFloat.java

/**
 * Subtracts a value./*from   w  ww .j a  v a 2 s. c o  m*/
 * 
 * @param operand
 *            the value to add
 * @throws NullPointerException
 *             if the object is null
 *
 * @since Commons Lang 2.2
 */
public void subtract(Number operand) {
    this.value -= operand.floatValue();
}

From source file:com.cloudera.oryx.common.collection.LongFloatMapTest.java

@Test
public void testVersusHashMap() {
    LongFloatMap actual = new LongFloatMap();
    Map<Long, Float> expected = Maps.newHashMap();
    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 .  j  av a 2  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());
        }
    }
}

From source file:MutableFloat.java

/**
 * Constructs a new MutableFloat with the specified value.
 * //from   w w w. j  ava2s . c o m
 * @param value
 *            a value.
 * @throws NullPointerException
 *             if the object is null
 */
public MutableFloat(Number value) {
    super();
    this.value = value.floatValue();
}

From source file:cz.cvut.kbss.jsonld.jackson.serialization.JacksonJsonWriter.java

@Override
public void writeNumber(Number number) throws IOException {
    if (number instanceof Integer) {
        jsonGenerator.writeNumber(number.intValue());
    } else if (number instanceof Long) {
        jsonGenerator.writeNumber(number.longValue());
    } else if (number instanceof Float) {
        jsonGenerator.writeNumber(number.floatValue());
    } else if (number instanceof Double) {
        jsonGenerator.writeNumber(number.doubleValue());
    } else if (number instanceof BigInteger) {
        jsonGenerator.writeNumber((BigInteger) number);
    } else if (number instanceof BigDecimal) {
        jsonGenerator.writeNumber((BigDecimal) number);
    } else if (number instanceof Short) {
        jsonGenerator.writeNumber(number.shortValue());
    } else if (number instanceof Byte) {
        jsonGenerator.writeNumber(number.byteValue());
    } else {/*from  www.  ja  v a 2s.c om*/
        throw new IllegalArgumentException(
                "Unable to write number " + number + " of type " + number.getClass());
    }
}

From source file:org.apache.fontbox.cff.Type1CharString.java

/**
 * Sets the current absolute point without performing a moveto.
 * Used only with results from callothersubr
 *//*from   w w  w  . j a  v  a 2  s . c  om*/
private void setcurrentpoint(Number x, Number y) {
    current.setLocation(x.floatValue(), y.floatValue());
}

From source file:net.sf.mzmine.modules.visualization.msms.MsMsPlot.java

@Override
public void mouseClicked(final MouseEvent event) {

    // Let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    if (event.getX() < 70) { // User clicked on Y-axis
        if (event.getClickCount() == 2) { // Reset zoom on Y-axis
            XYDataset data = ((XYPlot) getChart().getPlot()).getDataset();
            Number maximum = DatasetUtils.findMaximumRangeValue(data);
            getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue());
        } else if (event.getClickCount() == 1) {
            // Auto range on Y-axis
            getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            getXYPlot().getRangeAxis().setAutoRange(true);
        }//from  ww  w .j  av  a2s  .com
    } else if (event.getY() > this.getChartRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41
            && event.getClickCount() == 2) {
        // Reset zoom on X-axis
        getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        restoreAutoDomainBounds();
    } else if (event.getClickCount() == 2) {
        visualizer.actionPerformed(
                new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, "SHOW_SPECTRUM"));
    }
}

From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java

@Override
public void mouseClicked(final MouseEvent event) {

    // Let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    if (event.getX() < 70) { // User clicked on Y-axis
        if (event.getClickCount() == 2) { // Reset zoom on Y-axis
            XYDataset data = ((XYPlot) getChart().getPlot()).getDataset();
            Number maximum = DatasetUtilities.findMaximumRangeValue(data);
            getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue());
        } else if (event.getClickCount() == 1) {
            // Auto range on Y-axis
            getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            getXYPlot().getRangeAxis().setAutoRange(true);
        }//from ww  w . ja v a 2s .c o  m
    } else if (event.getY() > this.getChartRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41
            && event.getClickCount() == 2) {
        // Reset zoom on X-axis
        getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        restoreAutoDomainBounds();
    } else if (event.getClickCount() == 2) {
        visualizer.actionPerformed(
                new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, "SHOW_SPECTRUM"));
    }
}

From source file:org.qi4j.runtime.types.NumberType.java

public Object fromJSON(Object json, Module module) {
    if (json == JSONObject.NULL) {
        return null;
    }//from w  w w. jav a  2  s .  c  o m
    if (type.isClass(BigDecimal.class)) {
        return new BigDecimal("" + json);
    } else if (type.isClass(BigInteger.class)) {
        return new BigInteger("" + json);
    }
    Number number = (Number) json;

    if (type.isClass(Integer.class)) {
        return number.intValue();
    } else if (type.isClass(Long.class)) {
        return number.longValue();
    } else if (type.isClass(Double.class)) {
        return number.doubleValue();
    } else if (type.isClass(Float.class)) {
        return number.floatValue();
    } else if (type.isClass(Short.class)) {
        return number.shortValue();
    } else if (type.isClass(Byte.class)) {
        return number.byteValue();
    }

    throw new IllegalStateException("Unknown number type:" + type);
}

From source file:com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype.java

protected Number requestedType(Number number) {
    if (type.equals(Integer.class))
        return number.intValue();
    if (type.equals(Long.class))
        return number.longValue();
    if (type.equals(Double.class))
        return number.doubleValue();
    if (type.equals(Float.class))
        return number.floatValue();
    return number;
}