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.chart.demo.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device.//  www .  j a  v  a  2 s  .  co  m
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea,
        final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis,
        final CategoryDataset dataset, final int row, final int column) {

    // nothing is drawn for null values...
    final Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    final double value = dataValue.doubleValue();

    final PlotOrientation orientation = plot.getOrientation();
    final double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        final Number v = dataset.getValue(i, column);
        if (v != null) {
            final double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    final double translatedBase;
    final double translatedValue;
    final RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    final double barL0 = Math.min(translatedBase, translatedValue);
    final double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    //        final CategoryLabelGenerator generator = getLabelGenerator(row, column);
    //      if (generator != null && isItemLabelVisible(row, column)) {
    //        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    //  }       

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                final double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                //            RefineryUtilities.drawRotatedString(
                //              this.totalFormatter.format(total), g2,
                //            (float) bar.getCenterX(),
                //          (float) (bar.getMinY() - 4.0), 
                ///        TextAnchor.BOTTOM_CENTER, 
                //         TextAnchor.BOTTOM_CENTER, 
                //       0.0
                // );              
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                final double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                /*                    RefineryUtilities.drawRotatedString(
                String.valueOf(total), g2,
                (float) bar.getCenterX(),
                (float) (bar.getMaxY() + 4.0), 
                TextAnchor.TOP_CENTER, 
                TextAnchor.TOP_CENTER, 
                0.0
                                    );              
                  */ }
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        final EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
        if (entities != null) {
            String tip = null;
            final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            final CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            //            entities.addEntity(entity);
        }
    }

}

From source file:nz.co.senanque.rules.OperationsImpl.java

@InternalFunction(operator = "%", precedence = 21)
public Number mod(Number value, Number value2) {
    if (value == null || value2 == null) {
        return new Long(0L);
    }/*www. j a v  a  2 s. c  o m*/
    return value2.doubleValue() % value.doubleValue();
}

From source file:nz.co.senanque.rules.OperationsImpl.java

@InternalFunction(operator = "-", precedence = 20)
public Number sub(Number value, Number value2) {
    if (value == null || value2 == null) {
        return new Long(0L);
    }//from  w  w w  .  j av a  2s  .co m
    return value2.doubleValue() - value.doubleValue();
}

From source file:nz.co.senanque.rules.OperationsImpl.java

@InternalFunction(operator = "+", precedence = 20)
public Number add(Number value, Number value2) {
    if (value == null || value2 == null) {
        return new Long(0L);
    }/*from  ww w. ja v a 2  s .  co  m*/
    return value2.doubleValue() + value.doubleValue();
}

From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a horizontal orientation.
 * //ww w  . java 2s  .  c om
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawHorizontalItem(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) {
    // nothing is drawn for null... //added this test block, Rinke
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

    // BAR Y
    double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectY = rectY + row * (state.getBarWidth() + seriesGap);
    } else {
        rectY = rectY + row * state.getBarWidth();
    }

    // BAR X
    final Number meanValue = dataset.getMeanValue(row, column);

    double value = meanValue.doubleValue();
    double base = 0.0;
    final double lclip = getLowerClip();
    final double uclip = getUpperClip();

    if (uclip <= 0.0) { // cases 1, 2, 3 and 4
        if (value >= uclip) {
            return; // bar is not visible
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else { // cases 9, 10, 11 and 12
        if (value <= lclip) {
            return; // bar is not visible
        }
        base = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
    final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
    final double rectX = Math.min(transY2, transY1);

    final double rectHeight = state.getBarWidth();
    final double rectWidth = Math.abs(transY2 - transY1);

    final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (state.getBarWidth() > 3) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }
    // ********** BLOCK WITH CHANGES RELATIVE TO StatisticalBarRenderere *********************
    // standard deviation lines
    final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset;
    final Number highValRaw = asymmDataset.getUpperValue(row, column);
    final Number lowValRaw = asymmDataset.getLowerValue(row, column);
    if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE
        final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation);
        final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation);
        // *************************** end of block with changes ******************************

        if (getErrorIndicatorPaint() != null) {
            g2.setPaint(getErrorIndicatorPaint());
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        Line2D line = null;
        line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d);
        g2.draw(line);
        line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75);
        g2.draw(line);
        line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75);
        g2.draw(line);
    }

    final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    final EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}

