Example usage for java.util ArrayList iterator

List of usage examples for java.util ArrayList iterator

Introduction

In this page you can find the example usage for java.util ArrayList iterator.

Prototype

public Iterator<E> iterator() 

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:App.java

protected ArrayList<String> checkLinks(ArrayList<Urls> originalValue) {

    // here we convert our Data arrayList to a String arrayList
    ArrayList<String> stringArray = new ArrayList<String>();

    for (Urls currentData : originalValue) {
        stringArray.add(currentData.getContentUrl());
    }//from   w w  w .  j  av  a 2  s . c om

    // System.out.println("Original array with " + stringArray.size() + "
    // elements");
    // System.out.println("============");
    // stringArray.forEach(System.out::println);

    // get an iterator
    Iterator iter = stringArray.iterator();
    String strElement = "";
    URL linkAsUrl = null;

    // variable to count the number of valid urls
    int count = 0;

    while (iter.hasNext()) {
        strElement = (String) iter.next();
        // System.out.println("============");
        // System.out.println("CHECKING: " + strElement);

        try {
            linkAsUrl = new URL(strElement);
            imageResponses = ImageIO.read(linkAsUrl);
            getImageFromHttp(strElement, labelTryLinks);
            // System.out.println("OK");
            // count++;
        } catch (MalformedURLException e) {
            System.out.println("malformed exception with url " + strElement);
            e.printStackTrace();
        } catch (NullPointerException e) {
            System.out.println("NullPointerException: element to be removed - " + strElement);
            iter.remove();
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IIOException \nLink to be removed: " + strElement);
            iter.remove();
            e.printStackTrace();
        }
        // stop checking when 4 valid links are found
        if (count == 4) {
            break;
        }
    }

    // System.out.println("=======================");
    // System.out.println("Filtered array: ");
    // stringArray.forEach(System.out::println);
    // System.out.println("number of elements after the deletion " +
    // stringArray.size());

    return stringArray;
}

From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java

private static void appendWiki(WikiPDFContext context, Wiki currentWiki, Document document, Connection db,
        ArrayList<Integer> wikiListDone) throws SQLException {

    LOG.debug("appendWiki-> " + currentWiki.getSubject());

    // Context Objects
    Project project = context.getProject();
    WikiExportBean exportBean = context.getExportBean();

    // Track the wikis to get appended to the output
    ArrayList<Integer> wikiListTodo = new ArrayList<Integer>();

    try {/*from   ww  w .  j a  va2 s  .com*/
        // Output the name of the Wiki
        boolean hasTitle = StringUtils.hasText(currentWiki.getSubject());
        if (hasTitle) {
            Anchor wikiAnchor = new Anchor(currentWiki.getSubject(), wikiFont);
            wikiAnchor.setName(currentWiki.getSubject().toLowerCase());
            LOG.debug("Add anchor: " + currentWiki.getSubject().toLowerCase());
            document.add(wikiAnchor);
            LOG.debug("document.add(wikiAnchor)");
        }

        // Output the wiki content
        parseContent(context, currentWiki, currentWiki.getContent(), document, null, db, wikiListTodo,
                wikiListDone, 0f);
        wikiListDone.add(currentWiki.getId());

        // See if any linked wikis should be appended
        if (exportBean.getFollowLinks() && wikiListTodo.size() > 0) {
            Iterator i = wikiListTodo.iterator();
            while (i.hasNext()) {
                Integer id = (Integer) i.next();
                if (id > -1 && !wikiListDone.contains(id)) {
                    Wiki subwiki = new Wiki(db, id);
                    document.add(Chunk.NEXTPAGE);
                    appendWiki(context, subwiki, document, db, wikiListDone);
                }
                //i.remove();
            }
        }
    } catch (Exception e) {
        LOG.error("appendWiki", e);
    }
}

From source file:com.chinamobile.bcbsp.comm.CommunicatorNew.java

