Example usage for java.lang Double longValue

List of usage examples for java.lang Double longValue

Introduction

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

Prototype

public long longValue() 

Source Link

Document

Returns the value of this Double as a long after a narrowing primitive conversion.

Usage

From source file:com.ocs.dynamo.importer.impl.BaseXlsImporter.java

/**
 * Retrieves the value of a cell as a string. Returns <code>null</code> if the cell does not
 * contain a string/*ww  w .j  ava 2  s.c om*/
 * 
 * @param cell
 * @return
 */
protected String getStringValue(Cell cell) {
    if (cell != null
            && (Cell.CELL_TYPE_STRING == cell.getCellType() || cell.getCellType() == Cell.CELL_TYPE_BLANK)) {
        String value = cell.getStringCellValue();
        return value == null ? null : value.trim();
    } else if (cell != null && Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        // if a number is entered in a field that is supposed to contain a
        // string, Excel goes insane. We have to compensate for this
        Double d = cell.getNumericCellValue();
        return d == null ? null : Long.toString(d.longValue());
    }
    return null;
}

From source file:com.nkapps.billing.services.NumberServiceImpl.java

@Override
public String convertToText(Double number) {
    if (number == 0) {
        return "00";
    }/*from  w ww  .j  a va 2s . co  m*/

    String mask = "000000000000";
    DecimalFormat df = new DecimalFormat(mask);
    String snumber = df.format(number.longValue());

    int billions = Integer.parseInt(snumber.substring(0, 3));
    int millions = Integer.parseInt(snumber.substring(3, 6));
    int hundredThousands = Integer.parseInt(snumber.substring(6, 9));
    int thousands = Integer.parseInt(snumber.substring(9, 12));

    String tradBillions;
    switch (billions) {
    case 0:
        tradBillions = "";
        break;
    default:
        tradBillions = convertLessThanOneThousand(billions) + "  ";
    }
    String result = tradBillions;

    String tradMillions;
    switch (millions) {
    case 0:
        tradMillions = "";
        break;
    default:
        tradMillions = convertLessThanOneThousand(millions) + "  ";
    }
    result = result + tradMillions;

    String tradHundredThousands;
    switch (hundredThousands) {
    case 0:
        tradHundredThousands = "";
        break;
    case 1:
        tradHundredThousands = "?? ";
        break;
    default:
        tradHundredThousands = convertLessThanOneThousand(hundredThousands) + " ??";
    }
    result = result + tradHundredThousands;

    String tradThousand;
    tradThousand = convertLessThanOneThousand(thousands);
    result = result + tradThousand;
    Double tiyin = number - number.intValue();
    // remove extra spaces!
    return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ") + " ? "
            + (tiyin.equals(0) ? "00" : Double.valueOf(tiyin * 100).intValue()) + " ";
}

From source file:com.amazonaws.util.TimingInfo.java

@Deprecated
public final long getElapsedTimeMillis() {
    Double v = getTimeTakenMillisIfKnown();
    return v == null ? UNKNOWN : v.longValue();
}

From source file:com.esri.geoevent.test.tools.RunTcpInTcpOutTest.java

public void send(String server, Integer port, Long numEvents, Integer rate) {
    Random rnd = new Random();
    BufferedReader br = null;/* www.ja  v  a  2  s  .  c  o m*/
    LocalDateTime st = null;

    try {
        Socket sckt = new Socket(server, port);
        OutputStream os = sckt.getOutputStream();
        //PrintWriter sckt_out = new PrintWriter(os, true);

        Integer cnt = 0;

        st = LocalDateTime.now();

        Double ns_delay = 1000000000.0 / (double) rate;

        long ns = ns_delay.longValue();
        if (ns < 0) {
            ns = 0;
        }

        while (cnt < numEvents) {
            cnt += 1;
            LocalDateTime ct = LocalDateTime.now();
            String dtg = ct.toString();
            Double lat = 180 * rnd.nextDouble() - 90.0;
            Double lon = 360 * rnd.nextDouble() - 180.0;
            String line = "RandomPoint," + cnt.toString() + "," + dtg + ",\"" + lon.toString() + ","
                    + lat.toString() + "\"," + cnt.toString() + "\n";

            final long stime = System.nanoTime();

            long etime = 0;
            do {
                etime = System.nanoTime();
            } while (stime + ns >= etime);

            if (cnt % 1000 == 0) {
                //System.out.println(cnt);
            }

            //sckt_out.write(line);
            os.write(line.getBytes());
            os.flush();

        }

        if (st != null) {
            LocalDateTime et = LocalDateTime.now();

            Duration delta = Duration.between(st, et);

            Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0;

            send_rate = (double) numEvents / elapsed_seconds;
        }

        //sckt_out.close();
        sckt.close();
        os = null;
        //sckt_out = null;

    } catch (Exception e) {
        System.err.println(e.getMessage());
        send_rate = -1.0;
    } finally {
        try {
            br.close();
        } catch (Exception e) {
            //
        }

        this.send_rate = send_rate;

    }

}