From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java

/**
 * Draws an item for a plot with a vertical orientation.
 * /*from w  w w  . ja v a  2  s  .  co m*/
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawVerticalItem(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) {
    // nothing is drawn for null... //ADDED THIS BLOCK, RINKE
    final Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();

    // BAR X
    double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        rectX = rectX + row * (state.getBarWidth() + seriesGap);
    } else {
        rectX = rectX + row * state.getBarWidth();
    }

    // BAR Y
    final Number meanValue = dataset.getMeanValue(row, column);

    double value = meanValue.doubleValue();
    double base = 0.0;
    final double lclip = getLowerClip();
    final double uclip = getUpperClip();

    if (uclip <= 0.0) { // cases 1, 2, 3 and 4
        if (value >= uclip) {
            return; // bar is not visible
        }
        base = uclip;
        if (value <= lclip) {
            value = lclip;
        }
    } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
        if (value >= uclip) {
            value = uclip;
        } else {
            if (value <= lclip) {
                value = lclip;
            }
        }
    } else { // cases 9, 10, 11 and 12
        if (value <= lclip) {
            return; // bar is not visible
        }
        base = getLowerClip();
        if (value >= uclip) {
            value = uclip;
        }
    }

    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
    final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
    final double rectY = Math.min(transY2, transY1);

    final double rectWidth = state.getBarWidth();
    final double rectHeight = Math.abs(transY2 - transY1);

    final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (state.getBarWidth() > 3) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    // standard deviation lines
    final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset;
    final Number highValRaw = asymmDataset.getUpperValue(row, column);
    final Number lowValRaw = asymmDataset.getLowerValue(row, column);
    // only draw if both error bars items are not null
    if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE
        final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation);
        final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation);

        if (getErrorIndicatorPaint() != null) {
            g2.setPaint(getErrorIndicatorPaint());
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
        }
        Line2D line = null;
        line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d,
                highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d,
                lowVal);
        g2.draw(line);
    }

    final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    final EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }
}

From source file:nz.co.senanque.rules.OperationsImpl.java

@InternalFunction(operator = "^", precedence = 22)
public Number pow(Number value, Number value2) {
    if (value == null || value2 == null) {
        return new Long(0L);
    }//  ww w  . j ava  2s . co  m
    return Math.pow(value2.doubleValue(), value.doubleValue());
}

From source file:com.parse.ParseConfig.java

/**
 * Access a {@code double} value, returning a default value if it doesn't exist.
 *
 * @param key//from  w  w  w. j  ava  2  s .c  om
 *          The key to access the value for.
 * @param defaultValue
 *          The value to return if the key is not present or has the wrong type.
 * @return The default value if there is no such key or if it is not a number.
 */
public double getDouble(String key, double defaultValue) {
    Number number = getNumber(key);
    return number != null ? number.doubleValue() : defaultValue;
}

From source file:NumericTextField.java

public Double getDoubleValue() throws ParseException {
    Number result = getNumberValue();
    if ((result instanceof Long) == false && (result instanceof Double) == false) {
        throw new ParseException("Not a valid double", 0);
    }/*  ww  w.jav a  2 s. c om*/

    if (result instanceof Long) {
        result = new Double(result.doubleValue());
    }

    return (Double) result;
}

From source file:LabelXYToolTipGenerator.java

/**
 * Generates a tool tip text item for a particular item within a series.
 *
 * @param data  the dataset (ignored in this implementation).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The tooltip text.//from  ww  w  .j av a 2  s .c o  m
 */
public String generateToolTip(XYDataset dataset, int series, int item) {

    String seriesLabel = dataset.getSeriesKey(series).toString();
    Number x = dataset.getX(series, item);
    Number y = dataset.getY(series, item);
    String pointLabel = getToolTipText(series, item);

    String toolTip = "<html><center>" + "<p style='color:green;'><b>" + pointLabel + "</b></p>"
    // +"<br>"
            + "<p style='color:purple;'>" + seriesLabel + "</p>"
            // +"<br>"
            + "(" + format(x.doubleValue(), 2, 2) + ", " + format(y.doubleValue(), 2, 2) + ")</center></html>";

    return (toolTip);

}