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:com.hello2morrow.sonarplugin.SonargraphSensor.java

private double getBuildUnitMetric(String key) {
    Number num = buildUnitMetrics.get(key);

    if (num == null) {
        LOG.error("Cannot find metric <" + key + "> in generated report");
        return 0.0;
    }//from  ww w.  j a v a 2 s.  c o m
    return num.doubleValue();
}

From source file:de.ifsr.adam.ImageGenerator.java

/**
 * Main method for generating an Preview out of a report with it results.
 *
 * @param resultReport The report with it results
 * @return returns true if the generation and saving of the image was successful, false
 * otherwise//from w w  w  .ja  v  a 2 s  .  co  m
 */
public Scene generatePreview(JSONArray resultReport) {
    log.info("Preview generation has started");
    VBox vbox = generateImageVBox(resultReport);

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
    scrollPane.setContent(vbox);

    //Gets the screen resulution for scaling.
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    int width = gd.getDisplayMode().getWidth();
    int height = gd.getDisplayMode().getHeight();

    scrollPane.setVmax(100.0);
    scrollPane.setPrefSize(width * 0.65, height * 0.8); //TODO Can I do this better?

    ((Group) scene.getRoot()).getChildren().add(scrollPane);
    scene.getStylesheets().add(this.stylesheetURI.toString());

    //The Observer for resizing the scrollpane when the window changes.
    scene.widthProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth,
                Number newSceneWidth) {
            scrollPane.setPrefWidth(newSceneWidth.doubleValue());
        }
    });

    //The Observer for resizing the scrollpane when the window changes.
    scene.heightProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight,
                Number newSceneHeight) {
            scrollPane.setPrefHeight(newSceneHeight.doubleValue());
        }
    });

    log.info("End of Preview generation");
    return scene;
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java

/**
 * Draws the visual representation of a single data item when the plot has a
 * vertical orientation.//w  w w .jav a  2  s . c o  m
 *
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area within which the plot is being drawn.
 * @param plot the plot (can be used to obtain standard color information
 * etc).
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
@Override
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    //Determine the catgory start and end.
    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;

    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;

    domainAxis.setCategoryMargin(0.25);

    rangeAxis.setUpperMargin(0.3);
    rangeAxis.setLowerMargin(0.3);

    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    if (seriesCount > 1) {
        double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
        // offset the start of the boxes if the total width used is smaller
        // than the category width
        double offset = (categoryWidth - usedWidth) / 2;
        xx = xx + offset + (row * (state.getBarWidth() + seriesGap));
    } else {
        // offset the start of the box if the box width is smaller than the category width
        double offset = (categoryWidth - state.getBarWidth()) / 2;
        xx = xx + offset;
    }
    double xxmid = xx + state.getBarWidth() / 2.0;

    //Draw the box.
    Paint p = getItemPaint(row, column);
    if (p != null) {
        g2.setPaint(p);
    }
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);

    RectangleEdge location = plot.getRangeAxisEdge();
    Shape box = null;

    Number yQ1 = bawDataset.getQ1Value(row, column);
    Number yQ3 = bawDataset.getQ3Value(row, column);
    Number yMax = bawDataset.getMaxRegularValue(row, column);
    Number yMin = bawDataset.getMinRegularValue(row, column);

    if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {

        double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
        double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
        double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
        double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);

        // set the paint according to the right technical replicate
        int length = GuiUtils.getAvailableColors().length;
        int colorIndex = row % length;
        Color color = GuiUtils.getAvailableColors()[colorIndex];
        g2.setPaint(color);

        // draw the upper whisker
        g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
        g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax));
        // draw the lower whisker
        g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
        g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin));

        // draw the body
        box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
        g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175));

        //            if (getFillBox()) {
        //                g2.fill(box);
        //            }
        g2.draw(box);
    }

    // draw mean 
    g2.setPaint(getArtifactPaint());
    double yyAverage = 0.0;
    double aRadius = 2.0; // mean radius                       
    Number yMean = bawDataset.getMeanValue(row, column);
    if (yMean != null) {
        yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
        Ellipse2D.Double avgEllipse = new Ellipse2D.Double((xxmid - aRadius), (yyAverage - aRadius),
                aRadius * 2, aRadius * 2);
        g2.draw(avgEllipse);
    }

    //draw median
    double yyMedian = 0.0;
    Number yMedian = bawDataset.getMedianValue(row, column);
    if (yMedian != null) {
        yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
        g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian));
    }

    //Outliers and Farouts                 
    double oRadius = 2.0; //outlier radius
    double foRadius = 1.0; //farout radius

    // From outlier array sort out which are outliers and put these into a 
    // list. If there are any farouts, add them to the farout list.    
    // draw the outliers and farouts only if they are within the data area.
    double yyOutlier;
    double yyFarout;
    List outliers = new ArrayList();
    List farOutValues = new ArrayList();
    List yOutliers = bawDataset.getOutliers(row, column);
    if (yOutliers != null) {
        for (int i = 0; i < yOutliers.size(); i++) {
            Number outlierNum = (Number) yOutliers.get(i);
            double outlier = outlierNum.doubleValue();
            Number minOutlier = bawDataset.getMinOutlier(row, column);
            Number maxOutlier = bawDataset.getMaxOutlier(row, column);
            Number minRegular = bawDataset.getMinRegularValue(row, column);
            Number maxRegular = bawDataset.getMaxRegularValue(row, column);
            if (outlier > maxOutlier.doubleValue() || outlier < minOutlier.doubleValue()) {
                yyFarout = rangeAxis.valueToJava2D(outlier, dataArea, location);
                Outlier faroutToAdd = new Outlier(xxmid, yyFarout, foRadius);
                if (dataArea.contains(faroutToAdd.getPoint())) {
                    farOutValues.add(faroutToAdd);
                }
            } else if (outlier > maxRegular.doubleValue() || outlier < minRegular.doubleValue()) {
                yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
                Outlier outlierToAdd = new Outlier(xxmid, yyOutlier, oRadius);
                if (dataArea.contains(outlierToAdd.getPoint())) {
                    outliers.add(outlierToAdd);
                }
            }
        }

        //draw the outliers
        g2.setPaint(this.outlierPaint);
        for (Iterator iterator = outliers.iterator(); iterator.hasNext();) {
            Outlier outlier = (Outlier) iterator.next();
            Point2D point = outlier.getPoint();
            Shape dot = createEllipse(point, oRadius);
            g2.draw(dot);
        }

        //draw the farout values
        g2.setPaint(this.farOutColor);
        for (Iterator iterator = farOutValues.iterator(); iterator.hasNext();) {
            Outlier outlier = (Outlier) iterator.next();
            Point2D point = outlier.getPoint();
            Shape triangle = createTriangleVertical(point, foRadius);
            g2.draw(triangle);
        }
    }
}

From source file:dk.dma.vessel.track.model.VesselTarget.java

/**
 * Utility method that compares two numbers
 * @param f1 the first number// www  .  j av a2 s.c om
 * @param f2 the first number
 * @return if the numbers are (almost) identical
 */
