Example usage for java.util LinkedList size

List of usage examples for java.util LinkedList size

Introduction

In this page you can find the example usage for java.util LinkedList size.

Prototype

int size

To view the source code for java.util LinkedList size.

Click Source Link

Usage

From source file:modmanager.backend.ModificationOption.java

private boolean isInstalled(LinkedList<File> installed) {
    return installed.size() != 0;
}

From source file:modmanager.backend.ModificationOption.java

private boolean isCompletelyInstalled(LinkedList<File> installed) {
    return installed.size() == getFileCount();
}

From source file:com.funambol.json.api.dao.AlternateJsonApiDao.java

/**
 *  get all the keys of the new items since a specified time.
 * @return//from  www. ja v  a 2s  .  c om
 */
@Override
public String getNewSyncItemKeys() throws OperationFailureException {
    if (log.isInfoEnabled()) {
        log.info("Executing method: getNewSyncItemKeys() from:" + configLoader.getServerTimeStr(lastSyncTime)
                + " to  :" + configLoader.getServerTimeStr(beginSyncTime));
    }
    try {
        String req = configLoader.getServerProperty(Def.SERVER_URI) + "/" + getSourceName() + "/keys/new";

        String response = sendGetRequest(req, configLoader.getServerTime(lastSyncTime),
                configLoader.getServerTime(beginSyncTime));

        if (log.isTraceEnabled()) {
            log.trace("RESPONSE getNewSyncItemKeys: \n" + response);
        }
        JSONArray arrayOfKeys = JSONObject.fromObject(response).getJSONObject("data").getJSONArray("keys");

        LinkedList<String> newItems = configLoader.getNewItems(sourceName, testName);
        LinkedList<String> updatedItems = configLoader.getUpdatedItems(sourceName, testName);
        int itemsCount = newItems.size() + updatedItems.size();
        if (itemsCount != arrayOfKeys.size()) {
            log.info("ERROR Expected :" + itemsCount + " found " + arrayOfKeys.size());
            log.info("ERROR client N:" + newItems + " U:" + updatedItems);
            log.info("ERROR server  :" + arrayOfKeys);
        }

        return response;
    } catch (IOOperationException ex) {
        throw new OperationFailureException("Error retrieving new items ", ex);
    }
}

From source file:com.kse.bigdata.file.SequenceSampler.java

public LinkedList<Sequence> getRandomSample() {
    System.out.println("Sampling Start...");
    System.out.println("Sample Size is  " + SAMPLE_SIZE);

    try {/*from  w w  w  . j a v a 2 s .  c  o m*/
        FileSystem fs = FileSystem.get(new Configuration());
        BufferedReader fileReader = new BufferedReader(new InputStreamReader(fs.open(sampleFile)));
        LinkedList<Double> deque = new LinkedList<Double>();
        String line;
        int[] sampleIndexes = getRandomSampleIndexArray();
        int counter = -1;

        while ((line = fileReader.readLine()) != null) {
            counter++;

            deque.add(extractValidInformation(line));

            if (deque.size() == Sequence.SIZE_OF_SEQUENCE) {

                for (int sampleIndex : sampleIndexes)
                    if (sampleIndex == counter)
                        randomSamples.add(new Sequence(deque));

                deque.removeFirst();
            }

            if (randomSamples.size() == SAMPLE_SIZE)
                return randomSamples;

        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return this.randomSamples;
}

From source file:org.samjoey.graphing.GraphUtility.java

public static void createGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (Game game : games) {
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }//from   w ww.j  a  v a2 s .c  o m
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }

    for (String key : datasets.keySet()) {
        JFrame f = new JFrame();
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        f.setContentPane(chartPanel);
        f.pack();
        RefineryUtilities.centerFrameOnScreen(f);
        f.setVisible(true);
    }
}

From source file:com.k42b3.aletheia.protocol.http.HttpProtocol.java

