Example usage for java.lang Integer doubleValue

List of usage examples for java.lang Integer doubleValue

Introduction

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

Prototype

public double doubleValue() 

Source Link

Document

Returns the value of this Integer as a double after a widening primitive conversion.

Usage

From source file:com.act.lcms.MassCalculator.java

public static Double calculateMass(IndigoObject mol) {
    String formula = mol.grossFormula();
    double out = 0.0;
    String[] molCounts = StringUtils.split(formula, " ");
    for (String atomEntry : molCounts) {
        //Extract the atom count
        Matcher matcher = MOL_COUNT_PATTERN.matcher(atomEntry);
        if (!matcher.matches()) {
            throw new RuntimeException("Found unexpected malformed atomEntry: " + atomEntry);
        }//from ww w.j  a  v  a2  s .c  om
        String element = matcher.group(1);
        String countStr = matcher.group(2);

        Integer count = 1;
        if (countStr != null && !countStr.isEmpty()) {
            count = Integer.parseInt(countStr);
        }

        if (!ATOMIC_WEIGHTS.containsKey(element)) {
            throw new RuntimeException("Atomic weights table is missing an expected element: " + element);
        }

        out += ATOMIC_WEIGHTS.get(element) * count.doubleValue();
    }

    // TODO: log difference between mol.molecularWeight(), mol.monoisotopicMass(), and our value.
    return out;
}

From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java

/**
 * Safely converts an object to a BigInteger. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    object to parse//from   w w  w.j  a v a2 s . c o  m
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static BigDecimal toBigDecimal(Object obj) {

    /* Switch on class and convert to BigDecimal */

    String type = obj.getClass().getSimpleName();
    BigDecimal parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = new BigDecimal(by.doubleValue());
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = new BigDecimal(sh.doubleValue());
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = new BigDecimal(in.doubleValue());
        break;

    case "Long":
        Long lo = (Long) obj;
        parsed = new BigDecimal(lo.doubleValue());
        break;

    case "Float":
        Float fl = (Float) obj;
        parsed = new BigDecimal(fl.doubleValue());
        break;

    case "BigInteger":
        parsed = new BigDecimal(((BigInteger) obj));
        break;

    case "BigDecimal":
        parsed = (BigDecimal) obj;
        break;

    case "Double":
        Double db = (Double) obj;
        parsed = new BigDecimal(db);
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java

/**
 * Safely converts a number to a BigInteger. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    object to parse/* www  .j ava2s.  com*/
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static BigDecimal toBigDecimal(Number number) {

    /* Switch on class and convert to BigDecimal */

    String type = number.getClass().getSimpleName();
    BigDecimal parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = new BigDecimal(by.doubleValue());
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = new BigDecimal(sh.doubleValue());
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = new BigDecimal(in.doubleValue());
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = new BigDecimal(lo.doubleValue());
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = new BigDecimal(fl.doubleValue());
        break;

    case "BigInteger":
        parsed = new BigDecimal(((BigInteger) number));
        break;

    case "BigDecimal":
        parsed = (BigDecimal) number;
        break;

    case "Double":
        Double db = (Double) number;
        parsed = new BigDecimal(db);
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts an object to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    object to parse//from  ww  w.j  av a 2  s.  com
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Object obj) {

    /* Switch on class and convert to double */

    String type = obj.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) obj;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) obj;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) obj;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + obj + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) obj;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + obj + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) obj;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts a number to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    number to parse//from ww  w.  j  a v a2s  .c om
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Number number) {

    /* Switch on class and convert to double */

    String type = number.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) number;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) number;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) number;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:Util.PacketGenerator.java

