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:Main.java

/**
 * Returns an iterator over the children of the given element with
 * the given tag name./*from w w  w.  j ava2  s  .c  om*/
 * @param element    The parent element
 * @param tagName    The name of the desired child
 * @return           An interator of children or null if element is null.
 */
public static Iterator<Element> getChildrenByTagName(Element element, String tagName) {
    if (element == null)
        return null;
    // getElementsByTagName gives the corresponding elements in the whole 
    // descendance. We want only children
    NodeList children = element.getChildNodes();
    ArrayList<Element> goodChildren = new ArrayList<>();
    for (int i = 0; i < children.getLength(); i++) {
        Node currentChild = children.item(i);
        if (currentChild.getNodeType() == Node.ELEMENT_NODE
                && ((Element) currentChild).getTagName().equals(tagName)) {
            goodChildren.add((Element) currentChild);
        }
    }
    return goodChildren.iterator();
}

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

public static void updatePageLinks(Connection db, Wiki wiki) throws SQLException {
    // Delete any items that no longer exist
    // Add any new items
    ArrayList pageList = getPageLinks(wiki);
    Iterator i = pageList.iterator();
    while (i.hasNext()) {
        String subject = (String) i.next();
        LOG.debug("updatePageLinks - PageLink: " + subject);
    }/*ww w.j a v  a2  s  .co m*/
}

From source file:Main.java

/**
 * Returns an iterator over the children of the given element with
 * the given tag name.//from  w  w  w  .ja  v a2  s .  c o  m
 *
 * @param element The parent element
 * @param tagName The name of the desired child
 * @return An interator of children or null if element is null.
 */
