Example usage for java.util List iterator

List of usage examples for java.util List iterator

Introduction

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

Prototype

Iterator<E> iterator();

Source Link

Document

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

Usage

From source file:Main.java

public static boolean isServiceRunning(Context ctx, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List servicesList = activityManager.getRunningServices(2147483647);
    Iterator l = servicesList.iterator();
    while (l.hasNext()) {
        ActivityManager.RunningServiceInfo si = (ActivityManager.RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;/*from ww w. ja va 2s . co  m*/
        }
    }
    return isRunning;
}

From source file:Main.java

public static List getDifferenceOfTwoList(List originList, List targetList) {
    List diff = new ArrayList();
    for (Iterator it = originList.iterator(); it.hasNext();) {
        Object obj = it.next();/*from  w w  w  . jav  a2 s . co m*/
        if (!targetList.contains(obj)) {
            diff.add(obj);
        }
    }
    return diff;
}

From source file:Main.java

public static void printListThroughIterator(List list, String logTag) {
    StringBuilder sb = new StringBuilder();
    for (Iterator iter = list.iterator(); iter.hasNext();) {
        sb.append(iter.next() + " ");
    }//from ww  w  .j  ava2 s.  c  o  m

    System.out.println(logTag + " " + "printListThroughRandomAccess::" + sb.toString());
}

From source file:com.era7.bioinfo.blastxviewer7.server.util.FileUploadUtilities.java

public static FileItem getFileItem(HttpServletRequest httpRequest) throws FileUploadException {
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List items = upload.parseRequest(httpRequest);
    Iterator iter = items.iterator();
    FileItem item = null;/* w  w  w  . j  av  a  2  s.c o m*/
    while (iter.hasNext()) {
        item = (FileItem) iter.next();
        if (!item.isFormField()) {
            return item;
        }
    }
    return item;
}

From source file:Main.java

/**
 * Note: This method makes an in-memory copy of the elements.
 * This can be inefficient for large lists.
 *//*from  ww w .  java  2s .c o  m*/
public static <T> Iterator<T> reverse(Iterator<T> it) {
    List<T> list = Lists.newArrayList(it);
    Collections.reverse(list);
    return list.iterator();
}

From source file:Main.java

/**
 * Get Process Name by getRunningAppProcesses
 * <p/>/*from w ww.j ava  2  s.co  m*/
 * It's been reported that sometimes, the list returned from
 * getRunningAppProcesses simply doesn't contain your own process
 * (especially when called from Application).
 * Use {@link #getProcessName(Context, int)} instead
 */
public static String getProcessName_PM(Context context, int pID) {
    String processName = "";
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = context.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                return info.processName;
            }
        } catch (Exception e) {
            Log.e(TAG, "getAppName: error", e);
        }
    }
    return processName;
}

From source file:Main.java

/** Removes from given list the first element that matches given predicate. 
 * @return true if an element was removed, false otherwise. */
public static <E> boolean removeElement(List<? extends E> list, Predicate<E> predicate) {
    for (Iterator<? extends E> iter = list.iterator(); iter.hasNext();) {
        E obj = iter.next();// w  w w  .  jav a 2 s. c  om
        if (predicate.test(obj)) {
            iter.remove();
            return true;
        }
    }
    return false;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static void filtrerDoublonsSurPlace(List objets) {
    Map objetsDejaPresents = new HashMap();
    for (Iterator i = objets.iterator(); i.hasNext();) {
        Object objet = i.next();//from  ww w.  jav a 2  s . c o  m
        if (!objetsDejaPresents.containsKey(objet))
            objetsDejaPresents.put(objet, null);
        else
            i.remove();
    }
}

From source file:Main.java

private static void setSizes(java.util.List<JComponent> aComponents, Dimension aDimension) {
    Iterator<JComponent> compsIter = aComponents.iterator();
    while (compsIter.hasNext()) {
        JComponent comp = (JComponent) compsIter.next();
        comp.setPreferredSize((Dimension) aDimension.clone());
        comp.setMaximumSize((Dimension) aDimension.clone());
    }/*from  ww  w .  j  ava 2s. co  m*/
}

From source file:Main.java

public static Map getIndexMap(List list) {
    Map indexes = new HashMap();
    int index = 0;
    for (Iterator it = list.iterator(); it.hasNext();) {
        indexes.put(it.next(), new Integer(index++));
    }/*from  ww  w  .  ja v  a  2s  .co  m*/
    return indexes;
}