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.trade.ui.chart.renderer.HeikinAshiRenderer.java

private void configureToolTips() {
    setBaseToolTipGenerator(new XYToolTipGenerator() {
        public String generateToolTip(XYDataset dataset, int series, int item) {
            StringBuilder result = new StringBuilder("<html>");
            if (dataset instanceof HeikinAshiDataset) {
                HeikinAshiDataset d = (HeikinAshiDataset) dataset;
                Number time = d.getX(series, item);
                Number high = d.getHigh(series, item);
                Number low = d.getLow(series, item);
                Number open = d.getOpen(series, item);
                Number close = d.getClose(series, item);

                result.append("<b>Open:</b> ").append(new Money(open.doubleValue())).append("<br/>");
                result.append("<b>High:</b> ").append(new Money(high.doubleValue())).append("<br/>");
                result.append("<b>Low:</b> ").append(new Money(low.doubleValue())).append("<br/>");
                result.append("<b>Close:</b> ").append(new Money(close.doubleValue())).append("<br/>");
                result.append("<b>Date:</b> ").append(TOOLTIP_DATE_FORMAT.format(time)).append("<br/>");
            } else {

            }/*from  www  .  ja v  a 2s  .  c  o  m*/
            return result.toString();
        }

    });
}

From source file:cz.cvut.kbss.jsonld.jackson.serialization.JacksonJsonWriter.java

@Override
public void writeNumber(Number number) throws IOException {
    if (number instanceof Integer) {
        jsonGenerator.writeNumber(number.intValue());
    } else if (number instanceof Long) {
        jsonGenerator.writeNumber(number.longValue());
    } else if (number instanceof Float) {
        jsonGenerator.writeNumber(number.floatValue());
    } else if (number instanceof Double) {
        jsonGenerator.writeNumber(number.doubleValue());
    } else if (number instanceof BigInteger) {
        jsonGenerator.writeNumber((BigInteger) number);
    } else if (number instanceof BigDecimal) {
        jsonGenerator.writeNumber((BigDecimal) number);
    } else if (number instanceof Short) {
        jsonGenerator.writeNumber(number.shortValue());
    } else if (number instanceof Byte) {
        jsonGenerator.writeNumber(number.byteValue());
    } else {//from  w w w . j av  a 2 s .com
        throw new IllegalArgumentException(
                "Unable to write number " + number + " of type " + number.getClass());
    }
}

From source file:org.jfree.chart.demo.GanttRenderer2.java

