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:de.fabianonline.telegram_backup.DownloadManager.java

private void _downloadMedia() throws RpcErrorException, IOException, TimeoutException {
    logger.info("This is _downloadMedia");
    logger.info("Checking if there are messages in the DB with a too old API layer");
    LinkedList<Integer> ids = db
            .getIdsFromQuery("SELECT id FROM messages WHERE has_media=1 AND api_layer<" + Kotlogram.API_LAYER);
    if (ids.size() > 0) {
        System.out.println(//from   w w  w .j  a v a 2s .  com
                "You have " + ids.size() + " messages in your db that need an update. Doing that now.");
        logger.debug("Found {} messages", ids.size());
        downloadMessages(ids);
    }

    LinkedList<TLMessage> messages = this.db.getMessagesWithMedia();
    logger.debug("Database returned {} messages with media", messages.size());
    prog.onMediaDownloadStart(messages.size());
    for (TLMessage msg : messages) {
        AbstractMediaFileManager m = FileManagerFactory.getFileManager(msg, user, client);
        logger.trace("message {}, {}, {}, {}, {}", msg.getId(),
                msg.getMedia().getClass().getSimpleName().replace("TLMessageMedia", ""),
                m.getClass().getSimpleName(), m.isEmpty() ? "empty" : "non-empty",
                m.isDownloaded() ? "downloaded" : "not downloaded");
        if (m.isEmpty()) {
            prog.onMediaDownloadedEmpty();
        } else if (m.isDownloaded()) {
            prog.onMediaAlreadyPresent(m);
        } else {
            m.download();
            prog.onMediaDownloaded(m);
        }
    }
    prog.onMediaDownloadFinished();
}

From source file:mitm.application.djigzo.james.mailets.MailAttributes.java

@SuppressWarnings("unchecked")
@Override/*from   w  w  w . j  a  v  a  2  s.c o  m*/
public void serviceMailTransacted(Mail mail) throws MessagingException {
    /*
     * First delete all attributes, then set and finally add
     */
    for (String attribute : deleteAttributes) {
        mail.removeAttribute(attribute);
    }

    /*
     * Set attributes
     */
    for (Entry<String, String> attribute : setAttributes.entrySet()) {
        LinkedList<String> attributes = parseAttribute(attribute.getValue(), mail);

        if (attributes.size() > 0) {
            mail.setAttribute(attribute.getKey(), StringUtils.join(attributes, ','));
        } else {
            mail.removeAttribute(attribute.getKey());
        }
    }

    /*
     * Serialized attributes
     */
    for (Entry<String, Serializable> attribute : serializedAttributes.entrySet()) {
        mail.setAttribute(attribute.getKey(), attribute.getValue());
    }

    /*
     * Add attributes. If an attribute already exists and is a Collection, the new value
     * will be added to the collection. If not, a LinkedList will be created and the 
     * value will be added to the list.
     */
    for (Entry<String, List<String>> attribute : addAttributes.entrySet()) {
        /*
         * Check if the attribute exists and is a collection
         */
        Object existingAttr = mail.getAttribute(attribute.getKey());

        Collection<Object> attributes;

        if (existingAttr == null || !(existingAttr instanceof Collection)) {
            attributes = new LinkedList<Object>();
        } else {
            attributes = (Collection<Object>) existingAttr;
        }

        attributes.addAll(parseAttributes(attribute.getValue(), mail));

        if (attributes.size() > 0) {
            mail.setAttribute(attribute.getKey(), (Serializable) attributes);
        } else {
            mail.removeAttribute(attribute.getKey());
        }
    }

    if (nextProcessor != null) {
        mail.setState(nextProcessor);
    }
}

From source file:m.c.m.proxyma.context.ProxymaContext.java

/**
 * Remove a ProxyFolder from the context
 * @param proxyFolder the proxyFolder to remove.
 * @throws IllegalArgumentException if the context doesn't exist
 * @throws NullArgumentException if the argument is null
 *//* www  .  j  a  v  a2s.c o m*/
