Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

In this page you can find the example usage for java.lang Double doubleValue.

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:com.opengamma.analytics.financial.interestrate.market.PresentValueCurveSensitivityMarket.java

/**
 * Return a new sensitivity by sorting the times and adding the values at duplicated times.
 * @return The cleaned sensitivity.//www.j  a  v  a 2 s. co  m
 */
public PresentValueCurveSensitivityMarket clean() {
    //TODO: improve the sorting algorithm.
    Map<String, List<DoublesPair>> resultYield = new HashMap<String, List<DoublesPair>>();
    for (final String name : _sensitivityYieldCurve.keySet()) {
        List<DoublesPair> list = _sensitivityYieldCurve.get(name);
        List<DoublesPair> listClean = new ArrayList<DoublesPair>();
        Set<Double> set = new TreeSet<Double>();
        for (final DoublesPair pair : list) {
            set.add(pair.getFirst());
        }
        for (Double time : set) {
            double sensi = 0;
            for (int looplist = 0; looplist < list.size(); looplist++) {
                if (list.get(looplist).getFirst().doubleValue() == time.doubleValue()) {
                    sensi += list.get(looplist).second;
                }
            }
            listClean.add(new DoublesPair(time, sensi));
        }
        resultYield.put(name, listClean);
    }
    Map<String, List<DoublesPair>> resultPrice = new HashMap<String, List<DoublesPair>>();
    for (final String name : _sensitivityPriceCurve.keySet()) {
        List<DoublesPair> list = _sensitivityPriceCurve.get(name);
        List<DoublesPair> listClean = new ArrayList<DoublesPair>();
        Set<Double> set = new TreeSet<Double>();
        for (final DoublesPair pair : list) {
            set.add(pair.getFirst());
        }
        for (Double time : set) {
            double sensi = 0;
            for (int looplist = 0; looplist < list.size(); looplist++) {
                if (list.get(looplist).getFirst().doubleValue() == time.doubleValue()) {
                    sensi += list.get(looplist).second;
                }
            }
            listClean.add(new DoublesPair(time, sensi));
        }
        resultPrice.put(name, listClean);
    }
    return new PresentValueCurveSensitivityMarket(resultYield, resultPrice);
}

From source file:mondrian.udf.InverseNormalUdf.java

public Object execute(Evaluator evaluator, Argument[] args) {
    final Object argValue = args[0].evaluateScalar(evaluator);
    LOGGER.debug("Inverse Normal argument was : " + argValue);
    if (!(argValue instanceof Number)) {
        // Argument might be a RuntimeException indicating that
        // the cache does not yet have the required cell value. The
        // function will be called again when the cache is loaded.
        return null;
    }/*w w  w  .  j a v  a 2s .  com*/

    final Double d = new Double(((Number) argValue).doubleValue());
    LOGGER.debug("Inverse Normal argument as Double was : " + d);

    if (d.isNaN()) {
        return null;
    }

    // If probability is nonnumeric or
    //   probability < 0 or
    //   probability > 1,
    // returns an error.
    double dbl = d.doubleValue();
    if (dbl < 0.0 || dbl > 1.0) {
        LOGGER.debug("Invalid value for inverse normal distribution: " + dbl);
        throw new MondrianEvaluationException("Invalid value for inverse normal distribution: " + dbl);
    }
    try {
        Double result = new Double(nd.inverseCumulativeProbability(dbl));
        LOGGER.debug("Inverse Normal result : " + result.doubleValue());
        return result;
    } catch (MathException e) {
        LOGGER.debug("Exception calculating inverse normal distribution: " + dbl, e);
        throw new MondrianEvaluationException("Exception calculating inverse normal distribution: " + dbl);
    }
}

From source file:org.hawkular.alerts.engine.util.NelsonData.java

private boolean rule4(Double sample) {
    if (null == rule4PreviousSample || sample.doubleValue() == rule4PreviousSample.doubleValue()) {
        rule4PreviousSample = sample;// w  ww .ja va2 s .c o  m
        rule4PreviousDirection = "=";
        rule4Count = 0;
        return false;
    }

    String sampleDirection = (sample > rule4PreviousSample) ? ">" : "<";

    if (sampleDirection.equals(rule4PreviousDirection)) {
        rule4Count = 0;
    } else {
        ++rule4Count;
    }

    rule4PreviousSample = sample;
    rule4PreviousDirection = sampleDirection;

    return Math.abs(rule4Count) >= 14;
}

From source file:geogebra.kernel.AlgoFrequency.java

