Example usage for java.lang Double isNaN

List of usage examples for java.lang Double isNaN

Introduction

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

Prototype

public boolean isNaN() 

Source Link

Document

Returns true if this Double value is a Not-a-Number (NaN), false otherwise.

Usage

From source file:net.grinder.SingleConsole.java

private static Object getRealDoubleValue(Double doubleValue) {
    if (doubleValue == null) {
        return (double) 0;
    }//w  ww.  jav a  2s  . com
    return (doubleValue.isInfinite() || doubleValue.isNaN()) ? (double) 0 : doubleValue;
}

From source file:gamlss.algorithm.GlimFit.java

/** Check whether vector wv has some NaN values 
 * and if it does sets NaNs to zero./*from   w  w w. j  a  va  2s  .  c o m*/
 * @param v = (eta-os)+dldp/(dr*wt)
 * @return v = (eta-os)+dldp/(dr*wt) or zeros*/
private ArrayRealVector wvCheck(final ArrayRealVector v) {
    if (v.isNaN()) {
        double[] tempA = new double[v.getDimension()];
        for (int i = 0; i < tempA.length; i++) {
            Double vD = v.getEntry(i);
            if (vD.isNaN()) {
                tempA[i] = 0.0;
            } else {
                tempA[i] = vD;
            }
        }
        return new ArrayRealVector(tempA, false);
    }
    return v;
}

From source file:eu.fthevenet.binjr.sources.jrds.adapters.JrdsDataAdapter.java

@Override
public CsvDecoder<Double> getDecoder() {
    final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
            .withZone(getTimeZoneId());/*from   w  w w.java2 s.  co m*/
    return new CsvDecoder<>(getEncoding(), DELIMITER, DoubleTimeSeriesProcessor::new, s -> {
        Double val = Double.parseDouble(s);
        return val.isNaN() ? 0 : val;
    }, s -> ZonedDateTime.parse(s, formatter));
}

From source file:fr.cph.stock.external.YahooExternalDataAccess.java

@Override
public final List<Company> getCompaniesData(final List<String> yahooIds) throws YahooException {
    List<Company> companies = new ArrayList<Company>();

    String requestQuotes = "select * from yahoo.finance.quotes where symbol in (" + getFormattedList(yahooIds)
            + ")";
    Yahoo yahoo = new Yahoo(requestQuotes);
    JSONObject json = yahoo.getJSONObject();
    JSONArray jsonResults = getJSONArrayFromJSONObject(json);
    for (int j = 0; j < jsonResults.size(); j++) {
        JSONObject jsonCompany = jsonResults.getJSONObject(j);
        Company company = new Company();
        company.setYahooId(jsonCompany.optString("symbol"));
        company.setManual(false);/*from  w w  w. ja  v  a  2s  . c o  m*/
        if (jsonCompany.optString("StockExchange").equals("null")) {
            company = getCompanyInfo(company);
            if (company.getSector() != null && company.getIndustry() != null
                    && company.getMarketCapitalization() != null) {
                company.setRealTime(false);
                company.setMarket(guessMarket(company.getYahooId()));
                company.setCurrency(Market.getCurrency(company.getMarket()));
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.DATE, -5);
                try {
                    List<Company> temp = getCompanyDataHistory(company.getYahooId(), cal.getTime(), null);
                    company.setQuote(temp.get(0).getQuote());
                } catch (YahooException e) {
                    LOG.info(e.getMessage(), e);
                }
                companies.add(company);
            } else {
                throw new YahooUnknownTickerException(
                        jsonCompany.optString("symbol") + YahooUnknownTickerException.TOCKEN_UNKNOWN);
            }
        } else {
            company.setName(WordUtils.capitalizeFully(jsonCompany.optString("Name")));
            company.setMarket(Market.getMarket(jsonCompany.optString("StockExchange").toUpperCase()));

            company.setCurrency(Market.getCurrency(company.getMarket()));
            if (!jsonCompany.optString("DividendYield").equals("null")) {
                company.setYield(Double.valueOf(jsonCompany.optString("DividendYield")));
            }
            company.setQuote(Double.valueOf(jsonCompany.optString("LastTradePriceOnly")));
            String marketCap = jsonCompany.optString("MarketCapitalization");
            if (marketCap != null && !marketCap.equals("null") && !marketCap.equals("")) {
                company.setMarketCapitalization(marketCap);
            }
            Double previousClose = jsonCompany.optDouble("PreviousClose");
            if (previousClose != null && !previousClose.isNaN()) {
                company.setYesterdayClose(previousClose);
            } else {
                company.setYesterdayClose(0.0);
            }
            company.setChangeInPercent(jsonCompany.optString("ChangeinPercent"));
            Double yearLow = jsonCompany.optDouble("YearLow");
            if (!yearLow.isNaN()) {
                company.setYearLow(yearLow);
            }
            Double yearHigh = jsonCompany.optDouble("YearHigh");
            if (!yearHigh.isNaN()) {
                company.setYearHigh(yearHigh);
            }
            company.setRealTime(true);
            company.setFund(false);
            companies.add(company);
        }
    }
    return companies;
}

