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:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleMul(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case IMUL://from w  ww .j a v a 2 s  .  c  om
        number = Integer.valueOf(one.intValue() * two.intValue());
        break;
    case DMUL:
        number = Double.valueOf(one.doubleValue() * two.doubleValue());
        break;
    case FMUL:
        number = Float.valueOf(one.floatValue() * two.floatValue());
        break;
    case LMUL:
        number = Long.valueOf(one.longValue() * two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleSub(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case ISUB://from  w  w  w.j  av  a  2s. c o m
        number = Integer.valueOf(one.intValue() - two.intValue());
        break;
    case DSUB:
        number = Double.valueOf(one.doubleValue() - two.doubleValue());
        break;
    case FSUB:
        number = Float.valueOf(one.floatValue() - two.floatValue());
        break;
    case LSUB:
        number = Long.valueOf(one.longValue() - two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleAdd(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case IADD://from   w w  w. jav  a2  s . c o  m
        number = Integer.valueOf(one.intValue() + two.intValue());
        break;
    case DADD:
        number = Double.valueOf(one.doubleValue() + two.doubleValue());
        break;
    case FADD:
        number = Float.valueOf(one.floatValue() + two.floatValue());
        break;
    case LADD:
        number = Long.valueOf(one.longValue() + two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

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

private void processCategoryArea(Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataSet, LineFillItemRendererState rendererState, int row,
        int column, double currentValue, double currentItemYPoint, int totalColumns, boolean isFirstItem,
        boolean isLastItem) {
    RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
    double zeroRangePoint = calculateItemYPoint(plot, rangeAxis, dataArea, 0.0);
    double categoryStartXPoint = domainAxis.getCategoryStart(column, totalColumns, dataArea, domainAxisEdge);
    double categoryMiddleXPoint = domainAxis.getCategoryMiddle(column, totalColumns, dataArea, domainAxisEdge);
    double categoryEndXPoint = domainAxis.getCategoryEnd(column, totalColumns, dataArea, domainAxisEdge);

    if (isFirstItem) {
        categoryStartXPoint = categoryMiddleXPoint;
    } else if (isLastItem) {
        categoryEndXPoint = categoryMiddleXPoint;
    }/*from w w  w.  ja  v a2 s .c om*/

    double previousItemYValue = 0.0;
    if (!isFirstItem) {
        Number previousItemValue = dataSet.getValue(row, column - 1);

        if (previousItemValue != null) {
            previousItemYValue = (previousItemValue.doubleValue() + currentValue) / 2.0;

            if (domainAxis instanceof CategoryAxisAdapter) {
                categoryStartXPoint -= ((CategoryAxisAdapter) domainAxis).calculateCategoryGapSize(totalColumns,
                        dataArea, domainAxisEdge) / 2.0;
            }
        } else {
            categoryStartXPoint = categoryMiddleXPoint;
        }
    }

    double nextItemYValue = 0.0;
    if (!isLastItem) {
        Number nextValue = dataSet.getValue(row, column + 1);
        if (nextValue != null) {
            nextItemYValue = (nextValue.doubleValue() + currentValue) / 2.0;

            if (domainAxis instanceof CategoryAxisAdapter) {
                categoryEndXPoint += ((CategoryAxisAdapter) domainAxis).calculateCategoryGapSize(totalColumns,
                        dataArea, domainAxisEdge) / 2.0;
            }
        } else {
            categoryEndXPoint = categoryMiddleXPoint;
        }
    }

    double previousItemYPoint = rangeAxis.valueToJava2D(previousItemYValue, dataArea, rangeAxisEdge);
    double nextItemYPoint = rangeAxis.valueToJava2D(nextItemYValue, dataArea, rangeAxisEdge);

    Polygon polygon = rendererState.getAreaPolygon();
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        polygon.addPoint((int) categoryStartXPoint, (int) zeroRangePoint);
        polygon.addPoint((int) categoryStartXPoint, (int) previousItemYPoint);
        polygon.addPoint((int) categoryMiddleXPoint, (int) currentItemYPoint);
        polygon.addPoint((int) categoryEndXPoint, (int) nextItemYPoint);
        polygon.addPoint((int) categoryEndXPoint, (int) zeroRangePoint);
    } else {
        polygon.addPoint((int) zeroRangePoint, (int) categoryStartXPoint);
        polygon.addPoint((int) previousItemYPoint, (int) categoryStartXPoint);
        polygon.addPoint((int) currentItemYPoint, (int) categoryMiddleXPoint);
        polygon.addPoint((int) nextItemYPoint, (int) categoryEndXPoint);
        polygon.addPoint((int) zeroRangePoint, (int) categoryEndXPoint);
    }
}

From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java

private void validateGreaterThanNumber(Object propertyValidator) {
    Number minValue = (Number) ((PropertyValidator) propertyValidator).getMinValue();
    BindingComponent inputComponent = ((PropertyValidator) propertyValidator).getBindingComponent();
    logger.info("validation " + inputComponent.getFieldName() + ": is greaterThan");
    Number valorCampo = (Number) inputComponent.getValue();
    if (valorCampo != null) {
        if (!(minValue.doubleValue() < valorCampo.doubleValue())) {
            throw new AWValidationException("sw.error.validate.greaterThan",
                    new Object[] { minValue.toString() }, Arrays.asList(new Object[] { inputComponent }));
        }//w w w .  j av  a  2s  . co  m
    }
}

From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java

private void validateGreaterThanEqualsNumber(Object propertyValidator) {
    Number minValue = (Number) ((PropertyValidator) propertyValidator).getMinValue();
    BindingComponent inputComponent = ((PropertyValidator) propertyValidator).getBindingComponent();
    logger.info("validation " + inputComponent.getFieldName() + ": is greaterThan");
    Number valorCampo = (Number) inputComponent.getValue();
    if (valorCampo != null) {
        if (!(minValue.doubleValue() <= valorCampo.doubleValue())) {
            throw new AWValidationException("sw.error.validate.greaterThan",
                    new Object[] { minValue.toString() }, Arrays.asList(new Object[] { inputComponent }));
        }/* www  .  j  av a2 s. c o m*/
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java

/**
 * Draw a single data item./*w ww  .  j  a  v  a2 s .c o  m*/
 *
 * @param g2         the graphics device.
 * @param state      the renderer state.
 * @param dataArea   the data plot 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).
 * @param pass       the pass index.
 */
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, final int pass) {

    if (!isSeriesVisible(row)) {
        return;
    }

    if ((pass == 1) && !isItemLabelVisible(row, column)) {
        return;
    }

    // setup for collecting optional entity info...
    Shape entityArea = null;
    final EntityCollection entities = state.getEntityCollection();

    double y1 = 0.0;
    Number n = dataset.getValue(row, column);
    if (n != null) {
        y1 = n.doubleValue();
        if (this.renderAsPercentages) {
            final double total = DataUtilities.calculateColumnTotal(dataset, column);
            y1 = y1 / total;
        }
    }
    final double[] stack1 = getStackValues(dataset, row, column);

    // leave the y values (y1, y0) untranslated as it is going to be be
    // stacked up later by previous series values, after this it will be
    // translated.
    double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    double y0 = 0.0;
    n = dataset.getValue(row, Math.max(column - 1, 0));
    if (n != null) {
        y0 = n.doubleValue();
        if (this.renderAsPercentages) {
            final double total = DataUtilities.calculateColumnTotal(dataset, Math.max(column - 1, 0));
            y0 = y0 / total;
        }
    }
    final double[] stack0 = getStackValues(dataset, row, Math.max(column - 1, 0));

    // FIXME: calculate xx0
    double xx0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    final int itemCount = dataset.getColumnCount();
    double y2 = 0.0;
    n = dataset.getValue(row, Math.min(column + 1, itemCount - 1));
    if (n != null) {
        y2 = n.doubleValue();
        if (this.renderAsPercentages) {
            final double total = DataUtilities.calculateColumnTotal(dataset,
                    Math.min(column + 1, itemCount - 1));
            y2 = y2 / total;
        }
    }
    final double[] stack2 = getStackValues(dataset, row, Math.min(column + 1, itemCount - 1));

    double xx2 = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    // This gets rid of the white lines between most category values
    // Doug Moran - Hitachi Vantara
    xx0 = Math.round(xx0);
    xx1 = Math.round(xx1);
    xx2 = Math.round(xx2);

    // FIXME: calculate xxLeft and xxRight
    final double xxLeft = xx0;
    final double xxRight = xx2;

    final double[] stackLeft = averageStackValues(stack0, stack1);
    final double[] stackRight = averageStackValues(stack1, stack2);
    final double[] adjStackLeft = adjustedStackValues(stack0, stack1);
    final double[] adjStackRight = adjustedStackValues(stack1, stack2);

    final float transY1;

    final RectangleEdge edge1 = plot.getRangeAxisEdge();

    final GeneralPath left = new GeneralPath();
    final GeneralPath right = new GeneralPath();
    if (y1 >= 0.0) { // handle positive value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1);
        final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1);
        final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1);

        // LEFT POLYGON
        if (y0 >= 0.0) {
            final double yleft = (y0 + y1) / 2.0 + stackLeft[1];
            final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo((float) xx1, transY1);
            left.lineTo((float) xx1, transStack1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.lineTo((float) xxLeft, transYLeft);
            left.closePath();
        } else {
            left.moveTo((float) xx1, transStack1);
            left.lineTo((float) xx1, transY1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.closePath();
        }

        final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1);
        // RIGHT POLYGON
        if (y2 >= 0.0) {
            final double yright = (y1 + y2) / 2.0 + stackRight[1];
            final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transYRight);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        } else {
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        }
    } else { // handle negative value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1);
        final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1);
        final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1);

        // LEFT POLYGON
        if (y0 >= 0.0) {
            left.moveTo((float) xx1, transStack1);
            left.lineTo((float) xx1, transY1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.clone();
        } else {
            final double yleft = (y0 + y1) / 2.0 + stackLeft[0];
            final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            left.moveTo((float) xx1, transY1);
            left.lineTo((float) xx1, transStack1);
            left.lineTo((float) xxLeft, transStackLeft);
            left.lineTo((float) xxLeft, transYLeft);
            left.closePath();
        }
        final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1);

        // RIGHT POLYGON
        if (y2 >= 0.0) {
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        } else {
            final double yright = (y1 + y2) / 2.0 + stackRight[0];
            final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            right.moveTo((float) xx1, transStack1);
            right.lineTo((float) xx1, transY1);
            right.lineTo((float) xxRight, transYRight);
            right.lineTo((float) xxRight, transStackRight);
            right.closePath();
        }
    }

    if (pass == 0) {
        final Paint itemPaint = getItemPaint(row, column);
        g2.setPaint(itemPaint);
        g2.fill(left);
        g2.fill(right);

        // add an entity for the item...
        if (entities != null) {
            final GeneralPath gp = new GeneralPath(left);
            gp.append(right, false);
            entityArea = gp;
            addItemEntity(entities, dataset, row, column, entityArea);
        }
    } else if (pass == 1) {
        drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, transY1, y1 < 0.0);
    }

}

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

