Example usage for java.lang Number doubleValue

List of usage examples for java.lang Number doubleValue

Introduction

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

Prototype

public abstract double doubleValue();

Source Link

Document

Returns the value of the specified number as a double .

Usage

From source file:org.jfree.data.WaferMapDataset.java

/**
 * Tests to see if the passed value is larger than the stored maxvalue.
 * /* w  w  w . j  av  a 2  s . c  om*/
 * @param check
 *           the number to check.
 * @return true or false.
 */
public boolean isMaxValue(final Number check) {
    if (check.doubleValue() > this.maxValue.doubleValue()) {
        return true;
    }
    return false;
}

From source file:org.jfree.data.WaferMapDataset.java

/**
 * Tests to see if the passed value is smaller than the stored minvalue.
 * /*from  ww  w. j a va 2s.c  o m*/
 * @param check
 *           the number to check.
 * @return true or false.
 */
public boolean isMinValue(final Number check) {
    if (check.doubleValue() < this.minValue.doubleValue()) {
        return true;
    }
    return false;
}

From source file:com.arpnetworking.metrics.impl.ApacheHttpSinkTest.java

private static void assertSample(final List<ClientV2.MetricEntry> samples, final String name,
        final Number value, @Nullable final ClientV2.CompoundUnit compoundUnit) {

    final ClientV2.Quantity.Builder protobufSample = ClientV2.Quantity.newBuilder();
    if (value instanceof Double || value instanceof Float) {
        protobufSample.setDoubleValue(value.doubleValue());
    } else {//from www.  j  a v  a 2  s . c  o m
        protobufSample.setLongValue(value.longValue());
    }
    if (compoundUnit != null) {
        protobufSample.setUnit(compoundUnit);
    } else {
        protobufSample.setUnit(ClientV2.CompoundUnit.newBuilder().build());
    }

    Assert.assertTrue(
            String.format("Missing sample: name=%s, value=%s (%s)", name, value, value.getClass().getName()),
            samples.contains(ClientV2.MetricEntry.newBuilder().setName(name)
                    .addSamples(0, protobufSample.build()).build()));
}

From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java

/**
 * @param dataTypeClass//w w w  .  ja va  2  s  . c  o m
 * @param untypedValue
 * @return
 */