public void run() {
    try {//from ww w.j  av  a2  s  .c o m
        // get socket
        Socket socket = this.getSocket();
        conn.bind(socket, params);

        // build request
        BasicHttpRequest request;

        if (!this.getRequest().getBody().isEmpty()) {
            request = new BasicHttpEntityEnclosingRequest(this.getRequest().getMethod(),
                    this.getRequest().getPath());
        } else {
            request = new BasicHttpRequest(this.getRequest().getMethod(), this.getRequest().getPath());
        }

        // add headers
        String boundary = null;
        ArrayList<String> ignoreHeader = new ArrayList<String>();
        ignoreHeader.add("Content-Length");
        ignoreHeader.add("Expect");

        LinkedList<Header> headers = this.getRequest().getHeaders();

        for (int i = 0; i < headers.size(); i++) {
            if (!ignoreHeader.contains(headers.get(i).getName())) {
                // if the content-type header gets set the conent-length
                // header is automatically added
                request.addHeader(headers.get(i));
            }

            if (headers.get(i).getName().equals("Content-Type")
                    && headers.get(i).getValue().startsWith("multipart/form-data")) {
                String header = headers.get(i).getValue().substring(headers.get(i).getValue().indexOf(";") + 1)
                        .trim();

                if (!header.isEmpty()) {
                    String parts[] = header.split("=");

                    if (parts.length >= 2) {
                        boundary = parts[1];
                    }
                }
            }
        }

        // set body
        if (request instanceof BasicHttpEntityEnclosingRequest && boundary != null) {
            boundary = "--" + boundary;
            StringBuilder body = new StringBuilder();
            String req = this.getRequest().getBody();

            int i = 0;
            String partHeader;
            String partBody;

            while ((i = req.indexOf(boundary, i)) != -1) {
                int hPos = req.indexOf("\n\n", i + 1);
                if (hPos != -1) {
                    partHeader = req.substring(i + boundary.length() + 1, hPos).trim();
                } else {
                    partHeader = null;
                }

                int bpos = req.indexOf(boundary, i + 1);
                if (bpos != -1) {
                    partBody = req.substring(hPos == -1 ? i : hPos + 2, bpos);
                } else {
                    partBody = req.substring(hPos == -1 ? i : hPos + 2);
                }

                if (partBody.equals(boundary + "--")) {
                    body.append(boundary + "--" + "\r\n");
                    break;
                } else if (!partBody.isEmpty()) {
                    body.append(boundary + "\r\n");
                    if (partHeader != null && !partHeader.isEmpty()) {
                        body.append(partHeader.replaceAll("\n", "\r\n"));
                        body.append("\r\n");
                        body.append("\r\n");
                    }
                    body.append(partBody);
                }

                i++;
            }

            this.getRequest().setBody(body.toString().replaceAll("\r\n", "\n"));

            HttpEntity entity = new StringEntity(this.getRequest().getBody());

            ((BasicHttpEntityEnclosingRequest) request).setEntity(entity);
        } else if (request instanceof BasicHttpEntityEnclosingRequest) {
            HttpEntity entity = new StringEntity(this.getRequest().getBody());

            ((BasicHttpEntityEnclosingRequest) request).setEntity(entity);
        }

        logger.info("> " + request.getRequestLine().getUri());

        // request
        request.setParams(params);
        httpexecutor.preProcess(request, httpproc, context);

        HttpResponse response = httpexecutor.execute(request, conn, context);
        response.setParams(params);
        httpexecutor.postProcess(response, httpproc, context);

        logger.info("< " + response.getStatusLine());

        // update request headers 
        LinkedList<Header> header = new LinkedList<Header>();
        Header[] allHeaders = request.getAllHeaders();

        for (int i = 0; i < allHeaders.length; i++) {
            header.add(allHeaders[i]);
        }

        this.getRequest().setHeaders(header);

        // create response
        this.response = new Response(response);

        // call callback
        callback.onResponse(this.request, this.response);
    } catch (Exception e) {
        Aletheia.handleException(e);
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
            Aletheia.handleException(e);
        }
    }
}

From source file:ru.apertum.qsystem.reports.model.QReportsList.java

@Override
protected LinkedList<QReport> load() {
    final LinkedList<QReport> reports = new LinkedList<>(Spring.getInstance().getHt().loadAll(QReport.class));
    QLog.l().logRep().debug("   " + reports.size() + " .");

    passMap = new HashMap<>();
    htmlRepList = "";
    htmlUsersList = "";
    reports.stream().map((report) -> {
        addGenerator(report);/*from www . j  av  a  2 s .com*/
        return report;
    }).forEach((report) -> {
        htmlRepList = htmlRepList.concat("<tr>\n" + "<td style=\"text-align: left; padding-left: 60px;\">\n"
                + "<a href=\"" + report.getHref() + ".html\" target=\"_blank\">"
                + (RepResBundle.getInstance().present(report.getHref())
                        ? RepResBundle.getInstance().getStringSafe(report.getHref())
                        : report.getName())
                + "</a>\n" + "<a href=\"" + report.getHref() + ".rtf\" target=\"_blank\">[RTF]</a>\n"
                + "<a href=\"" + report.getHref() + ".pdf\" target=\"_blank\">[PDF]</a>\n" + "<a href=\""
                + report.getHref() + ".xlsx\" target=\"_blank\">[XLSX]</a>\n" + "</td>\n" + "</tr>\n");
    });
    /*
     *   . ?  ?? ,  ?   ?  
     * coocies ? ,    ??    ?   ? ? " ?".
     * ?    preparation(), ..   .
     */
    addGenerator(new ReportsList("reportList", ""));
    /*
     *    ???   ?
     */
    addGenerator(new ReportCurrentServices(Uses.REPORT_CURRENT_SERVICES.toLowerCase(),
            "/ru/apertum/qsystem/reports/templates/currentStateServices.jasper"));
    /*
     *    ???   
     */
    addGenerator(new RepCurrentUsers(Uses.REPORT_CURRENT_USERS.toLowerCase(),
            "/ru/apertum/qsystem/reports/templates/currentStateUsers.jasper"));

    String sel = " selected";
    for (QUser user : QUserList.getInstance().getItems()) {
        // ?? ,   
        if (user.getReportAccess()) {
            htmlUsersList = htmlUsersList.concat("<option" + sel + ">").concat(user.getName())
                    .concat("</option>\n");
            sel = "";
            if (user.getReportAccess()) {
                passMap.put(user.getName(), user.getPassword());
            }
        }
    }

    return reports;
}