private boolean compare(Number f1, Number f2) {
    if (f1 == null && f2 == null) {
        return true;
    } else if (f1 == null || f2 == null) {
        return false;
    }
    return Math.abs(f1.doubleValue() - f2.doubleValue()) < 0.001;
}

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataSet, int row, int column, int pass) {
    if (!getItemVisible(row, column)) {
        return;/*  www .  ja v  a2s . co m*/
    }

    Number value = dataSet.getValue(row, column);
    int visibleRow = state.getVisibleSeriesIndex(row);
    if ((value == null || visibleRow < 0)) {
        return;
    }

    LineFillItemRendererState rendererState = (LineFillItemRendererState) state;
    double currentValue = value.doubleValue();
    double currentItemXPoint = calculateItemXPoint(plot, dataSet, domainAxis, dataArea, column, visibleRow,
            state.getVisibleSeriesCount());
    double currentItemYPoint = calculateItemYPoint(plot, rangeAxis, dataArea, currentValue);

    if (isAreaAndLinePass(pass)) {
        processAreaAndLine(dataArea, plot, domainAxis, rangeAxis, dataSet, rendererState, row, column,
                currentValue, currentItemXPoint, currentItemYPoint, visibleRow);
    } else if (isShapesAndLabelsPass(pass)) {
        Shape entityArea = renderItemShapeAndLabel(g2, dataSet, row, column, plot.getOrientation(),
                currentValue, currentItemXPoint, currentItemYPoint);

        int dataSetIndex = plot.indexOf(dataSet);
        updateCrosshairValues(state.getCrosshairState(), dataSet.getRowKey(row), dataSet.getColumnKey(column),
                currentValue, dataSetIndex, currentItemXPoint, currentItemYPoint, plot.getOrientation());

        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataSet, row, column, entityArea);
        }
    }

}

From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java

