Example usage for java.lang Double intValue

List of usage examples for java.lang Double intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

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

Usage

From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java

public void setBackgroundImage(final File bgFile, final double x, final double y) {
    final Double x1 = x;
    final Double y1 = y;

    setBackgroundImage(bgFile, x1.intValue(), y1.intValue());
}

From source file:ua.aits.Carpath.controller.AjaxController.java

@RequestMapping(value = { "/system/contentByType/", "/system/contentByType", "/Carpath/system/contentByType/",
        "/Carpath/system/contentByType" }, method = RequestMethod.GET)
public @ResponseBody ResponseEntity<String> contentByType(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    request.setCharacterEncoding("UTF-8");
    String username = request.getParameter("username");
    String type = request.getParameter("type");
    String value = request.getParameter("value");
    int countPage = Integer.parseInt(request.getParameter("count"));
    int page = Integer.parseInt(request.getParameter("page"));
    List<ArticleModel> tempC = content.getAllContentByType(username, type, value);

    String returnHTML = "";
    String pagination = "<tr><td colspan=\"10\" class=\"pagination\">";
    int first = (countPage * page) - countPage;
    int second = countPage * page;
    if (countPage * page > tempC.size()) {
        first = (page - 1) * countPage;//from  w  w  w.  j  av  a  2s.  c o  m
        second = tempC.size();
    }

    Integer count = tempC.size() - (first);
    List<ArticleModel> tempS = tempC.subList(first, second);
    for (ArticleModel temp : tempS) {
        String ur = "article/full/";
        if (temp.type == 2) {
            ur = "map/markers/";
        }
        String check = "checked";
        String is_publish = "publish";
        String temp_title = temp.title;
        if (temp.title.length() > 36) {
            temp_title = temp.title.substring(0, 36) + "...";
        }
        if (temp.publish == 0) {
            check = "";
            is_publish = "";
        }
        returnHTML = returnHTML + "<tr><td>" + count.toString() + "</td>"
                + "      <td class=\"admin-table-cell date-cell\">" + temp.date + "</td>"
                + "      <td class=\"admin-table-cell-title\"><a href=\"http://www.carpathianroad.com/ua/" + ur
                + temp.id + ";jsessionid=" + request.getSession().getId() + "\" target=\"_blank\">" + temp_title
                + "</a></td>" + "      <td class=\"admin-table-cell\">" + temp.public_country + "</td>"
                + "      <td class=\"article-type admin-table-cell\">" + temp.textType + "</td>"
                + "      <td class=\"catID admin-table-cell\">" + temp.menuText + "</td>"
                + "      <td class=\"admin-table-cell\">" + temp.author + "</td>"
                + "      <td class=\"article-publish " + is_publish
                + "\"><input type=\"checkbox\" data-size=\"mini\" class=\"publish-checkbox\" data-id=\""
                + temp.id + "\" name=\"my-checkbox\" " + check + "></td>" + "<td class=\"" + is_publish + "\">"
                + "          <a class=\"edit-button\" href=\"/Carpath/system/articles/edit/" + temp.id
                + ";jsessionid=" + request.getSession().getId() + "\"><img class=\"edit-delete\" src=\""
                + Constants.URL + "img/edit.png\" /></a>" + "      </td>" + "      <td class=\"" + is_publish
                + "\">" + "          <a href=\"/Carpath/system/articles/delete/" + temp.id + ";jsessionid="
                + request.getSession().getId() + "\"><img class=\"edit-delete\" src=\"" + Constants.URL
                + "img/delete.png\" /></a>" + "      </td>" + "    </tr>";
        count--;
    }
    Double x = Math.ceil((double) tempC.size() / countPage);
    int pages = x.intValue();
    System.out.println(x + "///" + count / countPage + "///" + pages + "///" + count + "////" + countPage);
    for (int i = 1; i <= pages; i++) {
        pagination = pagination + "<a>" + i + "</a>";
    }
    returnHTML = returnHTML + pagination + "</td></tr>";
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "application/json; charset=utf-8");
    return new ResponseEntity<>(returnHTML, responseHeaders, HttpStatus.CREATED);

}