From source file:org.openmrs.module.kenyaemr.page.controller.chart.ChartViewPatientPageController.java

/**
 * Adds this patient to the user's recently viewed list
 * @param patient the patient//  w  ww.  j  a v  a2s . c om
 * @param session the session
 */
private void recentlyViewed(Patient patient, Session session) {
    String attrName = EmrConstants.APP_CHART + ".recentlyViewedPatients";

    LinkedList<Integer> recent = session.getAttribute(attrName, LinkedList.class);
    if (recent == null) {
        recent = new LinkedList<Integer>();
        session.setAttribute(attrName, recent);
    }
    recent.removeFirstOccurrence(patient.getPatientId());
    recent.add(0, patient.getPatientId());
    while (recent.size() > 10)
        recent.removeLast();
}

From source file:edu.jhu.pha.vospace.storage.SwiftKeystoneStorageManager.java

public static List<FilesObject> listObjectsStartingWith(String container, String startsWith, String path,
        int limit, String marker, String end_marker, Character delimiter) throws IOException, FilesException {

    HttpGet method = null;//from   ww  w.  j  a v  a2s. c  o  m

    LinkedList<NameValuePair> parameters = new LinkedList<NameValuePair>();
    parameters.add(new BasicNameValuePair("format", "json"));
    if (startsWith != null) {
        parameters.add(new BasicNameValuePair(FilesConstants.LIST_CONTAINER_NAME_QUERY, startsWith));
    }
    if (path != null) {
        parameters.add(new BasicNameValuePair("path", path));
    }
    if (limit > 0) {
        parameters.add(new BasicNameValuePair("limit", String.valueOf(limit)));
    }
    if (marker != null) {
        parameters.add(new BasicNameValuePair("marker", marker));
    }
    if (end_marker != null) {
        parameters.add(new BasicNameValuePair("marker", end_marker));
    }
    if (delimiter != null) {
        parameters.add(new BasicNameValuePair("delimiter", delimiter.toString()));
    }

    String uri = parameters.size() > 0 ? makeURI(getFileUrl + "/" + sanitizeForURI(container), parameters)
            : getFileUrl;
    method = new HttpGet(uri);
    method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
    method.setHeader(FilesConstants.X_AUTH_TOKEN, strToken);
    FilesResponse response = new FilesResponse(client.execute(method));

    if (response.getStatusCode() == HttpStatus.SC_OK) {
        ArrayList<FilesObject> objectList = new ArrayList<FilesObject>();

        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jp = jsonFactory.createJsonParser(IOUtils.toString(response.getResponseBodyAsStream()));
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        TypeReference ref = new TypeReference<List<FilesObject>>() {
        };
        objectList = mapper.readValue(jp, ref);
        return objectList;

    } else if (response.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
        logger.debug("Container " + container + " has no Objects");
        return new ArrayList<FilesObject>();
    } else if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        throw new FilesNotFoundException("Container was not found", response.getResponseHeaders(),
                response.getStatusLine());
    } else {
        throw new FilesException("Unexpected Server Result", response.getResponseHeaders(),
                response.getStatusLine());
    }
}

From source file:com.spmadden.jnfsn.NFSNDns.java

public DNSResourceRecord[] getResourceRecords(final String name, final String type, final String data)
        throws APIException {
    try {//from   w  w w . j a  va2s.  co  m
        final String url = getURL("listRRs");
        final HTTPConnection conn = new HTTPConnection(url, RequestMethod.POST, generator);

        if (name != null) {
            conn.addFormField("name", name);
        }
        if (type != null && !"".equals(type)) {
            conn.addFormField("type", type);
        }
        if (data != null && !"".equals(data)) {
            conn.addFormField("data", data);
        }

        final String value = NetUtils.consumeAll(conn.getDataStream());
        LOG.debug("JSON: " + value);

        final JSONArray arr = new JSONArray(value);
        final LinkedList<DNSResourceRecord> rrs = new LinkedList<>();
        for (int i = 0; i < arr.length(); ++i) {
            rrs.add(DNSResourceRecord.fromJSONObject(arr.getJSONObject(i)));
        }

        return rrs.toArray(new DNSResourceRecord[rrs.size()]);
    } catch (IOException e) {
        LOG.error(e);
    } catch (JSONException e) {
        LOG.error(e);
    }
    return null;
}