protected void drawTask(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        GanttCategoryDataset ganttcategorydataset, int i, int j) {
    PlotOrientation plotorientation = categoryplot.getOrientation();
    org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
    Number number = ganttcategorydataset.getEndValue(i, j);
    if (number == null)
        return;//from ww  w.  j av a  2  s . c  om
    double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge);
    Number number1 = ganttcategorydataset.getStartValue(i, j);
    if (number1 == null)
        return;
    double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge);
    if (d1 < d) {
        double d2 = d1;
        d1 = d;
        d = d2;
        Number number2 = number1;
        number1 = number;
        number = number2;
    }
    int k = countNonNullValues(ganttcategorydataset, j);
    if (k == 0)
        return;
    int l = countPriorNonNullValues(ganttcategorydataset, j, i);
    double d3 = (categoryaxis.getCategoryEnd(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge())
            - categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()))
            / (double) k;
    double d4 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d,
            categoryplot.getDomainAxisEdge()) + d3 * (double) l;
    double d5 = Math.abs(d1 - d);
    java.awt.geom.Rectangle2D.Double double1 = null;
    if (plotorientation == PlotOrientation.HORIZONTAL)
        double1 = new java.awt.geom.Rectangle2D.Double(d, d4, d5, d3);
    else if (plotorientation == PlotOrientation.VERTICAL)
        double1 = new java.awt.geom.Rectangle2D.Double(d4, d1, d3, d5);
    java.awt.geom.Rectangle2D.Double double2 = null;
    java.awt.geom.Rectangle2D.Double double3 = null;
    Number number3 = ganttcategorydataset.getPercentComplete(i, j);
    double d6 = getStartPercent();
    double d7 = getEndPercent();
    if (number3 != null) {
        double d8 = number3.doubleValue();
        if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) {
            double2 = new java.awt.geom.Rectangle2D.Double(d, d4 + d6 * d3, d5 * d8, d3 * (d7 - d6));
            double3 = new java.awt.geom.Rectangle2D.Double(d + d5 * d8, d4 + d6 * d3, d5 * (1.0D - d8),
                    d3 * (d7 - d6));
        } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) {
            double2 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1 + d5 * (1.0D - d8), d3 * (d7 - d6),
                    d5 * d8);
            double3 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1, d3 * (d7 - d6), d5 * (1.0D - d8));
        }
    }
    Paint paint = getItemPaint(i, j);
    graphics2d.setPaint(paint);
    graphics2d.fill(double1);
    if (double2 != null) {
        graphics2d.setPaint(getCompletePaint());
        graphics2d.fill(double2);
    }
    if (double3 != null) {
        graphics2d.setPaint(getIncompletePaint());
        graphics2d.fill(double3);
    }
    if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
        java.awt.Stroke stroke = getItemOutlineStroke(i, j);
        Paint paint1 = getItemOutlinePaint(i, j);
        if (stroke != null && paint1 != null) {
            graphics2d.setStroke(stroke);
            graphics2d.setPaint(paint1);
            graphics2d.draw(double1);
        }
    }
    org.jfree.chart.labels.CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j);
    if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j))
        drawItemLabel(graphics2d, ganttcategorydataset, i, j, categoryplot, categoryitemlabelgenerator, double1,
                false);
    if (categoryitemrendererstate.getInfo() != null) {
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection != null) {
            String s = null;
            CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j);
            if (categorytooltipgenerator != null)
                s = categorytooltipgenerator.generateToolTip(ganttcategorydataset, i, j);
            String s1 = null;
            if (getItemURLGenerator(i, j) != null)
                s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j);
            CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset,
                    ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j));
            entitycollection.add(categoryitementity);
        }
    }
}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Integer> getGeometric(final RandomNumberStream rng, final Number p) {
    final IntegerDistribution dist = new GeometricDistribution(
            RandomNumberStream.Util.asCommonsRandomGenerator(rng), p.doubleValue());
    return new RandomNumberDistribution<Integer>() {
        @Override// ww w.j  a  v  a  2  s  .  com
        public Integer draw() {
            return dist.sample();
        }
    };
}

From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device.//  www.  j  a  v  a  2 s.  c o  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).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

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

    double value = dataValue.doubleValue();

    PlotOrientation orientation = plot.getOrientation();
    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++) {
        Number v = dataset.getValue(i, column);
        if (v != null) {
            double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    double translatedBase;
    double translatedValue;
    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);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    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);
    }
    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);
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(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);
                double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(),
                        (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER);
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(),
                        (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER);
            }
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            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);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }

}

From source file:com.commander4j.util.JUtility.java

public static BigDecimal stringToBigDecimal(String str) {
    BigDecimal result;/*from  www .j a  v a 2  s  . com*/

    NumberFormat nf;
    nf = NumberFormat.getNumberInstance(Locale.getDefault());

    try {
        Number myNumber = nf.parse(str);
        Double dbl = myNumber.doubleValue();
        result = BigDecimal.valueOf(dbl);
        str = String.valueOf(dbl);
    } catch (ParseException e) {
        final Logger logger = Logger.getLogger(JUtility.class);
        logger.error(e.getMessage());
        str = "0";
        result = new BigDecimal("0");
    }

    // result = new BigDecimal(str);
    return result;
}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Double> getExponential(final RandomNumberStream rng, final Number mean) {
    final RealDistribution dist = new ExponentialDistribution(
            RandomNumberStream.Util.asCommonsRandomGenerator(rng), mean.doubleValue());
    return new RandomNumberDistribution<Double>() {
        @Override//from  www.  ja  v  a2s.  c o m
        public Double draw() {
            return dist.sample();
        }
    };
}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Double> getT(final RandomNumberStream rng, final Number degreesOfFreedom) {
    final RealDistribution dist = new TDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng),
            degreesOfFreedom.doubleValue());
    return new RandomNumberDistribution<Double>() {
        @Override/*from  w  w w .j av a2 s .  co m*/
        public Double draw() {
            return dist.sample();
        }
    };
}