From source file:stats.GaussianFitMeanStdev.java

public void CalculateMeanStdev(double[] values) {
    Long maxvalue = 0l;//from  w w w  .  j a  v  a 2s.  c  o  m
    if (values.length < 3) {
        log.log(Level.WARNING,
                "Mean/Stdev calculation had " + values.length + "initial observations! Doing simple estimate");
        this.mean = StdevAvg.DoubleAvg(values);
        this.stdev = StdevAvg.stdevDBL(this.mean, values);
        return;
    }
    for (Double d : values) {
        if (Math.round(d) > maxvalue)
            maxvalue = d.longValue();
    }

    if (maxvalue.intValue() <= 3) {
        log.log(Level.WARNING, "Chromosome had very little signal! Max signal value: " + maxvalue.intValue());
        this.cantUse = true;
        return;
    }

    Double[] bins = new Double[maxvalue.intValue() + 1];
    java.util.Arrays.fill(bins, 0.0d);
    for (Double d : values) {
        bins[d.intValue()] += 1;
    }
    double testmean = StdevAvg.DoubleAvg(values);
    double teststdev = StdevAvg.stdevDBL(testmean, values);

    log.log(Level.FINEST, "[GMSTDEV] testmean: " + testmean + " teststdev: " + teststdev);

    try {
        this.fitter = GaussianCurveFitter.create().withMaxIterations(50)
                .withStartPoint(new double[] { maxvalue * 0.4 / teststdev, testmean, teststdev * 0.5 });
    } catch (TooManyIterationsException ex) {
        log.log(Level.WARNING, "Too many iterations for local fitter! Using regular mean and stdev.");
        this.mean = testmean;
        this.stdev = teststdev;
        return;
    }
    WeightedObservedPoints obs = new WeightedObservedPoints();
    for (int i = 0; i < bins.length && i < testmean * 3; i++) {
        obs.add(i, bins[i]);
    }

    double[] parameters;
    try {
        parameters = fitter.fit(obs.toList());
    } catch (TooManyIterationsException ex) {
        log.log(Level.WARNING, "Too many iterations for local fitter! Using regular mean and stdev.");
        this.mean = testmean;
        this.stdev = teststdev;
        return;
    }
    this.mean = parameters[1];
    this.stdev = parameters[2];

    Double mincut = parameters[1] - 2.0d * parameters[2];
    Double maxcut = parameters[1] + 2.0d * parameters[2];

    log.log(Level.FINEST, "[GMSTDEV] initial mean: " + this.mean + " initial stdev: " + this.stdev
            + " mincut, maxcut: ( " + mincut + "," + maxcut + " )");

    if (maxcut - mincut < 3 || mincut < 0 || maxcut < 0) {
        log.log(Level.WARNING,
                "Mean/Stdev calculation had " + mincut + " and " + maxcut + "! Not cropping values");
        return;
    }
    //java.util.Arrays.fill(bins, 0.0d);
    obs = new WeightedObservedPoints();
    for (int i = mincut.intValue(); i < maxcut.intValue(); i++) {
        obs.add(i, bins[i]);
    }
    double[] par = fitter.fit(obs.toList());
    this.mean = par[1];
    this.stdev = par[2];
}

From source file:com.esri.geoevent.test.tools.RunTcpInBdsOutTest.java