From source file:nl.b3p.kaartenbalie.reporting.ReportThread.java

protected RequestSummary createRequestSummary(String service) {
    RequestSummary requestSummary = null;

    for (int operation = 2; operation <= 5; operation++) {

        Object[] result = null;//  ww w  . ja va 2s  . co  m
        try {
            result = (Object[]) em
                    .createQuery("SELECT count(ro.type), " + "sum(ro.bytesReceivedFromUser), "
                            + "sum(ro.bytesSentToUser), " + "sum(ro.dataSize), " + "avg(ro.duration), "
                            + "max(ro.duration) " + "FROM Operation AS ro "
                            + "WHERE ro.clientRequest.service = :service "
                            + "AND ro.clientRequest.organizationId = :organizationId " + "AND ro.type = :type "
                            + "AND ro.clientRequest.timestamp BETWEEN :startDate AND :endDate "
                            + "GROUP BY ro.type ")
                    .setParameter("service", service).setParameter("type", new Integer(operation))
                    .setParameter("startDate", startDate).setParameter("endDate", endDate)
                    .setParameter("organizationId", organization.getId()).getSingleResult();
        } catch (NoResultException nre) {
            // nothing to do
        }

        if (result != null && result.length == 6) {
            requestSummary = new RequestSummary();
            TypeSummary typeSummary = new TypeSummary();

            Long count = (Long) result[0];
            typeSummary.setCount(count == null ? new Integer(0) : new Integer(count.intValue()));
            Long bytesReceived = (Long) result[1];
            typeSummary.setBytesReceivedSum(
                    bytesReceived == null ? new Integer(0) : new Integer(bytesReceived.intValue()));
            Long bytesSent = (Long) result[2];
            typeSummary.setBytesSentSum(bytesSent == null ? new Integer(0) : new Integer(bytesSent.intValue()));
            Long dataSize = (Long) result[3];
            typeSummary.setDataSizeSum(dataSize == null ? new Integer(0) : new Integer(dataSize.intValue()));
            Double durationAvg = (Double) result[4];
            typeSummary
                    .setDurationAvg(durationAvg == null ? new Integer(0) : new Integer(durationAvg.intValue()));
            Long durationMax = (Long) result[5];
            typeSummary
                    .setDurationMax(durationMax == null ? new Integer(0) : new Integer(durationMax.intValue()));
            typeSummary.setType(Operation.NAME[operation - 1]);

            requestSummary.addTypeSummary(typeSummary);
        }
    }
    return requestSummary;
}

From source file:de.unidue.ltl.flextag.core.reports.CvAvgPerWordClassReport.java

public void execute() throws Exception {
    StorageService storageService = getContext().getStorageService();
    for (TaskContextMetadata subcontext : getSubtasks()) {
        if (TcTaskTypeUtil.isCrossValidationTask(storageService, subcontext.getId())) {
            File attributes = storageService.locateKey(subcontext.getId(), "ATTRIBUTES.txt");
            List<String> foldersOfSingleRuns = getFoldersOfSingleRuns(attributes);

            List<String> mla = new ArrayList<>();
            for (String context : foldersOfSingleRuns) {
                if (TcTaskTypeUtil.isMachineLearningAdapterTask(storageService, context)) {
                    mla.add(context);//from  ww  w .j  a v  a 2  s . c om
                }
            }

            for (String mlaContext : mla) {
                File locateKey = storageService.locateKey(mlaContext, Constants.ID_OUTCOME_KEY);
                Map<String, WordClass> wcPerformances = getWcPerformances(locateKey);
                for (String key : wcPerformances.keySet()) {
                    WordClass wc = wcPerformances.get(key);

                    List<WordClass> list = map.get(key);
                    if (list == null) {
                        list = new ArrayList<>();
                    }
                    list.add(wc);
                    map.put(key, list);
                }
            }

            StringBuilder sb = new StringBuilder();
            sb.append(String.format("%20s\t%8s\t%5s\n", "PoS", "Occr.", "Acc"));

            List<String> keySet = new ArrayList<>(map.keySet());
            Collections.sort(keySet);
            for (String k : keySet) {
                List<WordClass> list = map.get(k);

                Double N = new Double(0);
                double acc = 0;

                for (WordClass wc : list) {
                    N += wc.getN();
                    acc += (wc.getCorrect() / wc.getN());
                }
                N /= list.size();
                acc /= list.size();

                sb.append(
                        String.format("%20s\t%8d\t%5s\n", k, N.intValue(), String.format("%3.1f", acc * 100)));
            }

            File locateKey = storageService.locateKey(subcontext.getId(), OUTPUT_FILE);
            FileUtils.writeStringToFile(locateKey, sb.toString(), "utf-8");
        }
    }

}

