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

public FormatterFactoryDemo() {
    super(new BorderLayout());
    setUpFormats();//  w ww .  j av a  2 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);
}

From source file:forge.util.FileSection.java

/**
 * Gets the double./*  w  ww.  ja va  2  s. c  o m*/
 *
 * @param fieldName the field name
 * @param defaultValue the default value
 * @return the int
 */
public double getDouble(final String fieldName, final double defaultValue) {
    try {
        if (this.get(fieldName) == null) {
            return defaultValue;
        }

        NumberFormat format = NumberFormat.getInstance(Locale.US);
        Number number = format.parse(this.get(fieldName));

        return number.doubleValue();
    } catch (final NumberFormatException | ParseException ex) {
        return defaultValue;
    }
}

From source file:io.crate.execution.engine.aggregation.impl.GeometricMeanAggregation.java

@Override
public GeometricMeanState iterate(RamAccountingContext ramAccountingContext, GeometricMeanState state,
        Input... args) throws CircuitBreakingException {
    if (state != null) {
        Number value = (Number) args[0].value();
        if (value != null) {
            state.addValue(value.doubleValue());
        }//w w  w .  j av a 2 s .  c o m
    }
    return state;
}

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

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

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

/**
 * Tests to see if the passed value is smaller than the stored minvalue.
 *
 * @param check  the number to check.//  w  ww  .  jav a2s . c om
 *
 * @return A boolean.
 */
public boolean isMinValue(Number check) {
    if (check.doubleValue() < this.minValue.doubleValue()) {
        return true;
    }
    return false;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedScatterRenderer.java

/**
 * This function is taken directly from JFreeChart with adjustments to draw differently colored
 * items.// ww  w  .  j a  v  a  2 s  .c  o m
 * 
 * When updating JFreeChart this function must probably be adapted.
 * 
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    ValueSourceToMultiValueCategoryDatasetAdapter dataSet = (ValueSourceToMultiValueCategoryDatasetAdapter) dataset;
    List values = dataSet.getValues(row, column);
    if (values == null) {
        return;
    }
    int valueCount = values.size();
    for (int i = 0; i < valueCount; i++) {
        // current data point...
        double x1;
        if (getUseSeriesOffset()) {
            x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow,
                    visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
        } else {
            x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
        }
        Number n = (Number) values.get(i);
        int idx = dataSet.getValueIndex(row, column, i);
        double value = n.doubleValue();
        double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, idx);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        if (getItemShapeFilled(row, column)) {
            if (getUseFillPaint()) {
                g2.setPaint(getItemFillPaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.fill(shape);
        }
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column));
            } else {
                g2.setPaint(getItemPaint(row, idx));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }
}

From source file:NumberRange.java

/**
 * <p>Tests whether the specified <code>number</code> occurs within
 * this range using <code>double</code> comparison.</p>
 *
 * @param number the number to test/* ww  w.ja v  a 2  s.  co m*/
 * @return <code>true</code> if the specified number occurs within this
 *  range; otherwise, <code>false</code>
 */
public boolean includesNumber(Number number) {
    if (number == null) {
        return false;
    } else {
        return !(min.doubleValue() > number.doubleValue()) && !(max.doubleValue() < number.doubleValue());
    }
}

From source file:au.org.ala.delta.translation.dist.DistItemsFileWriter.java

private double average(List<? extends Number> values) {
    int count = 0;
    double sum = 0;
    for (Number value : values) {
        count++;/*  w w w  . j a  v a  2 s . c  o m*/
        sum += value.doubleValue();
    }
    double average = sum / (double) count;
    return average;
}

From source file:de.codesourcery.flocking.ui.NumberInputField.java

private Double limitDouble(Number n) {
    final double value = n == null ? 0 : n.doubleValue();
    if (value < minValue) {
        return minValue;
    }/*from   ww w .  j  av  a 2s .  com*/
    if (value > maxValue) {
        return maxValue;
    }
    return value;
}

From source file:javadz.beanutils.locale.converters.DoubleLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type. This method will return Double type.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value//w ww.ja va2 s.  com
 *
 * @throws org.apache.commons.beanutils.ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
protected Object parse(Object value, String pattern) throws ParseException {
    Number result = (Number) super.parse(value, pattern);
    if (result instanceof Long) {
        return new Double(result.doubleValue());
    } else {
        return (result);
    }
}