Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

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

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

Returns a new double initialized to the value represented by the specified String , as performed by the valueOf method of class Double .

Usage

From source file:Main.java

public static double getDoubleProperty(Properties properties, String key, double defaultValue) {
    if (properties != null) {
        String value = properties.getProperty(key, "").trim();

        if (!value.equals("")) {
            try {
                return Double.parseDouble(value);
            } catch (NumberFormatException var6) {
                ;/*  ww  w.  j  a v a2 s. c o m*/
            }
        }
    }

    return defaultValue;
}

From source file:Main.java

public static boolean isInteger(String numStr) {
    try {// w  w w . j a  v a  2s  .com
        double parseDouble = Double.parseDouble(numStr);
        return parseDouble % 1 == 0;
    } catch (Exception exception) {
        return false;
    }
}

From source file:com.act.lcms.db.analysis.BestMoleculesPickerFromLCMSIonAnalysis.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/*from w ww.ja  va  2s. c o  m*/
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        HELP_FORMATTER.printHelp(BestMoleculesPickerFromLCMSIonAnalysis.class.getCanonicalName(), HELP_MESSAGE,
                opts, null, true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(BestMoleculesPickerFromLCMSIonAnalysis.class.getCanonicalName(), HELP_MESSAGE,
                opts, null, true);
        System.exit(1);
    }

    List<String> positiveReplicateResults = new ArrayList<>(
            Arrays.asList(cl.getOptionValues(OPTION_INPUT_FILES)));

    if (cl.hasOption(OPTION_MIN_OF_REPLICATES)) {
        HitOrMissReplicateFilterAndTransformer transformer = new HitOrMissReplicateFilterAndTransformer();

        List<IonAnalysisInterchangeModel> models = positiveReplicateResults.stream().map(file -> {
            try {
                return IonAnalysisInterchangeModel.loadIonAnalysisInterchangeModelFromFile(file);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }).collect(Collectors.toList());

        IonAnalysisInterchangeModel transformedModel = IonAnalysisInterchangeModel
                .filterAndOperateOnMoleculesFromMultipleReplicateModels(models, transformer);

        printInchisAndIonsToFile(transformedModel, cl.getOptionValue(OPTION_OUTPUT_FILE),
                cl.hasOption(OPTION_JSON_FORMAT));
        return;
    }

    Double minSnrThreshold = Double.parseDouble(cl.getOptionValue(OPTION_MIN_SNR_THRESHOLD));
    Double minIntensityThreshold = Double.parseDouble(cl.getOptionValue(OPTION_MIN_INTENSITY_THRESHOLD));
    Double minTimeThreshold = Double.parseDouble(cl.getOptionValue(OPTION_MIN_TIME_THRESHOLD));

    if (cl.hasOption(OPTION_GET_IONS_SUPERSET)) {
        List<IonAnalysisInterchangeModel> models = positiveReplicateResults.stream().map(file -> {
            try {
                return IonAnalysisInterchangeModel.loadIonAnalysisInterchangeModelFromFile(file);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }).collect(Collectors.toList());

        IonAnalysisInterchangeModel transformedModel = IonAnalysisInterchangeModel
                .getSupersetOfIonicVariants(models, minSnrThreshold, minIntensityThreshold, minTimeThreshold);

        printInchisAndIonsToFile(transformedModel, cl.getOptionValue(OPTION_OUTPUT_FILE),
                cl.hasOption(OPTION_JSON_FORMAT));
        return;
    }

    if (cl.hasOption(OPTION_THRESHOLD_ANALYSIS)) {

        if (positiveReplicateResults.size() > 1) {
            LOGGER.error("Since this is a threshold analysis, the number of positive replicates should be 1.");
            System.exit(1);
        }

        // We need to set this variable as a final since it is used in a lambda function below.
        final Set<String> ions = new HashSet<>();
        if (cl.hasOption(OPTION_FILTER_BY_IONS)) {
            ions.addAll(Arrays.asList(cl.getOptionValues(OPTION_FILTER_BY_IONS)));
        }

        HitOrMissSingleSampleFilterAndTransformer hitOrMissSingleSampleTransformer = new HitOrMissSingleSampleFilterAndTransformer(
                minIntensityThreshold, minSnrThreshold, minTimeThreshold, ions);

        IonAnalysisInterchangeModel model = IonAnalysisInterchangeModel.filterAndOperateOnMoleculesFromModel(
                IonAnalysisInterchangeModel.loadIonAnalysisInterchangeModelFromFile(
                        positiveReplicateResults.get(0)),
                hitOrMissSingleSampleTransformer);

        printInchisAndIonsToFile(model, cl.getOptionValue(OPTION_OUTPUT_FILE),
                cl.hasOption(OPTION_JSON_FORMAT));
    }
}

From source file:Main.java

public static double[] parseDoubleArrayFromHeader(String lineFromHeader) {
    lineFromHeader = lineFromHeader.replaceAll(",$", "");
    lineFromHeader = lineFromHeader.trim();
    String[] splitLine = lineFromHeader.split("\\s*,\\s*");

    double[] doubles = new double[splitLine.length];
    for (int i = 0; i < doubles.length; i++) {
        doubles[i] = Double.parseDouble(splitLine[i]);
    }/*from  ww w  . j  ava  2  s . c  o  m*/

    return doubles;
}

From source file:Main.java

static double getJavaVersion() {
    String version = System.getProperty("java.version");

    // on android this property equals to 0
    if (version.equals("0"))
        return 0;

    int pos = 0, count = 0;
    for (; pos < version.length() && count < 2; pos++) {
        if (version.charAt(pos) == '.')
            count++;/*  w w  w . ja va 2  s  .c  o  m*/
    }
    return Double.parseDouble(version.substring(0, pos - 1));
}

From source file:Main.java

public static double contentDoubleGet(Element e, double defaultDouble) {
    if (e == null) {
        return defaultDouble;
    } else {/*from   w w  w .  j  av  a  2  s.  co m*/
        String text = e.getTextContent();
        return Double.parseDouble(text);
    }
}

From source file:Main.java

public static double getDoubleFrom(String txt) {
    double val = 0;

    if (!"".equals(txt.replace(" ", "")) && !".".equals(txt) && !",".equals(txt) && !"-".equals(txt)) {
        val = Double.parseDouble(txt);
    }/*from w  w w .  jav  a2s  . com*/

    return val;
}

From source file:Main.java

public static double parseNmeaFormat(String degrees, String direction) {

    double latlong = 0.0;
    double temp1 = Double.parseDouble(degrees);
    double temp2 = Math.floor(temp1 / 100);
    double temp3 = (temp1 / 100 - temp2) / 0.6;

    if (DIRECTION_SOUTH.equals(direction) || DIRECTION_WEST.equals(direction)) {
        latlong = -(temp2 + temp3);//from   w  w w.j av  a  2 s  .c  o m
    } else if (DIRECTION_NORTH.equals(direction) || DIRECTION_EAST.equals(direction)) {
        latlong = (temp2 + temp3);
    }

    return latlong;
}

From source file:Main.java

/**
 * Str format./*from   w w w  .  j  av a2 s  . com*/
 * 
 * @param v
 *            the v
 * @return the string
 */
public static String strFormat(String v) {
    if (v == null) {
        return "0.00";
    }
    double dv = Double.parseDouble(v);
    DecimalFormat nf = new DecimalFormat("#.##");
    nf.applyPattern("0.00");
    return nf.format(dv);
}

From source file:Main.java

public static double getDouble(Node aNode, String attr, double defaultValue) {
    if (aNode.getAttributes().getNamedItem(attr) != null) {
        String attrString = aNode.getAttributes().getNamedItem(attr).getNodeValue();
        double year = Double.parseDouble(attrString);
        return year;
    } else {//www  .  java 2  s .c o m
        return defaultValue;
    }
}