public void removeProxyFolder(ProxyFolderBean proxyFolder)
        throws IllegalArgumentException, NullArgumentException {
    if (proxyFolder == null) {
        log.warning("Null ProxyFolderBean parameter.. Ignoring operation");
        throw new NullArgumentException("Null ProxyFolderBean parameter.. Ignoring operation");
    } else {
        boolean exists = proxyFoldersByURLEncodedName.containsKey(proxyFolder.getURLEncodedFolderName());
        if (!exists) {
            log.warning("The Proxy foder doesn't exists.. nothing done.");
            throw new IllegalArgumentException("The Proxy foder doesn't exists.. nothing done.");
        } else {
            log.finer("Deleting existing Proxy folder " + proxyFolder.getFolderName());
            proxyFoldersByURLEncodedName.remove(proxyFolder.getURLEncodedFolderName());

            //Delete the proxy-folder from the second indexing map.
            String destinationHost = URLUtils.getDestinationHost(proxyFolder.getDestinationAsURL());
            LinkedList<ProxyFolderBean> currentSlot = null;
            currentSlot = proxyFoldersByDestinationHost.get(destinationHost);
            if (currentSlot.size() == 1) {
                currentSlot.remove(proxyFolder);
                proxyFoldersByDestinationHost.remove(destinationHost);
            } else {
                Iterator<ProxyFolderBean> iterator = currentSlot.iterator();
                while (iterator.hasNext()) {
                    ProxyFolderBean curFolder = iterator.next();
                    if (curFolder == proxyFolder)
                        iterator.remove();
                }
            }
        }
    }
}

From source file:eu.uqasar.model.qmtree.QMTreeNode.java