protected final void compute() {

    // Validate input arguments
    //=======================================================

    if (!dataList.isDefined() || dataList.size() == 0) {
        frequency.setUndefined();//from ww  w. ja va 2 s. com
        return;
    }

    if (!(dataList.getElementType() == GeoElement.GEO_CLASS_TEXT
            || dataList.getElementType() == GeoElement.GEO_CLASS_NUMERIC)) {
        frequency.setUndefined();
        return;
    }

    if (classList != null) {
        if (classList.getElementType() != GeoElement.GEO_CLASS_NUMERIC || classList.size() < 2) {
            frequency.setUndefined();
            return;
        }
    }

    if (density != null) {
        if (density.getDouble() <= 0) {
            frequency.setUndefined();
            return;
        }
    }

    frequency.setDefined(true);
    frequency.clear();
    if (value != null)
        value.clear();

    double numMax = 0, numMin = 0;
    boolean doCumulative = isCumulative != null && isCumulative.getBoolean();

    // Load the data into f, an instance of Frequency class 
    //=======================================================

    Frequency f = new Frequency();
    for (int i = 0; i < dataList.size(); i++) {
        if (dataList.getElementType() == GeoElement.GEO_CLASS_TEXT)
            f.addValue(((GeoText) dataList.get(i)).toValueString());
        if (dataList.getElementType() == GeoElement.GEO_CLASS_NUMERIC)
            f.addValue(((GeoNumeric) dataList.get(i)).getDouble());
    }

    // If classList does not exist, 
    // get the unique value list and compute frequencies for this list  
    //=======================================================

    // handle string data
    if (dataList.getElementType() == GeoElement.GEO_CLASS_TEXT) {

        Iterator itr = f.valuesIterator();
        String strMax = (String) itr.next();
        String strMin = strMax;
        itr = f.valuesIterator();

        while (itr.hasNext()) {
            String s = (String) itr.next();
            if (s.compareTo(strMax) > 0)
                strMax = s;
            if (s.compareTo(strMin) < 0)
                strMin = s;
            GeoText text = new GeoText(cons);
            text.setTextString(s);
            value.add(text);
            if (classList == null)
                if (doCumulative)
                    frequency.add(new GeoNumeric(cons, f.getCumFreq((Comparable) s)));
                else
                    frequency.add(new GeoNumeric(cons, f.getCount((Comparable) s)));
        }
    }

    // handle numeric data
    else {
        Iterator itr = f.valuesIterator();
        numMax = (Double) itr.next();
        numMin = numMax;
        itr = f.valuesIterator();

        while (itr.hasNext()) {
            Double n = (Double) itr.next();
            if (n > numMax)
                numMax = n.doubleValue();
            if (n < numMin)
                numMin = n.doubleValue();
            value.add(new GeoNumeric(cons, n));

            if (classList == null)
                if (doCumulative)
                    frequency.add(new GeoNumeric(cons, f.getCumFreq((Comparable) n)));
                else
                    frequency.add(new GeoNumeric(cons, f.getCount((Comparable) n)));
        }
    }

    // If classList exists, compute frequencies using the classList
    //=======================================================

    if (classList != null) {

        double lowerClassBound = 0;
        double upperClassBound = 0;
        double classFreq = 0;

        //set density conditions
        boolean hasDensity = false;
        if (useDensity != null)
            hasDensity = useDensity.getBoolean();

        double densityValue = 1; // default density
        if (density != null) {
            densityValue = density.getDouble();
        }

        double cumulativeClassFreq = 0;
        double swap;
        int length = classList.size();
        for (int i = 1; i < length; i++) {

            lowerClassBound = ((GeoNumeric) classList.get(i - 1)).getDouble();
            upperClassBound = ((GeoNumeric) classList.get(i)).getDouble();
            boolean increasing = true;
            if (lowerClassBound > upperClassBound) {
                swap = upperClassBound;
                upperClassBound = lowerClassBound;
                lowerClassBound = swap;
                increasing = false;
            }
            classFreq = f.getCumFreq((Comparable) upperClassBound) - f.getCumFreq((Comparable) lowerClassBound)
                    + f.getCount((Comparable) lowerClassBound);
            if ((i != length - 1 && increasing) || (i != 1 && !increasing))
                classFreq -= f.getCount((Comparable) upperClassBound);

            //   System.out.println(" =================================");
            //   System.out.println("class freq: " + classFreq + "   " + density);
            if (hasDensity) {
                classFreq = densityValue * classFreq / (upperClassBound - lowerClassBound);
            }
            if (doCumulative)
                cumulativeClassFreq += classFreq;
            //   System.out.println("class freq: " + classFreq);

            // add the frequency to the output GeoList
            frequency.add(new GeoNumeric(cons, doCumulative ? cumulativeClassFreq : classFreq));

        }

        // handle the last (highest) class frequency specially
        // it must also count values equal to the highest class bound  

    }
}

