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:cz.autoclient.github.local.ReleaseFileLocal.java

public static long sizeToNumber(String size) {
    //System.out.println("Parsing size!");
    // Space divides the size and the multipier (k, M, G...)
    int firstSpace = size.indexOf(' ');
    double multiplier = 1;
    // replace bytes to leae the multiplier alone
    size = size.replaceFirst("\\s*(B|b|Bytes)\\s*$", "");
    //System.out.println("Size: "+size);
    // If the space wasn't replaced there's stull some stuff
    if (firstSpace < size.length()) {
        //get the stuff after the space (if any)
        String unit = size.substring(firstSpace + 1);
        switch (unit) {
        case "T":
            multiplier = 1e12;/*  w w w . j ava2s  . co  m*/
            break;
        case "G":
            multiplier = 1e9;
            break;
        case "M":
            multiplier = 1e6;
            break;
        case "k":
            multiplier = 1e3;
            break;
        }
    }
    return (long) (Double.parseDouble(size.substring(0, firstSpace)) * multiplier);
}

From source file:de.sub.goobi.metadaten.copier.ComposeFormattedRule.java

/**
 * The function typecast() converts the String arguments so that they can be
 * used by {@link String#format(String, Object...)}. Only arguments that are
 * referenced by number can be typecasted. If the format String contains
 * %2$02d?, the function will convert the second list object to long, if
 * the format String contains %02d? the function cannot tell which argument
 * is meant and thus doesnt do anything for it. TODO: check (test) and fix
 * it - especially catch continue/*from   www .  jav  a2 s. c o m*/
 *
 * @param format
 *            format String, to get the desired types from
 * @param elements
 *            arguments
 * @return the objects for the format command
 */
private static Object[] typecast(String format, List<String> elements) {
    Object[] result = elements.toArray();
    Matcher expressions = FORMAT_CODES_SCHEME.matcher(format);
    while (expressions.find()) {
        try {
            int i = Integer.parseInt(expressions.group(1)) - 1;
            switch (expressions.group(2).codePointAt(0)) {
            case 'A':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'C':
                result[i] = Integer.parseInt(elements.get(i));
                continue;
            case 'E':
            case 'G':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'T':
                result[i] = ISODateTimeFormat.dateElementParser().parseMillis(elements.get(i));
                continue;
            case 'X':
                result[i] = Long.parseLong(elements.get(i));
                continue;
            case 'a':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'c':
                result[i] = Integer.parseInt(elements.get(i));
                continue;
            case 'd':
                result[i] = Long.parseLong(elements.get(i));
                continue;
            case 'e':
            case 'f':
            case 'g':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'o':
                result[i] = Long.parseLong(elements.get(i));
                continue;
            case 't':
                result[i] = ISODateTimeFormat.dateElementParser().parseMillis(elements.get(i));
                continue;
            case 'x':
                result[i] = Long.parseLong(elements.get(i));
            }
        } catch (ArrayIndexOutOfBoundsException | ClassCastException | NumberFormatException e) {
        }
    }
    return result;
}

From source file:de.uniwue.info2.numerics.prec.DoublePrecisionFloat.java

@Override
protected String floatValueToBinaryString(String value) {
    double d = Double.parseDouble(value);
    String binary;//from   ww w.j av a2s  .  c  om
    if (d == 0) {
        binary = StringUtils.repeat("0", 64);
    } else {
        binary = Long.toBinaryString(Double.doubleToLongBits(d));
    }
    return binary;
}

From source file:ml.shifu.shifu.core.LR.java

public static LR loadFromString(String input) {
    String target = StringUtils.remove(StringUtils.remove(input, '['), ']');
    String[] ws = target.split(",");
    double[] weights = new double[ws.length];
    int index = 0;
    for (String weight : ws) {
        weights[index++] = Double.parseDouble(weight);
    }//from w ww.j  av  a  2s.c o  m
    return new LR(weights);
}

From source file:evaluation.loadGenerator.randomVariable.Zipf.java

public Zipf(String[] parameters) {
    super(parameters);
    if (parameters.length != numberOfParameters)
        throw new RuntimeException(errorMessage);
    try {/*from  ww  w  .j a  va  2  s  .c  o  m*/
        this.numberOfElements = Integer.parseInt(parameters[0]);
        this.exponent = Double.parseDouble(parameters[1]);
        // test:
        this.randomDataImpl.nextZipf(numberOfElements, exponent);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(errorMessage);
    }
}

From source file:com.tr8n.core.Utils.java

/**
 * Parses a double/* w  w w .ja v  a 2 s  . c o  m*/
 * @param obj
 * @return
 */
public static Double parseDouble(Object obj) {
    return Double.parseDouble("" + obj);
}

From source file:blue.soundObject.jmask.Quantizer.java

