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.esa.snap.rcp.statistics.ProfilePlotPanel.java

private void updateDataSet() {
    if (!isInitialized) {
        return;//from   w w  w.  j a v  a  2  s  .  com
    }

    dataset.removeAllSeries();

    double dx = 0.5 * dataSourceConfig.boxSize;

    if (profileData != null) {
        final float[] sampleValues = profileData.getSampleValues();
        final float[] sampleSigmas = profileData.getSampleSigmas();
        XYIntervalSeries series = new XYIntervalSeries(
                getRaster() != null ? getRaster().getName() : DEFAULT_SAMPLE_DATASET_NAME);
        for (int x = 0; x < sampleValues.length; x++) {
            final float y = sampleValues[x];
            final float dy = sampleSigmas[x];
            series.add(x, x - dx, x + dx, y, y - dy, y + dy);
        }
        dataset.addSeries(series);

        if (dataSourceConfig.useCorrelativeData && dataSourceConfig.pointDataSource != null
                && dataSourceConfig.dataField != null) {

            XYIntervalSeries corrSeries = new XYIntervalSeries(StatisticChartStyling
                    .getCorrelativeDataLabel(dataSourceConfig.pointDataSource, dataSourceConfig.dataField));
            int[] shapeVertexIndexes = profileData.getShapeVertexIndexes();
            SimpleFeature[] simpleFeatures = dataSourceConfig.pointDataSource.getFeatureCollection()
                    .toArray(new SimpleFeature[0]);

            if (shapeVertexIndexes.length == simpleFeatures.length) {
                int fieldIndex = getAttributeIndex(dataSourceConfig.pointDataSource,
                        dataSourceConfig.dataField);
                if (fieldIndex != -1) {
                    for (int i = 0; i < simpleFeatures.length; i++) {
                        Number attribute = (Number) simpleFeatures[i].getAttribute(fieldIndex);
                        if (attribute != null) {
                            final double x = shapeVertexIndexes[i];
                            final double y = attribute.doubleValue();
                            corrSeries.add(x, x, x, y, y, y);
                        }
                    }
                    dataset.addSeries(corrSeries);
                }
            } else {
                System.out.println("Weird things happened:");
                System.out.println("  shapeVertexIndexes.length = " + shapeVertexIndexes.length);
                System.out.println("  simpleFeatures.length     = " + simpleFeatures.length);
            }

        }

        profilePlotDisplay.restoreAutoBounds();
        xAxisRangeControl.getBindingContext().setComponentsEnabled(PROPERTY_NAME_MARK_SEGMENTS,
                profileData.getShapeVertices().length > 2);
    }
}

From source file:org.esa.beam.visat.toolviews.stat.ProfilePlotPanel.java

private void updateDataSet() {
    if (!isInitialized) {
        return;//from  ww w  . ja v  a  2s.c  o m
    }

    dataset.removeAllSeries();

    double dx = 0.5 * dataSourceConfig.boxSize;

    if (profileData != null) {
        final float[] sampleValues = profileData.getSampleValues();
        final float[] sampleSigmas = profileData.getSampleSigmas();
        XYIntervalSeries series = new XYIntervalSeries(
                getRaster() != null ? getRaster().getName() : DEFAULT_SAMPLE_DATASET_NAME);
        for (int x = 0; x < sampleValues.length; x++) {
            final float y = sampleValues[x];
            final float dy = sampleSigmas[x];
            series.add(x, x - dx, x + dx, y, y - dy, y + dy);
        }
        dataset.addSeries(series);

        if (dataSourceConfig.useCorrelativeData && dataSourceConfig.pointDataSource != null
                && dataSourceConfig.dataField != null) {

            XYIntervalSeries corrSeries = new XYIntervalSeries(
                    getCorrelativeDataLabel(dataSourceConfig.pointDataSource, dataSourceConfig.dataField));
            int[] shapeVertexIndexes = profileData.getShapeVertexIndexes();
            SimpleFeature[] simpleFeatures = dataSourceConfig.pointDataSource.getFeatureCollection()
                    .toArray(new SimpleFeature[0]);

            if (shapeVertexIndexes.length == simpleFeatures.length) {
                int fieldIndex = getAttributeIndex(dataSourceConfig.pointDataSource,
                        dataSourceConfig.dataField);
                if (fieldIndex != -1) {
                    for (int i = 0; i < simpleFeatures.length; i++) {
                        Number attribute = (Number) simpleFeatures[i].getAttribute(fieldIndex);
                        if (attribute != null) {
                            final double x = shapeVertexIndexes[i];
                            final double y = attribute.doubleValue();
                            corrSeries.add(x, x, x, y, y, y);
                        }
                    }
                    dataset.addSeries(corrSeries);
                }
            } else {
                System.out.println("Weird things happened:");
                System.out.println("  shapeVertexIndexes.length = " + shapeVertexIndexes.length);
                System.out.println("  simpleFeatures.length     = " + simpleFeatures.length);
            }

        }

        profilePlotDisplay.restoreAutoBounds();
        xAxisRangeControl.getBindingContext().setComponentsEnabled(PROPERTY_NAME_MARK_SEGMENTS,
                profileData.getShapeVertices().length > 2);
    }
}