/**
 * Creates a new dataset./*from   w w  w. j  a v  a 2 s .c  om*/
 *
 * @param maxChipX  the wafer x-dimension.
 * @param maxChipY  the wafer y-dimension.
 * @param chipSpace  the space between chips.
 */
public WaferMapDataset(int maxChipX, int maxChipY, Number chipSpace) {

    this.maxValue = new Double(Double.NEGATIVE_INFINITY);
    this.minValue = new Double(Double.POSITIVE_INFINITY);
    this.data = new DefaultKeyedValues2D();

    this.maxChipX = maxChipX;
    this.maxChipY = maxChipY;
    if (chipSpace == null) {
        this.chipSpace = DEFAULT_CHIP_SPACE;
    } else {
        this.chipSpace = chipSpace.doubleValue();
    }

}

From source file:Converter.java

/**
 * Detects when the value of the text field (not necessarily the same number
 * as you'd get from getText) changes.//from  www . j av  a  2s.c o m
 */
public void propertyChange(PropertyChangeEvent e) {
    if ("value".equals(e.getPropertyName())) {
        Number value = (Number) e.getNewValue();
        sliderModel.setDoubleValue(value.doubleValue());
    }
}

From source file:cloudnet.weather.data.forecastio.FormatConverter.java

private void aggregateData(String inputDir) {
    LOGGER.info("read weather data...");

    File path = new File(inputDir);
    JSONParser parser = new JSONParser();

    for (File cityDir : path.listFiles()) {

        // If not a dir; next file in data path
        if (!cityDir.isDirectory()) {
            continue;
        }//from  w  w  w.j  a v a 2s . co  m

        LOGGER.trace(String.format("Processing %s...", cityDir.getAbsolutePath()));

        String[] extensions = { "json" };

        List<File> fileList = new ArrayList<>(FileUtils.listFiles(cityDir, extensions, false));

        for (File file : fileList) {

            try {
                try (Reader reader = new BufferedReader(new FileReader(file))) {
                    JSONObject jsonObject = (JSONObject) parser.parse(reader);

                    String timezone = (String) jsonObject.get("timezone");
                    locationTimeZone.put(cityDir.getName(), timezone);

                    Number currentTemp = (Number) ((JSONObject) jsonObject.get("currently")).get("temperature");
                    Number currentTime = (Number) ((JSONObject) jsonObject.get("currently")).get("time");

                    JSONObject hourlyForecast = (JSONObject) jsonObject.get("hourly");
                    JSONArray data = (JSONArray) hourlyForecast.get("data");

                    if (currentTemp != null) {
                        addWeatherdata(currentTime.longValue(), cityDir.getName(), currentTemp.doubleValue());
                    }

                    for (Object o : data) {
                        JSONObject oo = (JSONObject) o;

                        Number time = (Number) oo.get("time");
                        Number temp = (Number) oo.get("temperature");

                        long timeDiff = time.longValue() - currentTime.longValue();

                        if (temp != null) {
                            addWeatherdata(currentTime.longValue() + timeDiff, cityDir.getName(),
                                    temp.doubleValue());
                        }
                    }
                }

            } catch (IOException | ParseException e) {
                LOGGER.error("aggregateData", e);
            }
        }
    }
}