public static Iterator getChildrenByTagName(Element element, String tagName) {
    if (element == null) {
        return null;
    }
    // getElementsByTagName gives the corresponding elements in the whole
    // descendance. We want only children

    NodeList children = element.getChildNodes();
    ArrayList goodChildren = new ArrayList();
    for (int i = 0; i < children.getLength(); i++) {
        Node currentChild = children.item(i);
        if (currentChild.getNodeType() == Node.ELEMENT_NODE
                && ((Element) currentChild).getTagName().equals(tagName)) {
            goodChildren.add(currentChild);
        }
    }
    return goodChildren.iterator();
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

@SuppressWarnings("all")
public static String[] getShortcutsCompleteList(String cmd) {
    ArrayList result = new ArrayList();

    ShortcutsManager scm = ShortcutsManager.getInstance();

    ArrayList customCmdNameList = scm.getCmdNameList();
    if (customCmdNameList != null) {
        for (Iterator it = customCmdNameList.iterator(); it.hasNext();) {
            String cmdName = (String) it.next();
            if (cmdName.toLowerCase().startsWith(cmd))
                result.add(cmdName);/*from ww  w  .ja  v a 2s.  c  o  m*/
        }
    }

    if (result.size() <= 0)
        return null;

    String[] resultArray = new String[result.size()];
    for (int i = 0; i < resultArray.length; i++) {
        resultArray[i] = (String) result.get(i);
    }
    return resultArray;
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

@SuppressWarnings("all")
public static Shortcut[] getShortcutsCompleteList2(String cmd) {
    ArrayList result = new ArrayList();

    ShortcutsManager scm = ShortcutsManager.getInstance();

    boolean lowerCase = false;
    if (cmd.toLowerCase().equals(cmd)) {
        lowerCase = true;//from www  .j  a  va 2s.c o  m
    }
    ArrayList customCmdNameList = scm.getAll();
    if (customCmdNameList != null) {
        for (Iterator it = customCmdNameList.iterator(); it.hasNext();) {
            Shortcut shortcut = (Shortcut) it.next();
            String cmdName = shortcut.getName();
            if (lowerCase) {
                cmdName = cmdName.toLowerCase();
            }
            if (FilenameUtils.wildcardMatch(cmdName, cmd, IOCase.INSENSITIVE) || cmdName.startsWith(cmd)) {
                result.add(shortcut);
            }
        }
    }

    if (result.size() <= 0)
        return null;

    Shortcut[] resultArray = new Shortcut[result.size()];
    for (int i = 0; i < resultArray.length; i++) {
        resultArray[i] = (Shortcut) result.get(i);
    }
    return resultArray;
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

@SuppressWarnings("all")
public static String[] getCommandCompleteList(String cmd) {
    ArrayList result = new ArrayList();
    String[] cmds = CommandRegister.getInstance().getCmdNames();

    for (int i = 0; i < cmds.length; i++) {
        if (cmds[i].startsWith(cmd))
            result.add(cmds[i]);//  ww  w  .ja  v a 2s  .  com
    }
    ShortcutsManager scm = ShortcutsManager.getInstance();

    ArrayList customCmdNameList = scm.getCmdNameList();

    if (customCmdNameList != null) {
        for (Iterator it = customCmdNameList.iterator(); it.hasNext();) {
            String cmdName = (String) it.next();
            if (cmdName.startsWith(cmd))
                result.add(cmdName);
        }
    }

    if (result.size() <= 0)
        return null;

    String[] resultArray = new String[result.size()];
    for (int i = 0; i < resultArray.length; i++) {
        resultArray[i] = (String) result.get(i);
    }
    return resultArray;
}

From source file:Main.java

/**
 * Returns an iterator over the children of the given element with
 * the given tag name.//from ww  w . ja  va 2  s . co  m
 *
 * @param element    The parent element
 * @param tagName    The name of the desired child
 * @return           An interator of children or null if element is null.
 */
public static Iterator<Element> getChildrenByTagName(Element element, String tagName) {
    if (element == null)
        return null;
    // getElementsByTagName gives the corresponding elements in the whole 
    // descendance. We want only children

    NodeList children = element.getChildNodes();
    ArrayList<Element> goodChildren = new ArrayList<Element>();
    for (int i = 0; i < children.getLength(); i++) {
        Node currentChild = children.item(i);
        if (currentChild.getNodeType() == Node.ELEMENT_NODE
                && ((Element) currentChild).getTagName().equals(tagName)) {
            goodChildren.add((Element) currentChild);
        }
    }
    return goodChildren.iterator();
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherApplication.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
    while (iter.hasNext()) {
        processInstallShortcut(context, iter.next());
    }/*w ww.  ja va  2s .c om*/
}

From source file:com.github.anba.es6draft.chakra.ChakraTest.java

private static Iterator<String> lineIterator(Path p) throws IOException {
    try (BufferedReader reader = bomReader(Files.newInputStream(p))) {
        ArrayList<String> list = new ArrayList<>();
        for (;;) {
            String line = reader.readLine();
            if (line == null)
                break;
            list.add(line);/*from w ww.  jav  a  2s .  co  m*/
        }
        return list.iterator();
    }
}

From source file:info.unyttig.helladroid.newzbin.NewzBinController.java

/**
 * Fetches a report from Newzbin based on a given id.
 * However if the report is already cached, its just fetched from the hashmap.
 * @param id/*from  ww  w  . ja  va2  s.  c om*/
 */
public static NewzBinReport getReportInfo(int id) {
    if (detailedReports.containsKey(id))
        return detailedReports.get(id);

    String url = NBAPIURL + "reportinfo/";
    HashMap<String, String> searchOptions = new HashMap<String, String>();
    searchOptions.put("id", "" + id);
    try {
        HttpResponse response = doPost(url, searchOptions);
        checkReturnCode(response.getStatusLine().getStatusCode(), false);
        InputStream is = response.getEntity().getContent();

        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        NewzBinDRHandler handler = new NewzBinDRHandler();
        if (reports.containsKey(id))
            handler.nbdr = reports.get(id);
        xr.setContentHandler(handler);
        xr.parse(new InputSource(is));
        detailedReports.put(id, handler.getParsedData());
        // Temp
        ArrayList<NewzBinReportComment> comments = handler.nbdr.getComments();
        Log.i(LOG_NAME, "Comments size: " + comments.size());
        Iterator<NewzBinReportComment> sd = comments.iterator();
        while (sd.hasNext()) {
            NewzBinReportComment nrc = sd.next();
            Log.i(LOG_NAME, nrc.toString());
        }
        return handler.getParsedData();
    } catch (ClientProtocolException e) {
        Log.e(LOG_NAME, "ClientProtocol thrown: ", e);
    } catch (IOException e) {
        Log.e(LOG_NAME, "IOException thrown: ", e);
    } catch (NewzBinPostReturnCodeException e) {
        Log.e(LOG_NAME, "POST ReturnCode error: " + e.toString());
    } catch (ParserConfigurationException e) {
        Log.e(LOG_NAME, "ParserError thrown: ", e);
    } catch (SAXException e) {
        Log.e(LOG_NAME, "SAXError thrown: ", e);
    }
    return null;
}