From source file:com.opera.core.systems.scope.services.ums.EcmaScriptDebugger.java

protected Object parseNumber(String value) {
    Number number;
    try {/*from  w  ww  .ja  va  2  s.  c o m*/
        number = NumberFormat.getInstance().parse(value);
        if (number instanceof Long)
            return number.longValue();
        else
            return number.doubleValue();
    } catch (ParseException e) {
        throw new WebDriverException("The result from the script can not be parsed");
    }
}

From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java

private boolean hasValueChanged(Number change) {
    return change != null && Math.abs(change.doubleValue()) > 0.00001;
}

From source file:com.rapidminer.gui.plotter.charts.ParetoChartPlotter.java

public void paintParetoChart(Graphics graphics) {
    prepareData();//from  w w  w.j  a  va  2  s. c o  m

    JFreeChart chart = createChart();

    if (chart != null) {
        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);
        chart.getPlot().setBackgroundPaint(Color.WHITE);

        // bar renderer --> own 3D effect
        CategoryPlot plot = chart.getCategoryPlot();
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        // renderer.setBarPainter(new StandardBarPainter());
        renderer.setBarPainter(new RapidBarPainter());

        renderer.setSeriesPaint(0, getColorProvider(true).getPointColor(1));

        // labels on top of bars
        Map<String, String> barItemLabels = new HashMap<>();
        Map<String, String> cumulativeItemLabels = new HashMap<>();
        int groupSum = 0;
        int totalSum = 0;
        for (Object key : totalData.getKeys()) {
            String k = (String) key;
            try {
                Number groupValue = data.getValue(k);
                Number totalValue = totalData.getValue(k);
                groupSum += groupValue.intValue();
                totalSum += totalValue.intValue();
                barItemLabels.put(k, Tools.formatIntegerIfPossible(groupValue.doubleValue()) + " / "
                        + Tools.formatIntegerIfPossible(totalValue.doubleValue()));
                cumulativeItemLabels.put(k, groupSum + " / " + totalSum);
            } catch (UnknownKeyException e) {
                // do nothing
            }
        }
        renderer.setSeriesItemLabelFont(0, LABEL_FONT);

        if (showBarLabelsFlag) {
            renderer.setSeriesItemLabelsVisible(0, true);
            renderer.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(barItemLabels));

            if (isLabelRotating()) {
                renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                        TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
                renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                        TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d));
            }
        }

        LineAndShapeRenderer renderer2 = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(1);
        renderer2.setSeriesPaint(0, Color.GRAY.darker().darker());
        renderer2.setSeriesItemLabelFont(0, LABEL_FONT);
        renderer2.setSeriesItemLabelPaint(0, Color.BLACK);
        if (isLabelRotating()) {
            renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
            renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d));
        } else {
            renderer2.setSeriesPositiveItemLabelPosition(0,
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT));
            renderer2.setSeriesNegativeItemLabelPosition(0,
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT));
        }

        if (showCumulativeLabelsFlag) {
            renderer2.setSeriesItemLabelsVisible(0, true);
            renderer2.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(cumulativeItemLabels));
        }

        // draw outlines
        renderer.setDrawBarOutline(true);

        // gridline colors
        plot.setRangeGridlinePaint(Color.BLACK);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }

        Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
        chart.draw((Graphics2D) graphics, drawRect);
    }
}

From source file:QueryConnector.java

private void loadData(XSpreadsheet sheet, CellAddress startCell, Query query, boolean saveConnectionInfo)
        throws Exception {
    XCellRange cellRange = UnoRuntime.queryInterface(XCellRange.class, sheet);
    com.sun.star.lang.Locale locale = new com.sun.star.lang.Locale();
    //effettuo la query sul db
    Class.forName(query.getDriverClass());
    Connection con = DriverManager.getConnection(query.getURL(), query.getUsername(), query.getPassword());
    Statement stmt = con.createStatement();
    ResultSet result = stmt.executeQuery(query.getQuery());
    ResultSetMetaData metaData = result.getMetaData();
    int columnCount = metaData.getColumnCount();
    //intestazione del risultato (nomi delle colonne)
    for (int i = 1, j = startCell.Column; i <= columnCount; i++, j++) {
        XCell curCellHeader = cellRange.getCellByPosition(j, startCell.Row);
        XTextRange currentCellHeaderText = UnoRuntime.queryInterface(XTextRange.class, curCellHeader);
        currentCellHeaderText.setString(metaData.getColumnLabel(i));
        if (saveConnectionInfo)
            setCellUserProperty(curCellHeader, QUERY_PROPERTY, query.getName());
    }/*from   w  ww  .j  ava 2  s.  com*/
    //contenuto della query
    int rowCount = 1;
    int rowIdx = startCell.Row + 1;
    while (result.next()) {
        for (int i = 1, j = startCell.Column; i <= columnCount; i++, j++) {
            XCell curCellData = cellRange.getCellByPosition(j, rowIdx);
            XPropertySet cellDataProps = UnoRuntime.queryInterface(XPropertySet.class, curCellData);
            XTextRange currentCellDataText = UnoRuntime.queryInterface(XTextRange.class, curCellData);
            Object cellValue = result.getObject(i);
            if (cellValue instanceof java.sql.Date || cellValue instanceof java.sql.Time
                    || cellValue instanceof java.util.Date) {
                cellDataProps.setPropertyValue("NumberFormat",
                        this.numberFormats.queryKey("GG/MM/AAAA HH.MM.SS", locale, true));
                curCellData.setValue(dateValue(DATE_FORMATTER.format((java.util.Date) cellValue)));
            } else if (cellValue instanceof Number) {
                cellDataProps.setPropertyValue("NumberFormat", this.numberFormats.queryKey("#", locale, true));
                Number number = (Number) cellValue;
                curCellData.setValue(number.doubleValue());
            } else if (cellValue == null) {
                currentCellDataText.setString("");
            } else
                currentCellDataText.setString(cellValue.toString());
            if (saveConnectionInfo)
                setCellUserProperty(curCellData, QUERY_PROPERTY, query.getName());
        }
        rowCount++;
        rowIdx++;
    }
    result.close();
    stmt.close();
    con.close();
    //aggiono le informazioni sul range dei dati selezionato nella query
    query.setPositionAndArea(startCell.Column, startCell.Row, columnCount, rowCount);
    //salvo le informazioni sul documento
    if (saveConnectionInfo)
        settings.saveQuery(query);
}

