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

/**
 * Constructs a XPath query to the supplied node.
 * /*from w w w  .j  ava 2s.c om*/
 * @param n
 * @return
 */
public static String getXPath(Node n) {
    if (null == n) {
        throw new IllegalArgumentException("Invalid node");
    }

    ArrayList<Node> hierarchy = new ArrayList<Node>();
    StringBuffer buffer = new StringBuffer();
    Node parent = null;

    // Push parent element's on stack
    hierarchy.add(n);
    parent = n.getParentNode();
    while (parent != null && parent.getNodeType() != Node.DOCUMENT_NODE) {
        hierarchy.add(0, parent);
        parent = parent.getParentNode();
    }

    Iterator<Node> i = hierarchy.iterator();
    while (i.hasNext()) {
        Node node = i.next();
        buffer.append("/");
        buffer.append(node.getNodeName());
        if (node.hasAttributes()) {
            Node uuid = node.getAttributes().getNamedItem("uuid");
            if (uuid != null) {
                buffer.append("[@uuid='");
                buffer.append(uuid.getNodeValue());
                buffer.append("']");
            }
        }
    }

    // return buffer
    return buffer.toString();
}

From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.cache.java

private static void deleteCacheRecursive(String uri, int depth) {
    int pos = uri.lastIndexOf("/");
    while (pos != -1) { // we need to walk up the tree to check
        Document doc = (Document) cached.get(uri);
        if (doc != null) {
            // we have it in cache lets delete the main cache entry
            cached.remove(uri);//from   w ww. ja v a2 s  .com

            if (debuglevel.equals("high"))
                System.out.println(depth + " removed main=" + uri);
            //System.out.println(depth+" removed main="+uri);
            // now was this uri also a referid somewhere ? only works for one (daniel?)
            String refer = refers.get(uri);
            if (refer != null) {
                refers.remove(uri); // remove it
                // call it for subchilds
                if (depth < 10) {
                    if (debuglevel.equals("high"))
                        System.out.println(depth + " checking refer=" + refer);
                    //System.out.println(depth+" checking refer="+refer);

                    deleteCacheRecursive(refer, depth++);
                } else {
                    System.out.println("***** RECURSIVE ERROR IN CACHE REACHED 10");
                }
            }
        }

        // also remove them from the ones with params
        ArrayList<String> list = paramref.get(uri);
        if (list != null) {
            for (Iterator<String> i = list.iterator(); i.hasNext();) {
                String p = i.next();
                //System.out.println("REMOVE PARAM="+uri+p);
                cached.remove(uri + p);
                paramref.remove(uri);
            }
        }

        uri = uri.substring(0, pos);
        pos = uri.lastIndexOf("/");
        //System.out.println(depth+" new uri="+uri);
    }
}

From source file:com.redhat.rhn.frontend.action.systems.monitoring.BaseProbeAction.java

/**
 * Get the parameter values for <code>probe</code> as a list
 * of <code>CommandParameterValue</code> objects
 * @param probe the probe from which parameter values should be taken; if
 * it is <code>null</code>, the commands default values are used
 * @param command the command whose parameters to list
 * @param submitted whether the user submitted parameter values
 *///from  ww w  .  j a va  2s  .  c o m
protected static void setParamValueList(HttpServletRequest req, Probe probe, Command command,
        boolean submitted) {
    List result = new LinkedList();
    List thresholdParams = new LinkedList();
    ArrayList params = new ArrayList(command.getCommandParameters());
    Collections.sort(params, new CommandParameterComparator());
    Iterator i = params.iterator();
    String lastLabel = "";
    while (i.hasNext()) {
        CommandParameter cp = (CommandParameter) i.next();
        boolean isPassword = isPassword(cp);
        if (cp.isFieldVisible()) {
            String value = null;
            if (submitted) {
                value = paramValue(cp, req);
            } else if (probe == null) {
                value = cp.getDefaultValue();
            } else {
                value = probe.getProbeParameterValue(cp).getValue();
            }
            boolean isThreshold = cp instanceof ThresholdParameter;
            Map map = getCommandParameterMap(cp, paramName(cp), value, isThreshold, lastLabel);
            if (isThreshold) {
                thresholdParams.add(map);
            } else {
                result.add(map);
            }
            if (isPassword) {
                // Add extra password confirm field
                Map confirmmap = getCommandParameterMap(cp, paramName(cp) + "_confirm", null, false, lastLabel);
                String confirmLabel = (String) confirmmap.get("label");
                confirmLabel = confirmLabel + "_confirm";
                confirmmap.put("label", confirmLabel);
                // Get rid of value from map
                if (submitted) {
                    String requestParamName = paramName(cp) + "_confirm";
                    String confirmValue = req.getParameter(requestParamName);
                    confirmmap.put("value", confirmValue);
                } else {
                    if (value != null) {
                        map.put("value", PASSWORD_PLACEHOLDER);
                        confirmmap.put("value", PASSWORD_PLACEHOLDER);
                    } else {
                        map.put("value", null);
                    }
                }
                result.add(confirmmap);
            }
        }
    }
    result.addAll(thresholdParams);
    req.setAttribute("paramValueList", result);
}