public void send(String server, Integer port, Long numEvents, Integer rate, String data_file) {

    BufferedReader br = null;//from w  w  w  . j av a  2s.c  o  m
    ArrayList<String> lines = new ArrayList<>();
    LocalDateTime st = null;

    try {

        // Read the file into String array
        br = new BufferedReader(new FileReader(data_file));

        String line = null;
        while ((line = br.readLine()) != null) {
            lines.add(line);
        }

        Socket sckt = new Socket(server, port);
        OutputStream os = sckt.getOutputStream();

        Integer cnt = 0;

        st = LocalDateTime.now();

        Double ns_delay = 1000000000.0 / (double) rate;

        long ns = ns_delay.longValue();
        if (ns < 0) {
            ns = 0;
        }

        int i = 0;
        int j = 0;

        while (i < numEvents) {
            i++;
            j++;
            if (j >= lines.size()) {
                j = 0;
            }
            line = lines.get(j) + "\n";

            final long stime = System.nanoTime();

            long etime = 0;
            do {
                etime = System.nanoTime();
            } while (stime + ns >= etime);

            os.write(line.getBytes());
            os.flush();

        }

        LocalDateTime et = LocalDateTime.now();
        if (st != null) {
            et = LocalDateTime.now();

            Duration delta = Duration.between(st, et);

            Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0;

            send_rate = (double) numEvents / elapsed_seconds;
        }

        sckt.close();
        os = null;

    } catch (Exception e) {
        System.err.println(e.getMessage());
        send_rate = -1.0;
    } finally {
        try {
            br.close();
        } catch (Exception e) {
            //
        }

        this.send_rate = send_rate;

    }

}

From source file:gsn.reports.scriptlets.StreamScriptlet.java

@SuppressWarnings("unchecked")
public void setStatistics() throws JRScriptletException {

    String max = "NA";
    String min = "NA";
    String average = "NA";
    String stdDeviation = "NA";
    String median = "NA";
    String nb = "0";
    String startTime = "NA";
    String endTime = "NA";
    String samplingAverage = "NA";
    //      String samplingAverageUnit      = "NA";
    String nbOfNull = "0";
    String samplingStdDeviation = "NA";
    //      String samplingStdDeviationUnit   = "NA";

    Collection<Data> datas = (Collection<Data>) this.getFieldValue("datas");
    if (datas.size() > 0) {
        Double max_value = Double.MIN_VALUE;
        Double min_value = Double.MAX_VALUE;
        Double average_value = 0.0;
        Double sum_value = 0.0;//from w ww .  java2  s.  c  om
        Long start_time_value = 0L;
        Long end_time_value = 0L;
        Long sampling_average_value = 0L;
        Integer nb_value = 0;
        Integer nb_of_null = 0;
        Iterator<Data> iter = datas.iterator();
        Data nextData;
        Double nextDataValue;
        while (iter.hasNext()) {
            nextData = iter.next();
            if (nextData.getValue() != null) {
                nextDataValue = (Double) nextData.getValue();
                //
                sum_value += nextDataValue;
                //
                if (nextDataValue < min_value)
                    min_value = nextDataValue;
                if (nextDataValue > max_value)
                    max_value = nextDataValue;
                //               
                if (datas.size() == 1 || nb_value == datas.size() / 2)
                    median = nextDataValue.toString();
                //
                if (!iter.hasNext()) {
                    startTime = sdf.format(new Date((Long) nextData.getP2())).toString();
                    start_time_value = (Long) nextData.getP2();
                }
                if (nb_value == 0) {
                    endTime = sdf.format(new Date((Long) nextData.getP2())).toString();
                    end_time_value = (Long) nextData.getP2();
                }
            } else {
                nb_of_null++;
            }
            nb_value++;
        }
        //
        max = max_value == Double.MIN_VALUE ? "NA" : max_value.toString();
        min = min_value == Double.MAX_VALUE ? "NA" : min_value.toString();
        nb = nb_value.toString();
        average_value = (Double) (sum_value / nb_value);
        average = average_value.toString();
        nbOfNull = nb_of_null.toString();
        //
        if (datas.size() > 1) {
            sampling_average_value = (end_time_value - start_time_value) / (nb_value - 1);
            samplingAverage = Helpers.formatTimePeriod(sampling_average_value);
        }
        //
        iter = datas.iterator();
        Double variance_value = 0.0;
        Double sampling_variance_value = 0.0;
        Long lastDataTime = end_time_value;
        int i = 0;
        while (iter.hasNext()) {
            nextData = iter.next();
            if (nextData.getValue() != null) {
                nextDataValue = (Double) nextData.getValue();
                variance_value += Math.pow((average_value - nextDataValue), 2);
                if (i > 0) {
                    sampling_variance_value += Math
                            .pow((sampling_average_value - ((lastDataTime - (Long) nextData.getP2()))), 2);
                    lastDataTime = (Long) nextData.getP2();
                }
                i++;
            }
        }
        stdDeviation = ((Double) Math.sqrt(variance_value)).toString();
        if (datas.size() > 1) {
            Double sampling_std_deviation = (Double) Math.sqrt(sampling_variance_value);
            samplingStdDeviation = Helpers.formatTimePeriod(sampling_std_deviation.longValue());
        }
    }

    this.setVariableValue("max", max); // ok
    this.setVariableValue("min", min); // ok
    this.setVariableValue("average", average); // ok
    this.setVariableValue("stdDeviation", stdDeviation); // ok
    this.setVariableValue("median", median); // ok
    this.setVariableValue("nb", nb); // ok
    this.setVariableValue("startTime", startTime); // ok
    this.setVariableValue("endTime", endTime); // ok
    this.setVariableValue("samplingAverage", samplingAverage); // ok
    this.setVariableValue("nbOfNull", nbOfNull); // ok
    this.setVariableValue("samplingStdDeviation", samplingStdDeviation); // ok
}