public static void GenerateGraph() {
    try {//from  www .j  a  v  a 2 s.  c  o  m
        for (int j = 6; j <= 6; j++) {
            File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology"
                    + j + "\\Real.csv");
            for (int k = 1; k <= 4; k++) {
                File simu = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".csv");

                FileInputStream simuFIS = new FileInputStream(simu);
                DataInputStream simuDIS = new DataInputStream(simuFIS);
                BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS));

                FileInputStream realFIS = new FileInputStream(real);
                DataInputStream realDIS = new DataInputStream(realFIS);
                BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS));

                String lineSimu = simuBR.readLine();
                String lineReal = realBR.readLine();

                XYSeries matrix = new XYSeries("Matriz", false, true);
                while (lineSimu != null && lineReal != null) {

                    lineSimu = lineSimu.replaceAll(",", ".");
                    String[] simuMatriz = lineSimu.split(";");
                    String[] realMatriz = lineReal.split(";");

                    for (int i = 0; i < simuMatriz.length; i++) {
                        try {
                            Integer valorReal = Integer.parseInt(realMatriz[i]);
                            Float valorSimu = Float.parseFloat(simuMatriz[i]);
                            matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0);
                        } catch (NumberFormatException ex) {

                        }
                    }
                    lineSimu = simuBR.readLine();
                    lineReal = realBR.readLine();
                }

                simuFIS.close();
                simuDIS.close();
                simuBR.close();

                realFIS.close();
                realDIS.close();
                realBR.close();

                double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1;
                XYSeries middle = new XYSeries("Referncia");
                ;
                middle.add(0, 0);
                middle.add(maxPlot, maxPlot);
                XYSeries max = new XYSeries("Superior 20%");
                max.add(0, 0);
                max.add(maxPlot, maxPlot * 1.2);
                XYSeries min = new XYSeries("Inferior 20%");
                min.add(0, 0);
                min.add(maxPlot, maxPlot * 0.8);

                XYSeriesCollection dataset = new XYSeriesCollection();
                dataset.addSeries(middle);
                dataset.addSeries(matrix);
                dataset.addSeries(max);
                dataset.addSeries(min);
                JFreeChart chart;
                if (k == 4) {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset);
                } else {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset);
                }
                chart.setBackgroundPaint(Color.WHITE);
                chart.getPlot().setBackgroundPaint(Color.WHITE);
                chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13));

                chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10));

                chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getDomainAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));
                chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getRangeAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));

                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

                renderer.setSeriesLinesVisible(1, false);
                renderer.setSeriesShapesVisible(1, true);

                renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 0.1f }, 0.0f));
                renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f));
                renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));
                renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));

                renderer.setSeriesPaint(0, Color.BLACK);
                renderer.setSeriesPaint(1, Color.BLACK);
                renderer.setSeriesPaint(2, Color.BLACK);
                renderer.setSeriesPaint(3, Color.BLACK);

                int width = (int) (192 * 1.5f); /* Width of the image */

                int height = (int) (144 * 1.5f); /* Height of the image */

                File XYChart = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".jpeg");
                ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.regenstrief.hl7.util.UtilHL7.java

/**
 * Wraps an Integer in an NM//from  w  w  w.  j a  va2s. c  o  m
 * 
 * @param prop the HL7Properties
 * @param i the Integer
 * @return the NM
 **/
public final static NM getNM(final HL7Properties prop, final Integer i) {
    return i == null ? null : new NM(prop, i.doubleValue());
}

From source file:com.bah.applefox.main.plugins.fulltextindex.FTLoader.java

/**
 * This method is used to add all information parsed by tika into the
 * Accumulo table//from w  ww  .  j  a v a2 s  . c o m
 * 
 * @param url
 *            - the URL of the page that has been parsed
 * @param tikaParsed
 *            - all of the engrams from the page
 * @throws TikaException
 * @throws SAXException
 */