From source file:io.coala.time.AbstractInstant.java

/** @see Instant#minus(Number) */
@Override/*  w w  w. j a v a2  s.  c  o  m*/
public THIS minus(final Number value) {
    return plus(-value.doubleValue());
}

From source file:org.jfree.chart.demo.GanttRenderer2.java

protected void drawTasks(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        GanttCategoryDataset ganttcategorydataset, int i, int j) {
    int k = ganttcategorydataset.getSubIntervalCount(i, j);
    if (k == 0)/*  www  .ja  va  2 s  .c  om*/
        drawTask(graphics2d, categoryitemrendererstate, rectangle2d, categoryplot, categoryaxis, valueaxis,
                ganttcategorydataset, i, j);
    for (int l = 0; l < k; l++) {
        org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
        Number number = ganttcategorydataset.getStartValue(i, j, l);
        if (number == null)
            return;
        double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge);
        Number number1 = ganttcategorydataset.getEndValue(i, j, l);
        if (number1 == null)
            return;
        double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge);
        if (d1 < d) {
            double d2 = d1;
            d1 = d;
            d = d2;
        }
        double d3 = calculateBarW0(categoryplot, categoryplot.getOrientation(), rectangle2d, categoryaxis,
                categoryitemrendererstate, i, j);
        double d4 = Math.abs(d1 - d);
        double d5 = categoryitemrendererstate.getBarWidth();
        java.awt.geom.Rectangle2D.Double double1 = null;
        if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL)
            double1 = new java.awt.geom.Rectangle2D.Double(d, d3, d4, d5);
        else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL)
            double1 = new java.awt.geom.Rectangle2D.Double(d3, d, d5, d4);
        java.awt.geom.Rectangle2D.Double double2 = null;
        java.awt.geom.Rectangle2D.Double double3 = null;
        Number number2 = ganttcategorydataset.getPercentComplete(i, j, l);
        double d6 = getStartPercent();
        double d7 = getEndPercent();
        if (number2 != null) {
            double d8 = number2.doubleValue();
            if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) {
                double2 = new java.awt.geom.Rectangle2D.Double(d, d3 + d6 * d5, d4 * d8, d5 * (d7 - d6));
                double3 = new java.awt.geom.Rectangle2D.Double(d + d4 * d8, d3 + d6 * d5, d4 * (1.0D - d8),
                        d5 * (d7 - d6));
            } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) {
                double2 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d + d4 * (1.0D - d8),
                        d5 * (d7 - d6), d4 * d8);
                double3 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d, d5 * (d7 - d6),
                        d4 * (1.0D - d8));
            }
        }
        Paint paint = getItemPaint(i, j);
        graphics2d.setPaint(paint);
        graphics2d.fill(double1);
        if (double2 != null) {
            graphics2d.setPaint(getCompletePaint());
            graphics2d.fill(double2);
        }
        if (double3 != null) {
            graphics2d.setPaint(getIncompletePaint());
            graphics2d.fill(double3);
        }
        if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
            graphics2d.setStroke(getItemStroke(i, j));
            graphics2d.setPaint(getItemOutlinePaint(i, j));
            graphics2d.draw(double1);
        }
        if (categoryitemrendererstate.getInfo() == null)
            continue;
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection == null)
            continue;
        String s = null;
        if (getToolTipGenerator(i, j) != null)
            s = getToolTipGenerator(i, j).generateToolTip(ganttcategorydataset, i, j);
        String s1 = null;
        if (getItemURLGenerator(i, j) != null)
            s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j);
        CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset,
                ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j));
        entitycollection.add(categoryitementity);
    }

}