From source file:stats.GaussianFitMeanStdev.java

public void CalculateGlobalMeanStdev(ChrHistogramFactory gchisto, WindowPlan wins) {
    Long maxvalue = 0l;/*  www  .j  av a 2s . c  o  m*/
    int count = 0;
    for (String chr : wins.getChrList()) {
        if (!gchisto.hasChrHistogram(chr))
            continue;
        for (Double d : gchisto.getChrHistogram(chr).retrieveRDBins()) {
            count++;
            if (d.longValue() > maxvalue)
                maxvalue = d.longValue();
        }
    }
    if (count < 3 || maxvalue.intValue() < 3) {
        log.log(Level.SEVERE,
                "Error! Could not calculate Global Mean and Stdev! Count: " + count + " maxvalue: " + maxvalue);
        System.exit(-1);
    }

    Double[] bins = new Double[maxvalue.intValue() + 1];
    java.util.Arrays.fill(bins, 0.0d);
    double sum = 0.0d;
    for (String chr : wins.getChrList()) {
        if (!gchisto.hasChrHistogram(chr))
            continue;
        for (Double d : gchisto.getChrHistogram(chr).retrieveRDBins()) {
            sum += d;
            bins[d.intValue()] += 1;
        }
    }
    WeightedObservedPoints obs = new WeightedObservedPoints();
    for (int i = 0; i < bins.length; i++) {
        obs.add(i, bins[i]);
    }
    double testmean = sum / count;
    double teststdev = 0.0d;
    for (String chr : wins.getChrList()) {
        for (Double d : gchisto.getChrHistogram(chr).retrieveRDBins()) {
            teststdev += (double) Math.pow(d - testmean, 2.0d);
        }
    }
    teststdev /= (double) (count - 1);
    teststdev = Math.sqrt(teststdev);
    double[] parameters;
    try {
        this.fitter = GaussianCurveFitter.create().withMaxIterations(50)
                .withStartPoint(new double[] { maxvalue * 0.4 / teststdev, testmean, teststdev * 0.5 });
        parameters = fitter.fit(obs.toList());
    } catch (TooManyIterationsException ex) {
        log.log(Level.WARNING, "Too many iterations! Using regular mean and stdev.");
        this.mean = testmean;
        this.stdev = teststdev;
        return;
    }

    Double mincut = parameters[1] - 2.0d * parameters[2];
    Double maxcut = parameters[1] + 2.0d * parameters[2];

    if (maxcut - mincut < 3 || mincut < 0 || maxcut < 0) {
        log.log(Level.WARNING,
                "Gaussian fitting calculation had " + mincut + " and " + maxcut + "! Not fitting values");
        this.mean = parameters[1];
        this.stdev = parameters[2];
        return;
    }

    List<Double> tempvals = new ArrayList<>();
    for (int i = mincut.intValue(); i < maxcut.intValue(); i++) {
        tempvals.add(bins[i]);
    }

    obs = new WeightedObservedPoints();
    for (int i = mincut.intValue(); i < maxcut.intValue(); i++) {
        obs.add(i, bins[i]);
    }
    try {
        this.fitter = GaussianCurveFitter.create().withMaxIterations(50)
                .withStartPoint(new double[] { maxvalue * 0.4 / teststdev, testmean, teststdev * 0.5 });
    } catch (TooManyIterationsException ex) {
        log.log(Level.WARNING, "Too many iterations! Using previously generated mean and stdev.");
        return;
    }
    double[] par = fitter.fit(obs.toList());
    this.mean = par[1];
    this.stdev = par[2];
}