From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java

private void importDataToWorkbook(HSSFWorkbook xlsBook, Workbook workbook) {
    if (workbook.getObservations() != null) {
        HSSFSheet observationSheet = xlsBook.getSheetAt(1);
        int xlsRowIndex = 1; //row 0 is the header row
        for (MeasurementRow wRow : workbook.getObservations()) {
            HSSFRow xlsRow = observationSheet.getRow(xlsRowIndex);
            for (MeasurementData wData : wRow.getDataList()) {
                String label = wData.getLabel();
                int xlsColIndex = findColumn(observationSheet, label);
                Cell cell = xlsRow.getCell(xlsColIndex);
                String xlsValue = "";

                if (cell != null) {
                    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                        Double doubleVal = Double.valueOf(cell.getNumericCellValue());
                        Integer intVal = Integer.valueOf(doubleVal.intValue());
                        if (Double.parseDouble(intVal.toString()) == doubleVal.doubleValue()) {
                            xlsValue = intVal.toString();
                        } else {
                            xlsValue = doubleVal.toString();
                        }/* ww w .  j a v  a2s. com*/

                    } else
                        xlsValue = cell.getStringCellValue();
                }
                wData.setValue(xlsValue);
            }
            xlsRowIndex++;
        }
    }
}

From source file:net.sourceforge.eclipsetrader.core.ui.dialogs.ExchangeRateDialog.java

private void update() {
    try {/*w  w  w . ja  v  a  2s.c o  m*/
        Date date = dateParse.parse(text.getText());
        Double r = CurrencyConverter.getInstance().getExchangeRatio(date, from.getText(), to.getText());
        if (r == null) {
            r = CurrencyConverter.getInstance().getExchangeRatio(date, to.getText(), from.getText());
            if (r != null)
                r = new Double(1 / r.doubleValue());
        }
        if (r == null)
            r = CurrencyConverter.getInstance().getExchangeRatio(from.getText(), to.getText());
        if (r != null)
            ratio.setSelection((int) (r.doubleValue() * Math.pow(10, ratio.getDigits())));
        else
            ratio.setSelection((int) (1 * Math.pow(10, ratio.getDigits())));
    } catch (Exception e) {
        ratio.setSelection((int) (1 * Math.pow(10, ratio.getDigits())));
        LogFactory.getLog(getClass()).warn(e);
    }
    if (getButton(IDialogConstants.OK_ID) != null)
        getButton(IDialogConstants.OK_ID).setEnabled(!from.getText().equals(to.getText()));
}

From source file:org.hyperic.hq.plugin.mysql_stats.MySqlStatsMeasurementPlugin.java

private double getGlobalStatusMetric(Metric metric)
        throws NumberFormatException, SQLException, JDBCQueryCacheException {
    JDBCQueryCache globalStatus = getQueryCache(metric, SHOW_GLOBAL_STATUS);
    String valColumn = metric.getObjectProperty("value");
    String alias = metric.getAttributeName();
    if (metric.isAvail()) {
        return getAvailability(metric).getValue();
    } else {/*w  w w . jav a  2s.  c  o m*/
        Connection conn = getCachedConnection(metric);
        Double val = Double.valueOf(globalStatus.get(conn, alias, valColumn).toString());
        return val.doubleValue();
    }
}

From source file:org.n52.ifgicopter.spf.input.LastDataPostgisInputPlugin.java

@Override
protected JPanel makeControlPanel() {
    if (this.controlPanel == null) {
        this.controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));

        JButton startButton = new JButton("Start");
        startButton.addActionListener(new ActionListener() {

            @Override//w w  w  .j  a v  a 2 s.com
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        start();
                    }
                });
            }
        });
        this.controlPanel.add(startButton);
        JButton stopButton = new JButton("Stop");
        stopButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        stop();
                    }
                });
            }
        });
        this.controlPanel.add(stopButton);

        JLabel minTimeLabel = new JLabel("Mimium time database queries in milliseconds:");
        this.controlPanel.add(minTimeLabel);
        SpinnerModel model = new SpinnerNumberModel(this.minimumMillisBetweenRequests, 10d, 3600000d, 10d);
        JSpinner sleepTimeSpinner = new JSpinner(model);
        sleepTimeSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                Object source = e.getSource();
                if (source instanceof JSpinner) {
                    final JSpinner spinner = (JSpinner) source;

                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            Double value = (Double) spinner.getValue();
                            value = Double.valueOf(value.doubleValue() * 1000d);
                            setMinimumMillisBetweenRequests(value.longValue());
                        }
                    });
                } else
                    log.warn("Unsupported ChangeEvent, need JSpinner as source: " + e);
            }
        });
        // catch text change events without loosing the focus
        // JSpinner.DefaultEditor editor = (DefaultEditor) sleepTimeSpinner.getEditor();
        // not implemented, can be done using KeyEvent, but then it hast to be checked where in the text
        // field the keystroke was etc. --> too complicated.

        this.controlPanel.add(sleepTimeSpinner);
    }

    return this.controlPanel;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.MyLogarithmicAxis.java