@Override
public boolean canChangePositionWithNextSibling(boolean changeParents) {
    LinkedList<QMTreeNode> directSiblings = (LinkedList<QMTreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex + 1;
    if (newIndex < directSiblings.size()) {
        // switch currently selected node with the next one
        return true;
    } else if (newIndex >= directSiblings.size() && changeParents) {
        // add currently selected node as first entry to the next parent
        // sibling
        LinkedList<QMTreeNode> parentSiblings = (LinkedList<QMTreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex + 1;
        if (newParentIndex < parentSiblings.size()) {
            return true;
        }//  w  w w.  ja v a 2s  . c o m
    }
    return false;
}

From source file:org.openmeetings.app.remote.ChatService.java

public LinkedList<LinkedList<String>> getAllPublicEmoticons() {
    try {//ww  w. j  a v  a  2  s .  c  o m
        LinkedList<LinkedList<String>> publicemotes = new LinkedList<LinkedList<String>>();
        LinkedList<LinkedList<String>> allEmotes = EmoticonsManager.getEmotfilesList();
        for (Iterator<LinkedList<String>> iter = allEmotes.iterator(); iter.hasNext();) {
            LinkedList<String> emot = iter.next();
            LinkedList<String> emotPub = new LinkedList<String>();
            if (emot.get((emot.size() - 1)).equals("y")) {
                emotPub.add(emot.get(0));
                emotPub.add(emot.get(1).replace("\\", ""));
                if (emot.size() > 4) {
                    emotPub.add(emot.get(2).replace("\\", ""));
                    emotPub.add(emot.get(3));
                    emotPub.add(emot.get(4));
                } else {
                    emotPub.add(emot.get(2));
                    emotPub.add(emot.get(3));
                }
                publicemotes.add(emotPub);
            }
        }
        return publicemotes;
    } catch (Exception err) {
        log.error("[getAllPublicEmoticons] ", err);
        return null;
    }
}

From source file:eu.uqasar.model.qmtree.QMTreeNode.java

@SuppressWarnings("unchecked")
@Override/* www . j a v  a  2 s  .  com*/
public boolean changePositionWithNextSibling(boolean changeParents) {
    LinkedList<QMTreeNode> directSiblings = (LinkedList<QMTreeNode>) getMutableSiblings();
    int currentIndex = directSiblings.indexOf(this);
    int newIndex = currentIndex + 1;
    if (newIndex < directSiblings.size()) {
        // switch currently selected node with the next one
        QMTreeNode movedNode = directSiblings.remove(currentIndex);
        directSiblings.add(newIndex, movedNode);
        getParent().setChildren(directSiblings);
        logger.info(String.format("Moving %s from index %s to %s", this, currentIndex, newIndex));
        return true;
    } else if (newIndex >= directSiblings.size() && changeParents) {
        // add currently selected node as first entry to the next parent
        // sibling
        LinkedList<QMTreeNode> parentSiblings = (LinkedList<QMTreeNode>) this.getParent().getMutableSiblings();
        int parentIndex = parentSiblings.indexOf(this.getParent());
        int newParentIndex = parentIndex + 1;
        if (newParentIndex < parentSiblings.size()) {
            QMTreeNode oldParent = this.getParent();
            LinkedList<QMTreeNode> oldParentChildren = (LinkedList) oldParent.getChildren();
            oldParentChildren.removeLast();
            oldParent.setChildren(oldParentChildren);

            QMTreeNode newParent = parentSiblings.get(newParentIndex);
            logger.info(String.format("Moving %s from parent %s to %s", this, this.getParent(), newParent));
            this.setParent(newParent);
            return true;
        }
    }
    return false;
}

From source file:fr.univlorraine.mondossierweb.views.NotesDetailMobileView.java

public void refreshJavascript() {

    //Ajout du javascript
    for (Entry<String, LinkedList<HorizontalLayout>> entry : layoutList.entrySet()) {
        String pere = entry.getKey();
        LinkedList<HorizontalLayout> listeLayoutFils = entry.getValue();
        // traitements
        if (listeLayoutFils != null && listeLayoutFils.size() > 0) {
            String affichagejavascriptfils = "";
            for (HorizontalLayout hl : listeLayoutFils) {
                //On masque par dfaut tous les fils
                Page.getCurrent().getJavaScript()
                        .execute("document.getElementById('" + hl.getId() + "').style.display=\"none\";");
                //Creation du js pour modifier l'affichage au clic sur le pere
                affichagejavascriptfils += "if(document.getElementById('" + hl.getId()
                        + "').style.display==\"none\"){document.getElementById('" + hl.getId()
                        + "').style.display = \"block\";}else{document.getElementById('" + hl.getId()
                        + "').style.display = \"none\";}";
            }/*  w  w w . j av a 2 s. c o  m*/
            //sur le clic du layout pere, on affiche les fils
            Page.getCurrent().getJavaScript().execute("document.getElementById('" + "layout_pere_" + pere
                    + "').onclick=function(){ " + affichagejavascriptfils + "};");
        }
    }
}

From source file:com.scm.reader.livescanner.search.ImageRecognizer.java

/**
 * @param context//from  w ww  .  ja  v  a 2s  .co  m
 * @param data
 * @param dataToPopulate
 * @return
 * @throws IOException
 * @throws JSONException
 * @return Search object
 * 
 * TODO refactor and make this method more readable if time
 */
public Search parseJSON(Context context, String data, Search dataToPopulate) throws IOException, JSONException {
    dataToPopulate.setSearchTime(new Date());
    dataToPopulate.setPending(false);
    JSONObject jObject;

    jObject = new JSONObject(data);

    dataToPopulate.setUuid(jObject.getString("query_id"));

    JSONArray resultArray = (JSONArray) jObject.get("results");

    //no results
    if (resultArray.length() == 0) {
        dataToPopulate.setRecognized(false);
        dataToPopulate.setTitle(context.getResources().getString(R.string.image_not_recognized_title));
        dataToPopulate.setUrl("http://");
    }

    //only one item result
    else if (resultArray.length() < 2) {
        System.out.println("only one item result");
        JSONObject result = resultArray.getJSONObject(0);
        JSONArray recognitions = result.getJSONArray("recognitions");

        dataToPopulate.setRecognized(true);
        //dataToPopulate.setTitle(result.getString("title"));

        JSONArray metaDataArray = result.getJSONArray("metadata");
        JSONObject metaDataObj = metaDataArray.getJSONObject(0);
        JSONObject recognition = recognitions.getJSONObject(0);

        //setting right language
        String title = extractFromLanguageString(metaDataObj.getJSONObject("title"));
        dataToPopulate.setTitle(title);

        String subtitle = extractFromLanguageString(metaDataObj.getJSONObject("subtitle"));
        dataToPopulate.setDetail(subtitle);
        dataToPopulate.setItemUuid(metaDataObj.getString("uuid"));

        String url = "";
        if (metaDataObj.has("response")) {
            System.out.println("direct response");
            JSONObject responseObject = metaDataObj.getJSONObject("response");
            url = responseObject.getString("content");
            LogUtils.logDebug("response qurl " + url);
            System.out.println(url);
        } else {
            System.out.println("normal response");
            url = createResultUrl(metaDataObj.getString("uuid"), recognition.getString("id"));
            LogUtils.logDebug("normal response response qurl " + url);

        }
        dataToPopulate.setUrl(url);
    }
    //multiple results
    else {
        //reading objects inside "results" node

        //inserting ads first
        for (int i = 0; i < resultArray.length(); i++) {
            JSONObject result = resultArray.getJSONObject(i);
            JSONArray metaDataArray = result.getJSONArray("metadata");
            JSONObject metaDataObj = metaDataArray.getJSONObject(0);

            boolean hasKind = false;
            for (int ind = 0; ind < metaDataArray.length(); ind++) {
                if (metaDataArray.getJSONObject(ind).has("kind")) {
                    hasKind = true;
                    break;
                }
            }

            if (hasKind) {
                if (!dataToPopulate.hasSections() && metaDataObj.getString("kind").equals("Ad")) {
                    dataToPopulate.addSection(parseSectionJSON(resultArray, result));
                }
            }
        }

        //inserting everything else than ads

        for (int i = 0; i < resultArray.length(); i++) {
            JSONObject result = resultArray.getJSONObject(i);

            JSONArray metaDataArray = result.getJSONArray("metadata");
            JSONObject metaDataObj = metaDataArray.getJSONObject(0);

            dataToPopulate.setTitle(context.getResources().getString(R.string.multiple_matches));
            if (dataToPopulate.hasSections()) {
                //checking that there is no two of same headers

                /**
                 * If any of the sections contains same header the insert boolean
                 * will be set false and loop is determined
                 */
                boolean insert = false;
                for (int index = 0; index < dataToPopulate.getSections().size(); index++) {
                    if (!metaDataObj.has("kind")) {
                        break;
                    }
                    SearchResultSection section = dataToPopulate.getSections().get(index);
                    if (!metaDataObj.getString("kind").equals(section.getHeader())) {
                        insert = true;
                    } else {
                        insert = false;
                        break;
                    }
                }
                if (insert) {
                    dataToPopulate.addSection(parseSectionJSON(resultArray, result));
                }

            } else {
                dataToPopulate.addSection(parseSectionJSON(resultArray, result));
            }

        }

        dataToPopulate.setRecognized(true);
    }
    //TODO check here
    if (!dataToPopulate.hasSections()) {
        if (dataToPopulate.getUrl() == null || dataToPopulate.getUrl().length() == 0) {
            throw new JSONException("url not found");
        }
        if (dataToPopulate.getTitle() == null || dataToPopulate.getTitle().length() == 0) {
            System.out.println(dataToPopulate.getTitle());
            throw new JSONException("title not found");
        }
    } else {
        // If we have a section with a single object, set title to the item's title
        // This is to avoid bug KOOABA-20
        LinkedList<SearchResultSection> sections = dataToPopulate.getSections();
        if (sections.size() == 1) {
            LinkedList<SearchResultItem> items = sections.getFirst().getItems();
            if (items.size() == 1) {
                dataToPopulate.setTitle(items.getFirst().getTitle());
            }
        }
    }
    return dataToPopulate;
}

From source file:net.semanticmetadata.lire.solr.FastLireRequestHandler.java

/**
 * Returns a random set of documents from the index. Mainly for testing purposes.
 *
 * @param req/*from   w  ww. jav a  2 s  . c o  m*/
 * @param rsp
 * @throws java.io.IOException
 */
private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
    SolrIndexSearcher searcher = req.getSearcher();
    DirectoryReader indexReader = searcher.getIndexReader();
    double maxDoc = indexReader.maxDoc();
    int paramRows = defaultNumberOfResults;
    if (req.getParams().getInt("rows") != null)
        paramRows = req.getParams().getInt("rows");
    LinkedList list = new LinkedList();
    while (list.size() < paramRows) {
        HashMap m = new HashMap(2);
        Document d = indexReader.document((int) Math.floor(Math.random() * maxDoc));
        m.put("id", d.getValues("id")[0]);
        m.put("title", d.getValues("title")[0]);
        list.add(m);
    }
    rsp.add("docs", list);
}

From source file:com.gargoylesoftware.htmlunit.WebConsole.java

/**
 * This method is used by all the public method to process the passed
 * parameters.//from  www  .j av  a2  s. c  o m
 *
 * If the last parameter implements the Formatter interface, it will be
 * used to format the parameters and print the object.
 * @param objs the logging parameters
 * @return a String to be printed using the logger
 */
private String process(final Object[] objs) {
    if (objs == null) {
        return "null";
    }

    final StringBuffer sb = new StringBuffer();
    final LinkedList<Object> args = new LinkedList<>(Arrays.asList(objs));

    final Formatter formatter = getFormatter();

    if (args.size() > 1 && args.get(0) instanceof String) {
        final StringBuilder msg = new StringBuilder((String) args.remove(0));
        int startPos = msg.indexOf("%");

        while (startPos > -1 && startPos < msg.length() - 1 && args.size() > 0) {
            if (startPos != 0 && msg.charAt(startPos - 1) == '%') {
                // double %
                msg.replace(startPos, startPos + 1, "");
            } else {
                final char type = msg.charAt(startPos + 1);
                String replacement = null;
                switch (type) {
                case 'o':
                case 's':
                    replacement = formatter.parameterAsString(pop(args));
                    break;
                case 'd':
                case 'i':
                    replacement = formatter.parameterAsInteger(pop(args));
                    break;
                case 'f':
                    replacement = formatter.parameterAsFloat(pop(args));
                    break;
                default:
                    break;
                }
                if (replacement != null) {
                    msg.replace(startPos, startPos + 2, replacement);
                    startPos = startPos + replacement.length();
                } else {
                    startPos++;
                }
            }
            startPos = msg.indexOf("%", startPos);
        }
        sb.append(msg);
    }

    for (final Object o : args) {
        if (sb.length() != 0) {
            sb.append(' ');
        }
        sb.append(formatter.printObject(o));
    }
    return sb.toString();
}