public static Object toDataType(Class<?> dataTypeClass, Object untypedValue) {
    if ((dataTypeClass == null) || (untypedValue == null)
            || ClassUtils.isAssignable(untypedValue.getClass(), dataTypeClass)) {
        if (Date.class == dataTypeClass) {
            return DateUtils.truncate(untypedValue, Calendar.DATE);
        }

        return untypedValue;
    }

    Object v = null;

    String strUntypedValue = null;
    boolean isStringUntypedValue = untypedValue instanceof String;

    Number numUntypedValue = null;
    boolean isNumberUntypedValue = untypedValue instanceof Number;

    if (isStringUntypedValue) {
        strUntypedValue = (String) untypedValue;
    }

    if (isNumberUntypedValue) {
        numUntypedValue = (Number) untypedValue;
    }

    if (dataTypeClass == boolean.class || dataTypeClass == Boolean.class) {
        if (isNumberUntypedValue) {
            v = BooleanUtils.toBooleanObject(numUntypedValue.intValue());
        } else if (isStringUntypedValue) {
            v = BooleanUtils.toBooleanObject(strUntypedValue);
        }
    } else if (dataTypeClass == Integer.class) {
        if (isNumberUntypedValue) {
            v = new Integer(numUntypedValue.intValue());
        } else if (isStringUntypedValue) {
            v = NumberUtils.createInteger(strUntypedValue);
        }
    } else if (dataTypeClass == Double.class) {
        if (isNumberUntypedValue) {
            v = new Double(numUntypedValue.doubleValue());
        } else if (isStringUntypedValue) {
            v = NumberUtils.createDouble(strUntypedValue);
        }
    } else if (dataTypeClass == Date.class) {
        if (isNumberUntypedValue) {
            v = DateUtils.truncate(new Date(numUntypedValue.longValue()), Calendar.DATE);
        }
    } else {
        v = ObjectUtils.toString(untypedValue);
    }

    return v;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.ExcelExportServiceImpl.java

private void setPropertyValue(Row row, int colNo, Object value) {
    if (value == null) {
        return;//  w  w  w.j a  va  2 s . c o  m
    }
    Cell cell = ExcelUtils.getOrCreateCell(row, colNo);

    if (value instanceof Number) {
        Number n = (Number) value;
        cell.setCellValue(n.doubleValue());
    } else if (value instanceof Date) {
        Date date = (Date) value;
        cell.setCellValue(date);
    } else if (value instanceof EnumerationLiteralExpression) {
        EnumerationLiteralExpression literal = (EnumerationLiteralExpression) value;
        cell.setCellValue(String.valueOf(literal.getPersistentName()));
    } else {
        cell.setCellValue(String.valueOf(value));
    }
}

From source file:com.opengamma.engine.view.NumberDeltaComparer.java

@Override
public boolean isDelta(Number previousValue, Number newValue) {
    if (previousValue == null && newValue == null) {
        return false;
    }/*from  w  ww  .  j a  v a 2 s.c o m*/
    if (previousValue == null || newValue == null) {
        return true;
    }

    long previousCompare = (long) (previousValue.doubleValue() * _multiplier);
    long newCompare = (long) (newValue.doubleValue() * _multiplier);
    return previousCompare != newCompare;
}

From source file:gate.termraider.bank.AbstractTermbank.java

private void findMinAndMaxDefaultScores() {
    Collection<Number> values = this.getDefaultScores().values();
    if (values.isEmpty()) {
        minDefaultScore = new Integer(0);
        maxDefaultScore = new Integer(1);
    } else {/* w  w w  .j a v a2 s . c om*/
        minDefaultScore = values.iterator().next();
        maxDefaultScore = values.iterator().next();
        for (Number n : values) {
            if (n.doubleValue() < minDefaultScore.doubleValue()) {
                minDefaultScore = n;
            }

            if (n.doubleValue() > maxDefaultScore.doubleValue()) {
                maxDefaultScore = n;
            }
        }
    }
}

From source file:com.cedarsoft.serialization.jackson.NumberSerializer.java

@Override
public void serialize(@Nonnull JsonGenerator serializeTo, @Nonnull Number object,
        @Nonnull Version formatVersion) throws IOException, VersionException, JsonProcessingException {
    if (isIntegerNumber(object)) {
        serializeTo.writeNumber(object.longValue());
    } else {//w  w w.j  a  v a2 s  .c  o m
        serializeTo.writeNumber(object.doubleValue());
    }
}

From source file:net.sourceforge.jabm.init.RandomVariateInitialiser.java

protected void fireEvent(String variableName, Number value) {
    if (eventScheduler != null) {
        eventScheduler.fireEvent(new RandomVariateInitialisedEvent(variableName, value.doubleValue()));
    }// w  w w  .  j ava 2  s.  co m
}

From source file:FormatterFactoryDemo.java

public FormatterFactoryDemo() {
    super(new BorderLayout());
    setUpFormats();/*from w ww . j  a v a2  s  . c o m*/
    double payment = computePayment(amount, rate, numPeriods);

    //Create the labels.
    amountLabel = new JLabel(amountString);
    rateLabel = new JLabel(rateString);
    numPeriodsLabel = new JLabel(numPeriodsString);
    paymentLabel = new JLabel(paymentString);

    //Create the text fields and set them up.
    amountField = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(amountDisplayFormat),
            new NumberFormatter(amountDisplayFormat), new NumberFormatter(amountEditFormat)));
    amountField.setValue(new Double(amount));
    amountField.setColumns(10);
    amountField.addPropertyChangeListener("value", this);

    NumberFormatter percentEditFormatter = new NumberFormatter(percentEditFormat) {
        public String valueToString(Object o) throws ParseException {
            Number number = (Number) o;
            if (number != null) {
                double d = number.doubleValue() * 100.0;
                number = new Double(d);
            }
            return super.valueToString(number);
        }

        public Object stringToValue(String s) throws ParseException {
            Number number = (Number) super.stringToValue(s);
            if (number != null) {
                double d = number.doubleValue() / 100.0;
                number = new Double(d);
            }
            return number;
        }
    };
    rateField = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(percentDisplayFormat),
            new NumberFormatter(percentDisplayFormat), percentEditFormatter));
    rateField.setValue(new Double(rate));
    rateField.setColumns(10);
    rateField.addPropertyChangeListener("value", this);

    numPeriodsField = new JFormattedTextField();
    numPeriodsField.setValue(new Integer(numPeriods));
    numPeriodsField.setColumns(10);
    numPeriodsField.addPropertyChangeListener("value", this);

    paymentField = new JFormattedTextField(paymentFormat);
    paymentField.setValue(new Double(payment));
    paymentField.setColumns(10);
    paymentField.setEditable(false);
    paymentField.setForeground(Color.red);

    //Tell accessibility tools about label/textfield pairs.
    amountLabel.setLabelFor(amountField);
    rateLabel.setLabelFor(rateField);
    numPeriodsLabel.setLabelFor(numPeriodsField);
    paymentLabel.setLabelFor(paymentField);

    //Lay out the labels in a panel.
    JPanel labelPane = new JPanel(new GridLayout(0, 1));
    labelPane.add(amountLabel);
    labelPane.add(rateLabel);
    labelPane.add(numPeriodsLabel);
    labelPane.add(paymentLabel);

    //Layout the text fields in a panel.
    JPanel fieldPane = new JPanel(new GridLayout(0, 1));
    fieldPane.add(amountField);
    fieldPane.add(rateField);
    fieldPane.add(numPeriodsField);
    fieldPane.add(paymentField);

    //Put the panels in this panel, labels on left,
    //text fields on right.
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    add(labelPane, BorderLayout.CENTER);
    add(fieldPane, BorderLayout.LINE_END);
}