/**
 * Main change of Logarithmic class that overwrites super method. Calculates the values of the
 * System.out.println("Upper = " + aUpper + "\tCeiling = " + ceiling); tick labels for the axis, storing
 * the results in the tick label list (ready for drawing).
 * //from www  . ja v  a 2  s . co  m
 * @param g2 the graphics device.
 * @param dataArea the area in which the plot should be drawn.
 * @param edge Rectangle edge for axis location.
 * @return A list of ticks.
 */
@Override
public List<?> refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

    // Ticklist that has to be filled with sensible values
    List<Tick> ticks = new ArrayList<Tick>();

    // Formatting of the tick labels
    TextAnchor anchor = null;
    TextAnchor rotationAnchor = null;
    double angle = 0.0;
    if (isVerticalTickLabels()) {
        if (edge == RectangleEdge.LEFT) {
            anchor = TextAnchor.BOTTOM_CENTER;
            rotationAnchor = TextAnchor.BOTTOM_CENTER;
            angle = -Math.PI / 2.0;
        } else {
            anchor = TextAnchor.BOTTOM_CENTER;
            rotationAnchor = TextAnchor.BOTTOM_CENTER;
            angle = Math.PI / 2.0;
        }
    } else {
        if (edge == RectangleEdge.LEFT) {
            anchor = TextAnchor.CENTER_RIGHT;
            rotationAnchor = TextAnchor.CENTER_RIGHT;
        } else {
            anchor = TextAnchor.TOP_CENTER;
            rotationAnchor = TextAnchor.TOP_CENTER;
        }
    }

    List<Double> myticks = new ArrayList<Double>();

    double lowerBound = dataRange.getLowerBound();
    double upperBound = dataRange.getUpperBound();

    // Select minimal tick set that fully contains the data range
    for (int i = 0; i < allticks.length - 1; i++) {
        if (allticks[i + 1] > lowerBound && allticks[i] <= upperBound) {
            myticks.add(new Double(allticks[i]));
        }
    }

    boolean isLastTickAdded = false;
    final boolean sci = (myticks.size() > 4);

    // Add all ticks that were selected before and their eight following unlabeled subticks
    for (final Double tick : myticks) {
        final double t = tick.doubleValue();
        ticks.add(new NumberTick(tick, toString(t, sci), anchor, rotationAnchor, angle));
        if (t < upperBound) {
            for (int j = 2; j < 10; j++) {
                double s = (t == 0.0 ? allticks[1] / 10.0 : t) * j; // to allows subticks from 0
                String label = "";
                if (s >= upperBound) {
                    isLastTickAdded = true;
                    label = toString(s, sci);
                }
                ticks.add(new NumberTick(new Double(s), label, anchor, rotationAnchor, angle));
                if (isLastTickAdded) {
                    break;
                }
            }
        }
    }

    // Add the very last tick value
    if (!isLastTickAdded) {
        Double t = new Double(computeLogCeil(upperBound));
        ticks.add(new NumberTick(t, toString(t, sci), anchor, rotationAnchor, angle));
    }

    return ticks;
}

From source file:org.amanzi.awe.render.network.NetworkRenderer.java

/**
 * Get azimuth and beamwidth/* w  w w. jav a  2s  .  com*/
 * 
 * @param site
 * @param sector
 * @param i
 * @return
 */
private Pair<Double, Double> getSectorParameters(final ISectorElement sector, final int i,
        final int sectorCount) {
    Double azimuth = sector.getAzimuth();
    Double beamwidth = sector.getBeamwidth();
    if ((azimuth == null) || (beamwidth == null) || (beamwidth == 0)) {
        beamwidth = FULL_CIRCLE / (sectorCount == 0 ? 1 : sectorCount);
        azimuth = beamwidth * i;

        beamwidth = beamwidth.doubleValue() * 0.8;
    }
    return new ImmutablePair<Double, Double>(azimuth, beamwidth);
}