From source file:eu.supersede.gr.utility.PointsLogic.java

private void computePoints() {
    List<HAHPGamePlayerPoint> gamesPlayersPoints = gamesPlayersPointsRepository.findAll();

    // cycle on every gamesPlayersPoints
    for (int i = 0; i < gamesPlayersPoints.size(); i++) {
        HAHPGame g = gamesRepository.findOne(gamesPlayersPoints.get(i).getGame().getGameId());

        // set currentPlayer that is used for other methods
        g.setCurrentPlayer(gamesPlayersPoints.get(i).getUser());

        List<HAHPCriteriasMatrixData> criteriasMatrixDataList = criteriaMatricesRepository.findByGame(g);

        // calculate the agreementIndex for every gamesPlayersPoints of a game and a specific user

        Map<String, Double> resultTotal = AHPRest.CalculateAHP(g.getCriterias(), g.getRequirements(),
                criteriasMatrixDataList, g.getRequirementsMatrixData());
        Map<String, Double> resultPersonal = AHPRest.CalculatePersonalAHP(
                gamesPlayersPoints.get(i).getUser().getUserId(), g.getCriterias(), g.getRequirements(),
                criteriasMatrixDataList, g.getRequirementsMatrixData());
        List<Requirement> gameRequirements = g.getRequirements();
        Double sum = 0.0;//from  w  w w .j  a va  2s.c  om

        for (int j = 0; j < resultTotal.size(); j++) {
            Double requirementValueTotal = resultTotal
                    .get(gameRequirements.get(j).getRequirementId().toString());
            Double requirementValuePersonal = resultPersonal
                    .get(gameRequirements.get(j).getRequirementId().toString());
            sum = sum + (Math.abs(requirementValueTotal - requirementValuePersonal)
                    * (1.0 - requirementValueTotal));
        }

        Double agreementIndex = M - (M * sum);
        gamesPlayersPoints.get(i).setAgreementIndex(agreementIndex.longValue());

        // calculate the positionInVoting for every gamesPlayersPoints of a game and a specific user

        List<User> players = g.getPlayers();
        List<HAHPRequirementsMatrixData> lrmd = requirementsMatricesRepository.findByGame(g);
        Map<User, Float> gamePlayerVotes = new HashMap<>();

        for (User player : players) {
            Integer total = 0;
            Integer voted = 0;

            if (lrmd != null) {
                for (HAHPRequirementsMatrixData data : lrmd) {
                    for (HAHPPlayerMove pm : data.getPlayerMoves()) {
                        if (pm.getPlayer().getUserId().equals(player.getUserId())) {
                            total++;

                            if (pm.getPlayed() == true && pm.getValue() != null && !pm.getValue().equals(-1l)) {
                                voted++;
                            }
                        }
                    }
                }
            }

            gamePlayerVotes.put(player, total.equals(0) ? 0f : ((new Float(voted) / new Float(total)) * 100));
        }

        LinkedHashMap<User, Float> orderedList = sortHashMapByValues(gamePlayerVotes);
        List<User> indexes = new ArrayList<>(orderedList.keySet());
        Integer index = indexes.indexOf(gamesPlayersPoints.get(i).getUser());
        Double positionInVoting = (orderedList.size() - (new Double(index) + 1.0)) + 1.0;
        gamesPlayersPoints.get(i).setPositionInVoting(positionInVoting.longValue());

        // calculate the virtualPosition of a user base on his/her points in a particular game

        HAHPGamePlayerPoint gpp = gamesPlayersPointsRepository
                .findByUserAndGame(gamesPlayersPoints.get(i).getUser(), g);
        List<HAHPGamePlayerPoint> specificGamePlayersPoints = gamesPlayersPointsRepository.findByGame(g);

        Collections.sort(specificGamePlayersPoints, new CustomComparator());

        Long virtualPosition = specificGamePlayersPoints.indexOf(gpp) + 1l;
        gamesPlayersPoints.get(i).setVirtualPosition(virtualPosition);

        Long movesPoints = 0l;
        Long gameProgressPoints = 0l;
        Long positionInVotingPoints = 0l;
        Long gameStatusPoints = 0l;
        Long agreementIndexPoints = 0l;
        Long totalPoints = 0l;

        // set the movesPoints
        movesPoints = g.getMovesDone().longValue();

        // setGameProgressPoints
        gameProgressPoints = (long) Math.floor(g.getPlayerProgress() / 10);

        // setPositionInVotingPoints
        if (positionInVoting == 1) {
            positionInVotingPoints = 5l;
        } else if (positionInVoting == 2) {
            positionInVotingPoints = 3l;
        } else if (positionInVoting == 3) {
            positionInVotingPoints = 2l;
        }

        // setGameStatusPoints
        if (g.getPlayerProgress() != 100) {
            gameStatusPoints = -20l;
        } else {
            gameStatusPoints = 0l;
        }

        // set AgreementIndexPoints
        agreementIndexPoints = agreementIndex.longValue();
        totalPoints = movesPoints.longValue() + gameProgressPoints + positionInVotingPoints + gameStatusPoints
                + agreementIndexPoints;

        // set totalPoints 0 if the totalPoints are negative
        if (totalPoints < 0) {
            totalPoints = 0l;
        }

        gamesPlayersPoints.get(i).setPoints(totalPoints);
        gamesPlayersPointsRepository.save(gamesPlayersPoints.get(i));
    }

    System.out.println("Finished computing votes");
}