public static Quantizer loadFromXML(Element data) {
    Quantizer retVal = new Quantizer();

    Elements nodes = data.getElements();

    while (nodes.hasMoreElements()) {
        Element node = nodes.next();
        String nodeName = node.getName();
        String nodeVal = node.getTextString();

        if (nodeName.equals("gridSize")) {
            retVal.gridSize = Double.parseDouble(nodeVal);
        } else if (nodeName.equals("strength")) {
            retVal.strength = Double.parseDouble(nodeVal);
        } else if (nodeName.equals("offset")) {
            retVal.offset = Double.parseDouble(nodeVal);
        } else if (nodeName.equals("gridSizeTableEnabled")) {
            retVal.gridSizeTableEnabled = Boolean.valueOf(node.getTextString()).booleanValue();
        } else if (nodeName.equals("strengthTableEnabled")) {
            retVal.strengthTableEnabled = Boolean.valueOf(node.getTextString()).booleanValue();
        } else if (nodeName.equals("offsetTableEnabled")) {
            retVal.offsetTableEnabled = Boolean.valueOf(node.getTextString()).booleanValue();
        } else if (nodeName.equals("enabled")) {
            retVal.enabled = Boolean.valueOf(node.getTextString()).booleanValue();
        } else if (nodeName.equals("table")) {
            Table t = Table.loadFromXML(node);
            String tabInstance = node.getAttributeValue("tableId");

            if (tabInstance.equals("gridSizeTable")) {
                retVal.gridSizeTable = t;
            } else if (tabInstance.equals("strengthTable")) {
                retVal.strengthTable = t;
            } else if (tabInstance.equals("offsetTable")) {
                retVal.offsetTable = t;/*from w  w w.java  2s .  c  o  m*/
            }

        }

    }

    return retVal;
}

From source file:edu.scripps.fl.pubchem.xml.extract.XrefExtractor.java

public void checkXrefAgainstPanel(List<Xref> xrefs, List<Panel> panel) {
    for (Panel yy : panel) {
        for (int ii = 0; ii < xrefs.size(); ii++) {
            Xref xx = xrefs.get(ii);/*from ww w .j a  v a 2 s.c  o m*/
            String type = xx.getXrefType();
            if (type.equalsIgnoreCase("gene") || type.equalsIgnoreCase("protein")
                    || type.equalsIgnoreCase("nucleotide")) {
                Double idD = Double.parseDouble(xx.getXrefValue().toString());
                Integer id = idD.intValue();
                if (type.equalsIgnoreCase("gene")) {
                    List<Integer> genes = yy.getPanelGene();
                    if (genes != null) {
                        if (genes.contains(id))
                            xrefs.remove(xx);
                    }
                } else if (type.equalsIgnoreCase("protein") || type.equalsIgnoreCase("nucleotide")) {
                    List<PanelTarget> targets = yy.getPanelTarget();
                    if (targets != null) {
                        for (PanelTarget target : targets) {
                            if (target.getPanelTargetGi().equals(id)) {
                                xrefs.remove(xx);
                            }
                        }
                    }
                } else if (type.equalsIgnoreCase("taxonomy")) {
                    List<Integer> taxonomies = yy.getPanelTaxonomy();
                    if (taxonomies != null) {
                        if (taxonomies.contains(id))
                            xrefs.remove(xx);
                    }
                }
            }
        }
    }

}

From source file:com.github.jmabuin.blaspark.io.IO.java

public static DenseVector readVectorFromFileInHDFS(String file, Configuration conf) {

    try {//  w w  w .  j a v a2s .c  o  m
        FileSystem fs = FileSystem.get(conf);

        Path pt = new Path(file);

        //FileSystem fileSystem = FileSystem.get(context.getConfiguration());
        BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));
        String line;
        line = br.readLine();

        double vector[] = null;

        boolean arrayInfo = true;

        int i = 0;

        while (line != null) {

            if ((arrayInfo == true) && (line.charAt(0) == '%')) {
                arrayInfo = true;
                //LOG.info("JMAbuin:: Skipping line with %");
            } else if ((arrayInfo == true) && !(line.charAt(0) == '%')) {
                arrayInfo = false;
                String[] matrixInfo = line.split(" ");
                //LOG.info("JMAbuin:: Creating vector after line with %");
                vector = new double[Integer.parseInt(matrixInfo[0])];

            } else {
                vector[i] = Double.parseDouble(line);
                i++;
            }

            line = br.readLine();
        }

        br.close();

        return new DenseVector(vector);

    } catch (IOException e) {
        LOG.error("Error in " + IO.class.getName() + ": " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    }

    return null;
}

From source file:com.streamsets.pipeline.lib.parser.log.LEEFParser.java

@Override
public Field getExtFormatVersion(String val) {
    double leefVersion = Double.parseDouble(StringUtils.substringAfter(val, ":"));
    return Field.create(leefVersion);
}