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 context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;/*from   w w  w .  j  av  a  2s.  co  m*/
        }
    }
    return isRunning;
}

From source file:com.amalto.core.storage.hibernate.ListBridge.java

private static String getValueFromObject(List object) {
    if (object == null) {
        return StringUtils.EMPTY;
    }//  w  w  w . j av  a 2s  .  c  o  m
    Iterator valuesIterator = object.iterator();
    StringBuilder builder = new StringBuilder();
    while (valuesIterator.hasNext()) {
        builder.append(String.valueOf(valuesIterator.next()));
        if (valuesIterator.hasNext()) {
            builder.append(' ');
        }
    }
    return builder.toString();
}

From source file:JDOMDemo.java

public static void demo(Element element) {
    System.out.println("Element " + element);

    List attributes = element.getAttributes();
    List children = element.getContent();
    Iterator iterator = children.iterator();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        if (o instanceof Element) {
            demo((Element) o);//from  w  ww  . j a v a 2s  . com
        } else if (o instanceof Comment)
            doComment((Comment) o);
        else if (o instanceof ProcessingInstruction)
            doPI((ProcessingInstruction) o);
        else if (o instanceof String) {
            System.out.println("String: " + o);
        }
    }
}

From source file:Main.java

public static List<Integer> checkIdentical(List<Integer> list1, List<Integer> list2) {
    List<Integer> resultList = new ArrayList<Integer>();

    Iterator<Integer> iterator1 = list1.iterator();
    while (iterator1.hasNext()) {
        Integer next1 = iterator1.next();
        Iterator<Integer> iterator2 = list2.iterator();
        while (iterator2.hasNext()) {
            Integer next2 = iterator2.next();
            if (next1.intValue() == next2.intValue()) {
                iterator1.remove();//ww w . j  a v a  2s .  co  m
                iterator2.remove();
                resultList.add(next1.intValue());
                break;
            }
        }
    }

    return resultList;
}

From source file:Main.java

protected static String printRequestParameters(List<NameValuePair> parameterList) {
    StringBuilder stringBuilder = new StringBuilder();
    Iterator<NameValuePair> nameValueIterator = parameterList.iterator();

    while (nameValueIterator.hasNext()) {
        NameValuePair pair = nameValueIterator.next();
        stringBuilder.append(pair.getName() + "=" + pair.getValue() + "||");
    }/* w w w.  j a v  a2 s.c  o m*/

    return stringBuilder.toString();
}

From source file:Main.java

public static <T> Iterator<T> dump(Iterator<T> it) {
    List<T> list = new ArrayList<T>();
    while (it.hasNext()) {
        list.add(it.next());/*from ww  w.j  a  va 2s.  com*/
    }

    System.out.println(list);
    return list.iterator();
}

From source file:Main.java

public static void startAppByPackageName(Context context, String packageName) {
    PackageInfo pi = null;//w w  w . j  av a 2 s .co  m
    try {
        pi = context.getPackageManager().getPackageInfo(packageName, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(pi.packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo ri = apps.iterator().next();
    if (ri != null) {
        String packageName1 = ri.activityInfo.packageName;
        String className = ri.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        ComponentName cn = new ComponentName(packageName1, className);

        intent.setComponent(cn);
        context.startActivity(intent);
    }

}

From source file:Main.java

public static List<ByteBuffer> mergeAdjacentBuffers(List<ByteBuffer> paramList) {
    ArrayList localArrayList = new ArrayList(paramList.size());
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext()) {
        ByteBuffer localByteBuffer1 = (ByteBuffer) localIterator.next();
        int i = -1 + localArrayList.size();
        if ((i >= 0) && (localByteBuffer1.hasArray()) && (((ByteBuffer) localArrayList.get(i)).hasArray())
                && (localByteBuffer1.array() == ((ByteBuffer) localArrayList.get(i)).array())
                && (((ByteBuffer) localArrayList.get(i)).arrayOffset()
                        + ((ByteBuffer) localArrayList.get(i)).limit() == localByteBuffer1.arrayOffset())) {
            ByteBuffer localByteBuffer3 = (ByteBuffer) localArrayList.remove(i);
            localArrayList.add(ByteBuffer.wrap(localByteBuffer1.array(), localByteBuffer3.arrayOffset(),
                    localByteBuffer3.limit() + localByteBuffer1.limit()).slice());
        } else if ((i >= 0) && ((localByteBuffer1 instanceof MappedByteBuffer))
                && ((localArrayList.get(i) instanceof MappedByteBuffer))
                && (((ByteBuffer) localArrayList.get(i))
                        .limit() == ((ByteBuffer) localArrayList.get(i)).capacity()
                                - localByteBuffer1.capacity())) {
            ByteBuffer localByteBuffer2 = (ByteBuffer) localArrayList.get(i);
            localByteBuffer2.limit(localByteBuffer1.limit() + localByteBuffer2.limit());
        } else {//  ww  w . j a  va 2s  . c  o  m
            localByteBuffer1.reset();
            localArrayList.add(localByteBuffer1);
        }
    }
    return localArrayList;
}

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<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        String serName = si.service.getClassName();
        Log.d("isServiceRunning", serName);
        if (className.equals(serName)) {
            isRunning = true;/*from   w w  w  .j a  v  a 2  s.c o  m*/
        }
    }
    return isRunning;
}

From source file:Main.java

public static int hashCode(List list) {
    if (list == null) {
        return 0;
    }/*from  w ww. jav a 2  s .  co  m*/

    final int prime = 31;
    int result = 1;
    for (Iterator it = list.iterator(); it.hasNext();) {
        result = prime * result + it.next().hashCode();
    }
    return result;
}