private static boolean addToDataBaseTable(String url) {
    try {
        // Connect to the data table
        BatchWriter writer = AccumuloUtils.connectBatchWrite(dTable);

        // Let the user know the url is being added
        System.out.println("Adding " + url + " with prefix " + longSuffix);

        // Get the input stream (in case it is not an html document
        InputStream urlInput = new URL(url).openStream();

        // Set the page contents (used for filtering if it is an html
        // document)
        String pageContents = getPageContents(new URL(url));

        // If the document is HTML
        if (exDivs.size() != 0 && pageContents.toLowerCase().contains("<html>")) {
            // Filter out some divs (especially generic headers/footers,
            // etc.)
            pageContents = DivsFilter.filterDivs(pageContents, exDivs);
            urlInput = new ByteArrayInputStream(pageContents.getBytes());
        }

        // Parse with tika
        Parser parser = new AutoDetectParser();
        Metadata metadata = new Metadata();
        ParseContext context = new ParseContext();
        ContentHandler handler = new BodyContentHandler();

        parser.parse(urlInput, handler, metadata, context);

        // Get the keywords of the page and its title
        String keywords = metadata.get("keywords");
        String title = metadata.get("title");
        if (title == null) {
            WebPageCrawl p;
            try {
                p = new WebPageCrawl(url, "", Collections.<String>emptySet());
            } catch (PageCrawlException e) {
                log.info(e);
                return false;
            }
            title = p.getTitle();
        }

        // If there are keywords, delimit the commas, otherwise make it a
        // blank screen (not null)
        if (keywords != null) {
            keywords = keywords.replaceAll(",", "[ ]");
        } else {
            keywords = "";
        }

        // Make everything lower case for ease of search
        String plainText = handler.toString().toLowerCase();

        // Split it into <Key,Value> pairs of NGrams, with the Value being
        // the count of the NGram on the page
        HashMap<String, Integer> tikaParsed = IngestUtils
                .collectTerms(IngestUtils.createNGrams(plainText, maxNGrams));

        // A counter for the final number of words
        Integer totalWords = 0;

        // A HashMap for the final NGrams
        HashMap<String, Integer> finalParsed = new HashMap<String, Integer>();

        for (String i : tikaParsed.keySet()) {
            int freq = tikaParsed.get(i);
            totalWords += freq;
            // erase stop words
            if (stopWords != null && !stopWords.contains(i)) {
                finalParsed.put(i, tikaParsed.get(i));
            } else if (stopWords == null) {
                finalParsed.put(i, tikaParsed.get(i));
            }
        }

        System.out.println("Tika Parsed: " + finalParsed.keySet().size());
        System.out.println("Starting");
        int counter = 0;

        String namedURL = url + "[ ]" + title + "[ ]" + keywords;

        for (String row : finalParsed.keySet()) {
            row = row + " " + longSuffix;
            for (String CQ : finalParsed.keySet()) {
                String groupedVal = new String();
                Integer wc = finalParsed.get(CQ);
                double freq = wc.doubleValue() / totalWords.doubleValue();
                groupedVal = wc + "," + freq;
                Value val = new Value(IngestUtils.serialize(groupedVal));

                Mutation m = new Mutation(row);
                m.put(namedURL, CQ, new Date().getTime(), val);
                writer.addMutation(m);
                counter++;
            }

        }

        System.out.println("Wrote " + counter + " Key-Value pairs to Accumulo.");

        writer.close();
        System.out.println("Stopped writing");
    } catch (AccumuloException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    } catch (AccumuloSecurityException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    } catch (TableNotFoundException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    } catch (TableExistsException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    } catch (MalformedURLException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
    } catch (IOException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    } catch (SAXException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    } catch (TikaException e) {
        if (e.getMessage() != null) {
            log.error(e.getMessage());
        } else {
            log.error(e.getStackTrace());
        }
        return false;
    }
    return true;
}

From source file:msi.gaml.operators.Maths.java

@operator(value = { "^" }, can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "Returns the value (always a float) of the left operand raised to the power of the right operand.")
public static Double pow(final Double a, final Integer b) {
    return pow(a, b.doubleValue());
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "exp", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "returns Euler's number e raised to the power of the operand.", special_cases = "the operand is casted to a float before being evaluated.")
public static Double exp(final Integer rv) {
    return Math.exp(rv.doubleValue());
}