private RectangleEdge drawRectangles(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, ValueAxis rangeAxis, int row, int column, BoxAndWhiskerCategoryDataset bawDataset,
        double xx) {
    RectangleEdge location = plot.getRangeAxisEdge();

    Number yQ1 = bawDataset.getQ1Value(row, column);
    Number yQ3 = bawDataset.getQ3Value(row, column);
    Number yMax = bawDataset.getMaxRegularValue(row, column);
    Number yMin = bawDataset.getMinRegularValue(row, column);
    Shape box = null;/*from   w  w  w  .jav a 2  s .c  o m*/
    if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {
        double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
        double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
        double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
        double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
        double xxmid = xx + state.getBarWidth() / 2.0;

        // draw the upper shadow...
        g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
        g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax));

        // draw the lower shadow...
        g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
        g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin));

        // draw the body...
        box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
        if (getFillBox()) {
            g2.fill(box);
        }
        g2.draw(box);
    }
    return location;
}

From source file:com.hello2morrow.sonarplugin.SonarJSensor.java

private double getProjectMetric(String key) {
    Number num = projectMetrics.get(key);

    if (num == null) {
        LOG.error("Cannot find metric <" + key + "> in generated report");
        return 0.0;
    }/*from   w ww . jav  a  2 s .  co  m*/
    return num.doubleValue();
}

From source file:net.sf.jasperreports.engine.data.JRAbstractTextDataSource.java

protected Object convertNumber(Number number, Class<?> valueClass) throws JRException {
    Number value = null;//from  ww  w .  ja  v a  2s. c o  m
    if (valueClass.equals(Byte.class)) {
        value = number.byteValue();
    } else if (valueClass.equals(Short.class)) {
        value = number.shortValue();
    } else if (valueClass.equals(Integer.class)) {
        value = number.intValue();
    } else if (valueClass.equals(Long.class)) {
        value = number.longValue();
    } else if (valueClass.equals(Float.class)) {
        value = number.floatValue();
    } else if (valueClass.equals(Double.class)) {
        value = number.doubleValue();
    } else if (valueClass.equals(BigInteger.class)) {
        value = BigInteger.valueOf(number.longValue());
    } else if (valueClass.equals(BigDecimal.class)) {
        value = new BigDecimal(Double.toString(number.doubleValue()));
    } else {
        throw new JRException(EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE, new Object[] { valueClass.getName() });
    }
    return value;
}

From source file:com.facebook.stetho.json.ObjectMapper.java

private Object getValueForField(Field field, Object value) throws JSONException {
    try {//ww  w  .ja  v  a2 s  . c  om
        if (value != null) {
            if (value == JSONObject.NULL) {
                return null;
            }
            if (value.getClass() == field.getType()) {
                return value;
            }
            if (value instanceof JSONObject) {
                return convertValue(value, field.getType());
            } else {
                if (field.getType().isEnum()) {
                    return getEnumValue((String) value, field.getType().asSubclass(Enum.class));
                } else if (value instanceof JSONArray) {
                    return convertArrayToList(field, (JSONArray) value);
                } else if (value instanceof Number) {
                    // Need to convert value to Number This happens because json treats 1 as an Integer even
                    // if the field is supposed to be a Long
                    Number numberValue = (Number) value;
                    Class<?> clazz = field.getType();
                    if (clazz == Integer.class || clazz == int.class) {
                        return numberValue.intValue();
                    } else if (clazz == Long.class || clazz == long.class) {
                        return numberValue.longValue();
                    } else if (clazz == Double.class || clazz == double.class) {
                        return numberValue.doubleValue();
                    } else if (clazz == Float.class || clazz == float.class) {
                        return numberValue.floatValue();
                    } else if (clazz == Byte.class || clazz == byte.class) {
                        return numberValue.byteValue();
                    } else if (clazz == Short.class || clazz == short.class) {
                        return numberValue.shortValue();
                    } else {
                        throw new IllegalArgumentException("Not setup to handle class " + clazz.getName());
                    }
                }
            }
        }
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Unable to set value for field " + field.getName(), e);
    }
    return value;
}

From source file:org.jfree.data.xy.XYSeries.java

/**
 * Returns a new array containing the x and y values from this
 * series.//  w w w.ja  v  a2 s. co m
 *
 * @return A new array containing the x and y values from this
 * series.
 *
 * @since 1.0.4
 */
public double[][] toArray() {
    int itemCount = getItemCount();
    double[][] result = new double[2][itemCount];

    for (int i = 0; i < itemCount; i++) {
        result[0][i] = this.getX(i).doubleValue();
        Number y = getY(i);
        if (y != null) {
            result[1][i] = y.doubleValue();
        } else {
            result[1][i] = Double.NaN;
        }
    }
    return result;
}