From source file:dbseer.gui.actions.ExplainChartAction.java

private void explain() {
    try {/*w ww.j a  v  a2 s .co  m*/
        if (panel.getAnomalyRegion().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Please select an anomaly region.", "Warning",
                    JOptionPane.WARNING_MESSAGE);
            return;
        }

        //         console.setText("Analyzing data for explanation... ");
        DBSeerGUI.explainStatus.setText("Analyzing data for explanation...");

        final StatisticalPackageRunner runner = DBSeerGUI.runner;
        final DBSeerExplainChartPanel explainPanel = this.panel;
        final String causalModelPath = this.causalModelPath;
        final JTextArea console = this.console;
        final ExplainChartAction action = this;

        SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
            String normalIdx = "";
            String anomalyIdx = "";

            HashSet<Integer> normalRegion = new HashSet<Integer>();
            HashSet<Integer> anomalyRegion = new HashSet<Integer>();

            @Override
            protected Void doInBackground() throws Exception {
                for (Double d : explainPanel.getNormalRegion()) {
                    normalRegion.add(d.intValue());
                }
                for (Double d : explainPanel.getAnomalyRegion()) {
                    anomalyRegion.add(d.intValue());
                }

                for (Integer i : normalRegion) {
                    normalIdx = normalIdx + i.toString() + " ";
                }
                for (Integer i : anomalyRegion) {
                    anomalyIdx = anomalyIdx + i.toString() + " ";
                }

                runner.eval("normal_idx = [" + normalIdx + "];");
                runner.eval("anomaly_idx = [" + anomalyIdx + "];");
                runner.eval(
                        "[predicates explanations] = explainPerformance(plotter.mv, anomaly_idx, normal_idx, '"
                                + causalModelPath + "', 500, 0.2, 10);");

                return null;
            }

            @Override
            protected void done() {
                try {
                    DBSeerGUI.explainStatus.setText("");
                    printExplanations();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    e.printStackTrace();
                }
            }
        };
        worker.execute();
    } catch (Exception e) {
        DBSeerExceptionHandler.handleException(e);
    }
}

From source file:nl.b3p.kaartenbalie.reporting.ReportThread.java