From source file:com.cyou.poplauncher.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            //final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;

            if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) {
                if (DBG)
                    Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
                continue;
            }//from  w ww.  jav  a 2 s.  co m

            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

            // TODO-XXX: Disable duplicates for now
            if (!exists /* && allowDuplicate */) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);
            }
            /*
            else if (exists && !allowDuplicate) {
            result = INSTALL_SHORTCUT_IS_DUPLICATE;
            duplicateName = name;
            }
            */
        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, context.getString(R.string.shortcut_duplicate, duplicateName),
                    Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts);
        }
    }
}

From source file:com.yuchu.launcher.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            //final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;

            if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) {
                if (DBG)
                    Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
                continue;
            }/*from   ww w  . j  a  v  a  2s.co  m*/

            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

            // TODO-XXX: Disable duplicates for now
            if (!exists /* && allowDuplicate */) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);
            }
            /*
            else if (exists && !allowDuplicate) {
            result = INSTALL_SHORTCUT_IS_DUPLICATE;
            duplicateName = name;
            }
            */
        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, context.getString(R.string.shortcut_duplicate, duplicateName),
                    Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedApps(context, addShortcuts, new ArrayList<AppInfo>());
        }
    }
}

From source file:Main.java

public static void cleanWhiteSpaceNodes(Element node, boolean deep) {
    NodeList list = node.getChildNodes();
    ArrayList temp = new ArrayList();
    for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);//from w  w w  . j ava 2  s  .co m
        short type = n.getNodeType();
        if (type == 1) {
            Element e = (Element) n;
            cleanWhiteSpaceNodes(e, deep);
        } else if (type == 3) {
            Text text = (Text) n;
            String val = text.getData();
            if (val.trim().equals(""))
                temp.add(text);
        }
    }

    for (Iterator i = temp.iterator(); i.hasNext(); node.removeChild((Node) i.next()))
        ;
}

From source file:ExifUtils.ExifReadWrite.java

private static List<meta> exifToMetaET(ArrayList<String> filenames, File dir) {
    String filename = null;/*from   w w  w  .  j a  v a  2 s.co m*/
    if (filenames.size() == 1 && filenames.get(0).length() > 5) {
        filename = dir + "\\" + filenames.get(0);
    }
    filenames.add(0, "-OriginalDocumentID");
    filenames.add(0, "-DocumentID");
    filenames.add(0, "-InstanceID");
    filenames.add(0, "-DateTimeOriginal");
    filenames.add(0, "-xmp:DateTimeOriginal");
    filenames.add(0, "-Model");
    filenames.add(0, "exiftool");
    ArrayList<String> exifTool = exifTool(filenames.toArray(new String[0]), dir);
    Iterator<String> iterator = exifTool.iterator();
    ArrayList<meta> results = new ArrayList<>();
    int i = -1;
    String model = null;
    String note = "";
    String iID = null;
    String dID = null;
    String odID = null;
    String captureDate = null;
    Boolean dateFormat = null;
    while (iterator.hasNext()) {
        String line = iterator.next();
        if (line.startsWith("========")) {
            if (i > -1) {
                meta meta = new meta(filename, getZonedTimeFromStr(captureDate), dateFormat, model, iID, dID,
                        odID, note);
                System.out.println(meta);
                results.add(meta);
            }
            i++;
            String fileTemp = line.substring(9).replaceAll("./", "").replaceAll("/", "\\");
            filename = dir + "\\" + fileTemp;
            model = null;
            captureDate = null;
            dID = null;
            odID = null;
            note = "";
            dateFormat = false;

            //End of exiftool output
        } else if (line.contains("image files read")) {
            if (!line.contains(" 0 image files read")) {
            }
        } else if (line.contains("files could not be read")) {

        } else {
            String tagValue = "";
            if (line.length() > 34)
                tagValue = line.substring(34);
            switch (line.substring(0, 4)) {
            case "Date":
                if (captureDate == null)
                    captureDate = tagValue;
                else {
                    if (Math.abs(captureDate.length() - tagValue.length()) == 6)
                        dateFormat = true;
                    captureDate = tagValue;
                }
                break;
            case "Came":
                model = tagValue;
                break;
            case "Orig":
                odID = tagValue;
                break;
            case "Docu":
                dID = tagValue;
                break;
            case "Inst":
                iID = tagValue;
                break;
            case "Warn":
                note = line;
                break;
            }
        }
    }
    if (filename != null) {
        meta meta = new meta(filename, getZonedTimeFromStr(captureDate), dateFormat, model, iID, dID, odID,
                note);
        System.out.println(meta);
        results.add(meta);
        //            results.add(new meta(filename, getZonedTimeFromStr(captureDate), dateFormat, model, note, dID, odID));
    }
    return results;
}