From source file:net.atomique.ksar.graph.Graph.java

private boolean add_datapoint_plot(Second now, int col, String colheader, double value) {
    try {/* w  w  w. j a va  2  s . co  m*/
        ((Stats.get(col))).add(now, value);
        return true;
    } catch (SeriesException se) {
        // insert not possible
        // check if column can be update
        StatConfig statconfig = ((OSParser) mysar.myparser).get_OSConfig()
                .getStat(mysar.myparser.getCurrentStat());
        if (statconfig != null) {
            if (statconfig.canDuplicateTime()) {
                Number oldval = ((Stats.get(col))).getValue(now);
                double tempval;
                if (oldval == null) {
                    return false;
                }
                ColumnConfig colconfig = GlobalOptions.getColumnConfig(colheader);
                if (colconfig == null) {
                    return false;
                }
                if (colconfig.getType() == 1) {
                    tempval = ((oldval.doubleValue() + value) / 2);
                } else if (colconfig.getType() == 2) {
                    tempval = (oldval.doubleValue() + value);
                } else {
                    return false;
                }

                try {
                    ((Stats.get(col))).update(now, tempval);
                    return true;
                } catch (SeriesException se2) {
                    return false;
                }
            }
        }
        return false;
    }

}

From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java

/**
 * Converts a numeric value to a BigDecimal
 * /*  ww w  . j  av a2s.  c  o m*/
 * @param value
 * @return
 */
protected BigDecimal toBigDecimal(Number value) {
    return value == null ? null : BigDecimal.valueOf(value.doubleValue());
}

From source file:com.espertech.esper.filter.RangeValueEventPropIndexed.java

public final Double getFilterValue(MatchedEventMap matchedEvents, ExprEvaluatorContext exprEvaluatorContext) {
    EventBean[] events = (EventBean[]) matchedEvents.getMatchingEventAsObjectByTag(resultEventAsName);

    Number value;
    if (events == null) {
        log.warn("Matching events for tag '" + resultEventAsName
                + "' returned a null result, using null value in filter criteria, for statement '"
                + statementName + "'");
        return null;
    } else if (resultEventIndex > (events.length - 1)) {
        log.warn("Matching events for tag '" + resultEventAsName + "' returned no result for index "
                + resultEventIndex + " at array length " + events.length
                + ", using null value in filter criteria, for statement '" + statementName + "'");
        return null;
    } else {//from  www .  j av  a2s .  co m
        value = (Number) events[resultEventIndex].get(resultEventProperty);
    }

    if (value == null) {
        return null;
    }
    return value.doubleValue();
}

From source file:com.newatlanta.bluedragon.CategoryItemLabelGenerator.java

protected Object[] createItemArray(CategoryDataset dataset, int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (value != null) {
        if (yAxisSymbols != null) {
            int intValue = value.intValue();
            if (intValue < yAxisSymbols.length)
                result[2] = yAxisSymbols[intValue];
            else/*from  w  ww . j  a v a 2  s  .  c om*/
                result[2] = "???";
        } else if (this.getNumberFormat() != null) {
            result[2] = this.getNumberFormat().format(value);
        } else if (this.getDateFormat() != null) {
            result[2] = this.getDateFormat().format(value);
        }
    } else {
        result[2] = "-"; // this.nullValueString;
    }

    if (value != null) {
        double total = DataUtilities.calculateRowTotal(dataset, row);
        double percent = value.doubleValue() / total;
        result[3] = NumberFormat.getPercentInstance().format(percent);
        if (this.getNumberFormat() != null) {
            result[4] = this.getNumberFormat().format(total);
        } else if (this.getDateFormat() != null) {
            // result[4] = this.getDateFormat().format(total);
        }
    }

    return result;
}