protected ServiceProviders createServiceProviders(String service) {
    ServiceProviders serviceProviders = null;

    List resultList = null;//from  w  w  w.j  ava2s  . c  om
    try {
        resultList = (List) em
                .createQuery("SELECT ro.serviceProviderId, " + "count(ro.serviceProviderId), "
                        + "sum(ro.bytesReceived), " + "sum(ro.bytesSent), " + "avg(ro.requestResponseTime), "
                        + "max(ro.requestResponseTime) " + "FROM ServiceProviderRequest AS ro "
                        + "WHERE ro.clientRequest.service = :service "
                        + "AND ro.clientRequest.organizationId = :organizationId "
                        + "AND ro.clientRequest.timestamp BETWEEN :startDate AND :endDate "
                        + "GROUP BY ro.serviceProviderId ")
                .setParameter("service", service).setParameter("startDate", startDate)
                .setParameter("endDate", endDate).setParameter("organizationId", organization.getId())
                .getResultList();
    } catch (NoResultException nre) {
        // nothing to do
    }
    if (resultList != null && resultList.size() > 0) {
        serviceProviders = new ServiceProviders();
        Iterator it = resultList.iterator();
        while (it.hasNext()) {
            Object[] result = (Object[]) it.next();
            if (result != null && result.length == 6) {
                ServiceProvider serviceProvider = new ServiceProvider();

                serviceProvider.setName(getSpName((Integer) result[0], service));
                Long count = (Long) result[1];
                serviceProvider.setCount(count == null ? new Integer(0) : new Integer(count.intValue()));
                Long bytesReceived = (Long) result[2];
                serviceProvider.setBytesReceivedSum(
                        bytesReceived == null ? new Integer(0) : new Integer(bytesReceived.intValue()));
                Long bytesSent = (Long) result[3];
                serviceProvider.setBytesSentSum(
                        bytesSent == null ? new Integer(0) : new Integer(bytesSent.intValue()));
                Double durationAvg = (Double) result[4];
                serviceProvider.setDurationAvg(
                        durationAvg == null ? new Integer(0) : new Integer(durationAvg.intValue()));
                Long durationMax = (Long) result[5];
                serviceProvider.setDurationMax(
                        durationMax == null ? new Integer(0) : new Integer(durationMax.intValue()));

                serviceProviders.addServiceProvider(serviceProvider);
            }
        }
    }
    return serviceProviders;
}

From source file:org.openhab.binding.sonance.internal.SonanceBinding.java

@Override
protected void internalReceiveCommand(String itemName, Command command) {
    logger.debug("Command received ({}, {})", itemName, command);

    SonanceBindingProvider provider = findFirstMatchingBindingProvider(itemName);
    String group = provider.getGroup(itemName);
    String ip = provider.getIP(itemName);
    int port = provider.getPort(itemName);

    Socket s = null;//from   w ww .  ja  va  2  s  .  c  om
    try {
        s = new Socket(ip, port);
        DataOutputStream outToServer = new DataOutputStream(s.getOutputStream());
        BufferedReader i = new BufferedReader(new InputStreamReader(s.getInputStream()));

        if (provider.isMute(itemName)) {
            if (command.equals(OnOffType.OFF)) {
                sendMuteCommand(itemName, SonanceConsts.MUTE_ON + group, outToServer, i);
            } else if (command.equals(OnOffType.ON)) {
                sendMuteCommand(itemName, SonanceConsts.MUTE_OFF + group, outToServer, i);
            } else {
                logger.error("I don't know what to do with the command \"{}\"", command);
            }
        } else if (provider.isPower(itemName)) {
            if (command.equals(OnOffType.OFF)) {
                sendPowerCommand(itemName, SonanceConsts.POWER_OFF, outToServer, i);
            } else if (command.equals(OnOffType.ON)) {
                sendPowerCommand(itemName, SonanceConsts.POWER_ON, outToServer, i);
            } else {
                logger.error("I don't know what to do with the command \"{}\"", command);
            }
        } else if (provider.isVolume(itemName)) {
            if (command.equals(UpDownType.UP)) {
                sendVolumeCommand(itemName, SonanceConsts.VOLUME_UP + group, outToServer, i);
            } else if (command.equals(UpDownType.DOWN)) {
                sendVolumeCommand(itemName, SonanceConsts.VOLUME_DOWN + group, outToServer, i);
            } else {
                try {
                    Double d = Double.parseDouble(command.toString());
                    setVolumeCommand(itemName, group, d.intValue(), outToServer, i, ip + ":" + port);
                } catch (NumberFormatException nfe) {
                    logger.error("I don't know what to do with the volume command \"{}\" ({})", command,
                            nfe.getMessage());
                }
            }
        }
        s.close();
    } catch (IOException e) {
        logger.debug("IO Exception when sending command. Exception: {}", e.getMessage());
    } finally {
        closeSilently(s);
    }
}

From source file:nl.b3p.kaartenbalie.reporting.ReportThread.java