From source file:XmlHelper.java

/**
 * Returns an iterator over the children of the given element with the given
 * tag name.//from   w  ww  . j  a va 2s.  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:com.android.launcher4.InstallShortcutReceiver.java

static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp);
    if (!installQueue.isEmpty()) {
        Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
        ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
        int result = INSTALL_SHORTCUT_SUCCESSFUL;
        String duplicateName = "";
        while (iter.hasNext()) {
            final PendingInstallShortcutInfo pendingInfo = iter.next();
            //final Intent data = pendingInfo.data;
            final Intent intent = pendingInfo.launchIntent;
            final String name = pendingInfo.name;

            if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) {
                if (DBG)
                    Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
                continue;
            }//from   ww  w.  j  a v  a 2 s .  c  om

            final boolean exists = LauncherModel.shortcutExists(context, name, intent);
            //final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

            // If the intent specifies a package, make sure the package exists
            String packageName = intent.getPackage();
            if (packageName == null) {
                packageName = intent.getComponent() == null ? null : intent.getComponent().getPackageName();
            }
            if (packageName != null && !packageName.isEmpty()) {
                UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
                if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) {
                    if (DBG)
                        Log.d(TAG, "Ignoring shortcut for absent package:" + intent);
                    continue;
                }
            }

            if (!exists) {
                // Generate a shortcut info to add into the model
                ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, pendingInfo.launchIntent);
                addShortcuts.add(info);
            }

        }

        // Notify the user once if we weren't able to place any duplicates
        if (result == INSTALL_SHORTCUT_IS_DUPLICATE) {
            Toast.makeText(context, context.getString(R.string.shortcut_duplicate, duplicateName),
                    Toast.LENGTH_SHORT).show();
        }

        // Add the new apps to the model and bind them
        if (!addShortcuts.isEmpty()) {
            LauncherAppState app = LauncherAppState.getInstance();
            app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts);
        }
    }
}

From source file:de.rrze.idmone.utils.jidgen.template.Parser.java

/**
 * Processes the given template string by splitting it into its
 * parts and parse each part to compile a list of according 
 * element objects.<br/>// w  w w  .j a  v a2  s.  c  om
 * Those are used by the template class to finally build the
 * result string.
 * 
 * @param template
 *          the template string to process
 * @return   a list of elements representing the element parts inside
 *          the template string
 */
public static ArrayList<IElement> getElements(String template) {

    // reset the hasCounter flag
    hasCounterElement = false;

    // init elements array
    ArrayList<IElement> elements = new ArrayList<IElement>();

    // split into parts (which later become elements)
    ArrayList<String> parts = new ArrayList<String>(Arrays.asList(template.split(ELEMENT_DELIMITER)));
    //logger.debug(parts.toString());

    boolean isResolver;

    // process the parts - here starts the fun ;)
    for (Iterator<String> iter = parts.iterator(); iter.hasNext();) {
        String currentPart = iter.next();

        /*
         * ALTERNATIVE / RESOLVER 
         */
        Matcher m = getMatcher("^\\[(.*)\\]$", currentPart);
        if (m.matches()) {
            logger.debug(
                    Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => ALTERNATIVE/RESOLVER");
            isResolver = true;
            currentPart = m.group(1);
        } else {
            isResolver = false;
        }

        // parse and get the element instance
        IElement element = Parser.parse(currentPart);

        // set the resolver status
        element.setResolver(isResolver);

        // add the element
        elements.add(element);
    }

    return elements;
}