From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java

private BoxAndWhiskerCategoryDataset getDataset(SimpleFeatureCollection features, String[] fields) {
    minMaxVisitor.reset();/* w ww. j  a  va  2s. co m*/

    Expression[] expression = new Expression[fields.length];
    Map<String, List<Double>> listMap = new TreeMap<String, List<Double>>();
    for (int index = 0; index < expression.length; index++) {
        expression[index] = ff.property(fields[index]);
        listMap.put(fields[index], new ArrayList<Double>());
    }

    SimpleFeatureIterator featureIter = features.features();
    try {
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();
            for (int index = 0; index < expression.length; index++) {
                Double val = expression[index].evaluate(feature, Double.class);
                if (val == null || val.isNaN() || val.isInfinite()) {
                    continue;
                }
                minMaxVisitor.visit(val, val);
                listMap.get(fields[index]).add(val);
            }
        }
    } finally {
        featureIter.close();
    }

    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (int index = 0; index < fields.length; index++) {
        dataset.add(listMap.get(fields[index]), "Series1", fields[index]); //$NON-NLS-1$
    }
    return dataset;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DRNormalizedController.java

/**
 * Perform normalization on velocities//from  www  .  java  2  s  .  c om
 */
protected Double normalize(Double velocity) {
    //check which values will become 0% and 100%
    Double bottomNormalize = Double.parseDouble(dRNormalizedPlotPanel.getBottomTextField().getText());
    Double topNormalize = Double.parseDouble(dRNormalizedPlotPanel.getTopTextField().getText());

    if (velocity == null) {
        return velocity;
    } else if (velocity.isNaN()) {
        return velocity;
    }
    return 100 * (velocity - bottomNormalize) / (topNormalize - bottomNormalize);
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRInputController.java

/**
 * Create and return table model for top panel table. Table contains
 * condition number, treatment name, concentration and concentration unit
 * and replicate slopes.//from   w  ww. j  a  va2 s .c  o  m
 *
 * @param processedConditions
 * @return
 */
private NonEditableTableModel createTableModel(List<PlateCondition> processedConditions) {
    List<Integer> conditionNumberList = new ArrayList();
    List<String> treatmentNameList = new ArrayList();
    List<Double> concentrationList = new ArrayList();
    List<String> concentrationUnitList = new ArrayList();
    List<Double[]> slopesList = new ArrayList();
    //start counting from 1, easier for user
    Integer i = 1;
    for (PlateCondition condition : processedConditions) {
        //1 platecondition might have multiple treatments
        List<Treatment> treatmentList = condition.getTreatmentList();

        for (Treatment treatment : treatmentList) {

            conditionNumberList.add(i);
            treatmentNameList.add(treatment.getTreatmentType().getName());
            concentrationList.add(treatment.getConcentration());
            concentrationUnitList.add(treatment.getConcentrationUnit());
            slopesList.add(doseResponseController.getLinearResultsAnalysisMap().get(condition).getSlopes());

        }
        i++;
    }
    int maximumNumberOfReplicates = AnalysisUtils.getMaximumNumberOfReplicates(processedConditions);
    Object[][] data = new Object[conditionNumberList.size()][maximumNumberOfReplicates + 4];
    for (int rowIndex = 0; rowIndex < conditionNumberList.size(); rowIndex++) {
        for (int columnIndex = 4; columnIndex < slopesList.get(rowIndex).length + 4; columnIndex++) {
            Double slope = slopesList.get(rowIndex)[columnIndex - 4];
            if (slope != null && !slope.isNaN()) {
                // round to three decimals slopes and coefficients
                slope = AnalysisUtils.roundThreeDecimals(slopesList.get(rowIndex)[columnIndex - 4]);
                // show in table slope + (coefficient)
                data[rowIndex][columnIndex] = slope;
            } else if (slope == null) {
                data[rowIndex][columnIndex] = "excluded";
            } else if (slope.isNaN()) {
                data[rowIndex][columnIndex] = "NaN";
            }
        }
        // first column contains condition numbers
        data[rowIndex][0] = conditionNumberList.get(rowIndex);
        // second to fourth will contain treatment information
        data[rowIndex][1] = treatmentNameList.get(rowIndex);
        data[rowIndex][2] = concentrationList.get(rowIndex);
        data[rowIndex][3] = concentrationUnitList.get(rowIndex);
    }
    // array of column names for table model
    String[] columnNames = new String[data[0].length];
    columnNames[0] = "Condition number";
    columnNames[1] = "Treatment";
    columnNames[2] = "Concentration";
    columnNames[3] = "Unit";
    for (int x = 4; x < columnNames.length; x++) {
        columnNames[x] = "Repl " + (x - 3);
    }

    NonEditableTableModel nonEditableTableModel = new NonEditableTableModel();
    nonEditableTableModel.setDataVector(data, columnNames);
    return nonEditableTableModel;
}

From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java

private XYDataset getScatterPlotData(SimpleFeatureCollection features, String xField, String yField) {
    XYSeries xySeries = new XYSeries(features.getSchema().getTypeName());
    minMaxVisitor.reset();//from  w w  w  . j a v  a 2s  .c  om

    Expression xExpression = ff.property(xField);
    Expression yExpression = ff.property(yField);

    SimpleFeatureIterator featureIter = features.features();
    try {
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();

            Double xVal = xExpression.evaluate(feature, Double.class);
            if (xVal == null || xVal.isNaN() || xVal.isInfinite()) {
                continue;
            }

            Double yVal = yExpression.evaluate(feature, Double.class);
            if (yVal == null || yVal.isNaN() || yVal.isInfinite()) {
                continue;
            }

            minMaxVisitor.visit(xVal, yVal);
            xySeries.add(new XYDataItem2(feature, xVal, yVal));
        }
    } finally {
        featureIter.close();
    }

    return new XYSeriesCollection(xySeries);
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRInputController.java

/**
 * Table model for bottom table: starts from analysis group.
 *
 * @param analysisGroup//from  w  w w.jav  a 2 s .  c  om
 * @return
 */
private NonEditableTableModel createTableModel(AreaDoseResponseAnalysisGroup analysisGroup) {
    LinkedHashMap<Double, String> concentrationsMap = analysisGroup.getConcentrationsMap()
            .get(analysisGroup.getTreatmentToAnalyse());
    LinkedHashMap<PlateCondition, List<Double>> velocitiesMap = analysisGroup.getVelocitiesMap();
    //when removing all conditions
    if (velocitiesMap.isEmpty()) {
        return new NonEditableTableModel();
    }

    int maxReplicates = 0;
    for (List<Double> value : velocitiesMap.values()) {
        int replicates = value.size();
        if (replicates > maxReplicates) {
            maxReplicates = replicates;
        }
    }

    Object[][] data = new Object[velocitiesMap.size()][maxReplicates + 2];
    int i = 0;
    int controlIndex = 100;
    int rowIndex = 0;

    for (Map.Entry<PlateCondition, List<Double>> entry : velocitiesMap.entrySet()) {
        //check if this platecondition is the control, save index for table
        for (Treatment treatment : entry.getKey().getTreatmentList()) {
            if (treatment.getTreatmentType().getName().contains("ontrol")) {
                controlIndex = i;
            }
        }
        i++;

        int columnIndex = 2;
        for (Double velocity : entry.getValue()) {

            if (velocity != null && !velocity.isNaN()) {
                // round to three decimals slopes and coefficients
                Double slope = AnalysisUtils.roundThreeDecimals(velocity);
                // show in table slope + (coefficient)
                data[rowIndex][columnIndex] = slope;
            } else if (velocity == null) {
                data[rowIndex][columnIndex] = "excluded";
            } else if (velocity.isNaN()) {
                data[rowIndex][columnIndex] = "NaN";
            }

            columnIndex++;
        }
        rowIndex++;
    }

    if (controlIndex != 100) {
        data[controlIndex][0] = 0.0;
        data[controlIndex][1] = "--";
    }
    rowIndex = 0;
    //if user only selects control, the concentrationsmap is null
    if (concentrationsMap != null) {
        for (Map.Entry<Double, String> entry : concentrationsMap.entrySet()) {
            if (rowIndex >= controlIndex) {
                data[rowIndex + 1][0] = entry.getKey();
                data[rowIndex + 1][1] = entry.getValue();
            } else {
                data[rowIndex][0] = entry.getKey();
                data[rowIndex][1] = entry.getValue();
            }

            rowIndex++;
        }
    }
    // array of column names for table model
    String[] columnNames = new String[data[0].length];
    columnNames[0] = "Conc of " + analysisGroup.getTreatmentToAnalyse();
    columnNames[1] = "Unit";
    for (int x = 2; x < columnNames.length; x++) {
        columnNames[x] = "Repl " + (x - 1);
    }

    NonEditableTableModel nonEditableTableModel = new NonEditableTableModel();
    nonEditableTableModel.setDataVector(data, columnNames);
    return nonEditableTableModel;

}

From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java

private double[] getValues(SimpleFeatureCollection features, String field) {
    minMaxVisitor.reset();/* w  w  w  . j  a v  a2 s . co  m*/

    double[] values = new double[features.size()];
    SimpleFeatureIterator featureIter = features.features();
    try {
        Expression expression = ff.property(field);
        int index = 0;
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();
            Double val = expression.evaluate(feature, Double.class);
            if (val == null || val.isNaN() || val.isInfinite()) {
                continue;
            }
            values[index++] = val;
            minMaxVisitor.visit(val, val);
        }
    } finally {
        featureIter.close();
    }

    return values;
}