protected RequestLoad createRequestLoad(String service) {
    RequestLoad requestLoad = null;// w w  w.j  a  v a2s  .c o m

    List resultList = null;
    try {
        resultList = (List) em
                .createQuery("SELECT count(cr.timestamp), " + "to_char(cr.timestamp, 'DD-MM-YYYY'), "
                        + "to_char(cr.timestamp, 'HH24'), " + "sum(ro.bytesReceivedFromUser), "
                        + "sum(ro.bytesSentToUser), " + "avg(ro.duration), " + "max(ro.duration) "
                        + "FROM ClientRequest AS cr " + "LEFT JOIN cr.requestOperations AS ro "
                        + "WHERE cr.service = :service " + "AND cr.organizationId = :organizationId "
                        + "AND cr.timestamp BETWEEN :startDate AND :endDate " + "AND ro.type = :type "
                        + "GROUP BY to_char(cr.timestamp, 'DD-MM-YYYY'), to_char(cr.timestamp, 'HH24') "
                        + "ORDER BY to_char(cr.timestamp, 'DD-MM-YYYY'), to_char(cr.timestamp, 'HH24') ASC")
                .setParameter("service", service).setParameter("type", new Integer(Operation.REQUEST))
                .setParameter("startDate", startDate).setParameter("endDate", endDate)
                .setParameter("organizationId", organization.getId()).getResultList();
    } catch (NoResultException nre) {
        // nothing to do
    }
    if (resultList != null && resultList.size() > 0) {
        requestLoad = new RequestLoad();
        Iterator it = resultList.iterator();
        while (it.hasNext()) {
            Object[] result = (Object[]) it.next();
            if (result != null && result.length == 7) {

                HourlyLoad hourlyLoad = new HourlyLoad();

                Long count = (Long) result[0];
                hourlyLoad.setCount(count == null ? new Integer(0) : new Integer(count.intValue()));

                Date datum = FormUtils.StringToDate((String) result[1], null);
                hourlyLoad.setDate(new org.exolab.castor.types.Date(datum == null ? new Date() : datum));
                String hour = (String) result[2];
                hourlyLoad.setHour(new Integer(hour));

                Long bytesReceived = (Long) result[3];
                hourlyLoad.setBytesReceivedSum(
                        bytesReceived == null ? new Integer(0) : new Integer(bytesReceived.intValue()));
                Long bytesSent = (Long) result[4];
                hourlyLoad.setBytesSentSum(
                        bytesSent == null ? new Integer(0) : new Integer(bytesSent.intValue()));
                Double durationAvg = (Double) result[5];
                hourlyLoad.setDurationAvg(
                        durationAvg == null ? new Integer(0) : new Integer(durationAvg.intValue()));
                Long durationMax = (Long) result[6];
                hourlyLoad.setDurationMax(
                        durationMax == null ? new Integer(0) : new Integer(durationMax.intValue()));

                requestLoad.addHourlyLoad(hourlyLoad);
            }
        }
    }
    return requestLoad;
}

From source file:org.kuali.rice.krad.util.KRADUtils.java

/**
 * Return the integer value of a string/*from   w  w w .  j  a  v a 2s .  co m*/
 *
 * <p>
 * If the string contains a decimal value everything after the decimal point is dropped.
 * </p>
 *
 * @param numberStr string
 * @return integer representation of the given string
 */
public static Integer getIntegerValue(String numberStr) {
    Integer numberInt = null;
    try {
        numberInt = new Integer(numberStr);
    } catch (NumberFormatException nfe) {
        Double numberDbl = new Double(numberStr);
        numberInt = new Integer(numberDbl.intValue());
    }
    return numberInt;
}

From source file:dk.dma.ais.view.rest.AisStoreResource.java

/**
 * Check against the expected rate of packets. Just like legacy /rate this
 * is a check for packets seen on average the last 10 minutes.
 * //w ww.  j ava  2s .co  m
 * @param expected
 *            number of packets expected every second (e.g 700)
 * @return "status=nok" or "status=ok"
 */
@GET
@Path("rate")
@Produces(MediaType.TEXT_PLAIN)
public String rate(@QueryParam("expected") Double expected) {
    if (expected == null) {
        expected = 0.0;
    }

    Double r = this.getTenMinuteCount().doubleValue() / 600;
    return "status=" + (r.intValue() > expected ? "ok" : "nok");
}