List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
public static Map<String, Boolean> parseBooleanJsonMap(JSONObject object) throws JSONException { Map<String, Boolean> map = new ArrayMap<String, Boolean>(); Iterator<String> keys = object.keys(); while (keys.hasNext()) { String key = keys.next(); map.put(key, object.getBoolean(key)); }// ww w. j av a 2 s .c o m return map; }
From source file:Main.java
public static <ELEM, COLL extends Collection<? super ELEM>> COLL addAllFromIterator(COLL dest, Iterator<? extends ELEM> source) { while (source.hasNext()) { dest.add(source.next());/*from w ww .ja v a 2 s . com*/ } return dest; }
From source file:Main.java
/** @return whether given coll contains all elements of other, using a naive/basic algorithm. */ public static boolean containsAll(Collection<?> coll, Collection<?> other) { Iterator<?> citer = other.iterator(); while (citer.hasNext()) if (!coll.contains(citer.next())) return false; return true;// w w w . jav a 2 s .c o m }
From source file:Main.java
public static Object keyString(HashMap<String, String> map, String o) { Iterator<String> it = map.keySet().iterator(); while (it.hasNext()) { Object keyString = it.next(); if (map.get(keyString).equals(o)) return keyString; }/*from w w w. j av a2s. co m*/ return null; }
From source file:Main.java
private static String buildQueryString(String method, Map<String, String> args) { String qry = buildQueryString(method); Iterator it = args.entrySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String val = args.get(key); qry = qry.concat("?").concat(key).concat("=").concat(val); }/*from ww w. j a v a 2 s . c o m*/ return qry; }
From source file:CollectionAll.java
static void traverse(Collection coll) { Iterator iter = coll.iterator(); while (iter.hasNext()) { String elem = (String) iter.next(); System.out.print(elem + " "); }/*w ww .ja v a2 s. co m*/ System.out.println(); }
From source file:Main.java
public static <E> boolean isEmpty(Collection<E> collection) { if (collection == null || collection.isEmpty()) { return true; }/*from w w w .j a v a 2 s . c o m*/ Iterator<E> it = collection.iterator(); while (it.hasNext()) { E type = (E) it.next(); if (type != null) { return false; } } return true; }
From source file:Main.java
public static <E> boolean contains(Collection<E> c, E item, BiPredicate<? super E, ? super E> equalTester) { Iterator<E> iter = c.iterator(); while (iter.hasNext()) { if (equalTester.test(iter.next(), item)) { return true; }//w w w .j av a 2 s .c om } return false; }
From source file:Main.java
/** * Removes nulls from provided collection. * //from w w w . j a v a 2s . c om * @param c * to remove nulls from * @return number of removed elements */ @SuppressWarnings("rawtypes") public static int removeNulls(Collection c) { int removed = 0; Iterator iterator = c.iterator(); while (iterator.hasNext()) { if (iterator.next() == null) { iterator.remove(); removed++; } } return removed; }
From source file:Main.java
public static boolean remove(Collection collection, Object object) { boolean removed = false; Iterator it = collection.iterator(); while (it.hasNext()) { Object o = it.next();/*from www .j a va 2 s .c o m*/ if (o.equals(object)) { removed = true; it.remove(); break; } } return removed; }