From source file:org.globus.workspace.accounting.impls.dbdefault.DBAccountingAdapter.java

public void destroy(int id, String ownerDN, long minutesElapsed, double chargeRatio) {

    if (this.lager.accounting) {
        logger.trace(//from   w  ww.  ja  v a 2  s . co m
                "destroy(): id = " + id + ", ownerDN = '" + ownerDN + "', minutesElapsed = " + minutesElapsed);
    }

    if (!this.initialized) {
        logger.error("never initialized, can't do anything");
        return;
    }

    long charge = Util.positiveCeiling(minutesElapsed, this.chargeGranularity);
    final Double chargeDouble = charge * chargeRatio;
    charge = chargeDouble.longValue();

    try {

        final String uuid = this.db.end(id, ownerDN, charge);

        if (this.lager.eventLog) {
            logger.info(Lager.ev(id) + "accounting: ownerDN = '" + ownerDN + "', minutesElapsed = " + charge
                    + ", chargeRatio = " + chargeRatio + ", real usage = " + minutesElapsed + ", uuid = '"
                    + uuid + '\'');
        }

        if (this.fileLog != null) {
            final Calendar now = Calendar.getInstance();
            try {
                this.fileLog.logRemove(uuid, id, ownerDN, charge, chargeRatio, now);
            } catch (WorkspaceException e) {
                if (logger.isDebugEnabled()) {
                    logger.error(e.getMessage(), e);
                } else {
                    logger.error(e.getMessage());
                }
            }
        }

    } catch (WorkspaceDatabaseException e) {
        logger.error(e.getMessage());
    }
}