@Override
public Iterator<IMessage> getMessageIterator(String vertexID) throws IOException {
    ArrayList<IMessage> incomedQueue = messageManager.removeIncomedQueue(vertexID);
    if (incomedQueue == null) {
        LOG.info("Vertex message is empty!");
        return null;
    }/*from  w w w .  jav  a  2s . c  o  m*/
    Iterator<IMessage> iterator = incomedQueue.iterator();
    return iterator;
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferHandler.java

protected Transferable createTransferable(JComponent c, int action) {
    SpreadSheet spreadSheet = getSpreadSheet(c);
    if (spreadSheet == null)
        return null;
    ArrayList nodes = (ArrayList) spreadSheet.getSelectedNodes().clone();

    ArrayList fields = spreadSheet.getSelectedFields();
    boolean nodeSelection = (fields == null);
    if (fields == null)
        fields = spreadSheet.getSelectableFields();
    if (action == TransferHandler.COPY) {
        if (nodeSelection) {
            SpreadSheet.SpreadSheetAction a = getNodeListCopyAction().getSpreadSheetAction();
            a.execute(nodes);//from  ww w.  ja  v  a  2s  .  c om
        }
        return new NodeListTransferable(nodes, fields, spreadSheet, spreadSheet.getSelectedRows(),
                spreadSheet.getSelectedColumns(), nodeSelection);
    } else if (action == TransferHandler.MOVE) {//cut
        if (nodeSelection) {
            SpreadSheet.SpreadSheetAction a = ((nodeSelection) ? getNodeListCutAction()
                    : getNodeListCopyAction()).getSpreadSheetAction();

            for (Iterator i = nodes.iterator(); i.hasNext();) {
                Node node = (Node) i.next();
                final boolean[] okForAll = new boolean[] { false };
                if (!transformSubprojectBranches(node, spreadSheet.getCache().getModel().getDataFactory(),
                        new Predicate() {
                            public boolean evaluate(Object arg0) {
                                if (okForAll[0])
                                    return true;
                                Node parent = (Node) arg0;
                                boolean r = Alert.okCancel(Messages.getString("Message.subprojectCut"));
                                if (r)
                                    okForAll[0] = true;
                                return r;
                            }

                        }))
                    return null;
            }

            a.execute(nodes);
        }
        return new NodeListTransferable(nodes, fields, spreadSheet, spreadSheet.getSelectedRows(),
                spreadSheet.getSelectedColumns(), nodeSelection);
    } else
        return null;
}

From source file:com.hp.hpl.inkml.Ink.java

/**
 * This method gives an Iterator for the List of Trace objects that - the Ink object contains. It includes the Trace object contained in Trace collections
 * such as TraceGroup and TraceView.//from  w  ww .  j a  v  a  2  s . c o  m
 * 
 * @return The Itearator object that can be used to navigate the list of - Trace objects that contained within the current Ink document.
 * @throws InkMLException
 */
public Iterator<Trace> getTraceIterator() throws InkMLException {
    final ArrayList<Trace> traceList = new ArrayList<Trace>();
    if (this.traceDataList != null) {
        final Iterator<TraceDataElement> inkChildrenListIterator = this.traceDataList.iterator();
        while (inkChildrenListIterator.hasNext()) {
            final InkElement object = inkChildrenListIterator.next();
            final String inkElmntType = object.getInkElementType();
            if ("Trace".equals(inkElmntType)) {
                traceList.add((Trace) object);
            }
            if ("TraceGroup".equals(inkElmntType)) {
                traceList.addAll(((TraceGroup) object).getTraceList());
            }
            if ("TraceGroup".equals(inkElmntType)) {
                traceList.addAll(((TraceView) object).getTraceList());
            }
        }
    }
    return traceList.iterator();
}

From source file:eu.aliada.ckancreation.impl.CKANCreation.java

/**
 * Update the organization information in CKAN Datahub.
 *
 * @param orgId           the organization id.
 * @param orgName         the organization name.
 * @param orgTitle         the organization title.
 * @param orgDescription   the organization description.
 * @param orgImageURL      the organization image URL.
 * @param orgHomePage      the organization home page.
 * @param lUsers         the organization's users and their capacity.
 * @return   the {@link eu.aliada.ckancreation.model.CKANOrgResponse}
 *          which contains the information of the organization in CKAN.
 * @since 2.0/*  w ww .j  a  va2  s .co  m*/
 */
public CKANOrgResponse updateOrganizationCKAN(final String orgId, final String orgName, final String orgTitle,
        final String orgDescription, final String orgImageURL, final String orgHomePage,
        final ArrayList<Map<String, String>> lUsers) {
    final Client client = ClientBuilder.newClient();
    final WebTarget webTarget = client.target(jobConf.getCkanApiURL());

    //Create a Java Object with the organization data
    final Organization org = new Organization(orgName, orgId, orgTitle, orgDescription, orgImageURL,
            orgHomePage);
    /////////////////////////******************///////////////////
    ///VERY IMPORTANT!!!!!
    //Update also the users dictionary(including "capacity" attribute), otherwise we lose rights for updating the organization
    for (Iterator<Map<String, String>> iterUsers = lUsers.iterator(); iterUsers.hasNext();) {
        Map<String, String> user = iterUsers.next();
        org.setUser(user.get("name"), user.get("capacity"));
    }

    //Convert Java Object to JSON representation with JACKSON libraries
    String orgJSON = "";
    final ObjectMapper mapper = new ObjectMapper();
    try {
        orgJSON = mapper.writeValueAsString(org);
    } catch (Exception exception) {
        LOGGER.error(MessageCatalog._00032_OBJECT_CONVERSION_FAILURE, exception);
    }

    //POST 
    final WebTarget resourceWebTarget = webTarget.path("/organization_update");
    final Response postResponse = resourceWebTarget.request(MediaType.APPLICATION_XML_TYPE)
            .header("Authorization", jobConf.getCkanApiKey()).post(Entity.json(orgJSON));
    final String orgUpdateResp = postResponse.readEntity(String.class);
    //Convert JSON representation to Java Object with JACKSON libraries
    CKANOrgResponse cResponse = new CKANOrgResponse();
    try {
        cResponse = mapper.readValue(orgUpdateResp, CKANOrgResponse.class);
    } catch (Exception exception) {
        LOGGER.error(MessageCatalog._00032_OBJECT_CONVERSION_FAILURE, exception);
    }
    return cResponse;
}

From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java

private LinkedHashMap<String, String> getAppInfos(String regex) {
    LinkedHashMap<String, String> appInfos = new LinkedHashMap<String, String>();
    ArrayList<Element> list = new ArrayList<Element>();
    // list.addAll(annotation.getUserInformation());
    list.addAll(annotation.getApplicationInformation());
    int i = 0;// w ww  .  jav a  2 s.c o  m
    for (Iterator<Element> iter = list.iterator(); iter.hasNext();) {
        Element ann = iter.next();
        String name = ann.getLocalName();
        if ("appinfo".equals(name.toLowerCase())) {//$NON-NLS-1$
            name = ann.getAttribute("source");//$NON-NLS-1$
            if (name.equals(regex)) {
                appInfos.put(name + "_" + i, ann.getFirstChild().getNodeValue());//$NON-NLS-1$
                i++;
            } else if (name.matches(regex)) {
                appInfos.put(name, ann.getFirstChild().getNodeValue());
            }
        }
    }
    return appInfos;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Encode a list of strings by 'escaping' all instances of: delim, '\', \r, \n. The
 * escape char is '\'.//from ww w.j  a v a  2 s.  c o  m
 * 
 * This is used to build text lists separated by 'delim'.
 * 
 * @param s      String to convert
 * @return      Converted string
 */
static String encodeList(ArrayList<String> sa, char delim) {
    StringBuilder ns = new StringBuilder();
    Iterator<String> si = sa.iterator();
    if (si.hasNext()) {
        ns.append(encodeListItem(si.next(), delim));
        while (si.hasNext()) {
            ns.append(delim);
            ns.append(encodeListItem(si.next(), delim));
        }
    }
    return ns.toString();
}

From source file:fr.ritaly.dungeonmaster.champion.Party.java

/**
 * Returns the champions in the party as a list. The given boolean
 * determines whether only living (false) or living and dead (true)
 * champions are returned.//w  w  w.j  a v a  2  s .  co  m
 *
 * @param all
 *            whether dead champions are to be returned too.
 * @return a list of champions. Never returns null.
 */
public List<Champion> getChampions(boolean all) {
    final ArrayList<Champion> result = new ArrayList<Champion>(champions.values());

    if (!all) {
        // Filter out the dead champions
        for (final Iterator<Champion> it = result.iterator(); it.hasNext();) {
            if (it.next().isDead()) {
                it.remove();
            }
        }
    }

    return result;
}

From source file:com.tremolosecurity.config.util.UnisonConfigManagerImpl.java

@Override
public UrlHolder findURL(String url) throws Exception {

    UrlHolder ret = this.cache.get(url);
    if (ret != null) {
        return ret;
    }//w ww .  j av a 2  s  .  c o m

    URL urlObj = new URL(url.toLowerCase());

    if (urlObj.getPath().startsWith(this.authPath) && !urlObj.getPath().startsWith(this.authIdP)) {
        return null;
    }

    String host = urlObj.getHost();
    ArrayList<UrlHolder> urls = this.byHost.get(host);

    if (urls == null) {

    }

    ArrayList<UrlHolder> tmpList = new ArrayList<UrlHolder>();
    if (urls != null) {
        tmpList.addAll(urls);
    }

    urls = this.byHost.get("*");
    if (urls != null) {
        tmpList.addAll(urls);
    }

    ret = null;

    Iterator<UrlHolder> holders = tmpList.iterator();
    while (holders.hasNext()) {
        UrlHolder holder = holders.next();
        if (holder.getUrl().isRegex()) {
            if (holder.getPattern().matcher(urlObj.getPath()).matches()) {
                if (ret != null && ret.getWeight() < holder.getWeight()) {
                    ret = holder;
                } else if (ret == null) {
                    ret = holder;
                }
            }
        } else {

            if (ret != null) {

            }
            if (urlObj.getPath().startsWith(holder.getLowerCasePath())) {
                if (ret != null
                        && ((ret.getWeight() < holder.getWeight()) || ((ret.getWeight() == holder.getWeight())
                                && (ret.getUrl().getUri().length() < holder.getUrl().getUri().length())))) {
                    ret = holder;
                } else if (ret == null) {
                    ret = holder;
                }
            }
        }
    }

    return ret;

}