List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
public static void clearTempDirectory() { // Abandon if we created no files in this session if (tempFileList.size() == 0) return;//w w w. j a v a 2 s. c o m Iterator i = tempFileList.iterator(); while (i.hasNext()) { try { File f = new File((String) i.next()); f.delete(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:Main.java
public static <T> T first(Collection<T> list) { Iterator<T> iterator = list.iterator(); if (iterator.hasNext()) { return iterator.next(); }/* w ww . j av a 2 s . com*/ return null; }
From source file:Main.java
public static <T> String join(Iterable<T> iterable, String d) { Iterator it = iterable.iterator(); if (!it.hasNext()) { return ""; }/*from w ww.ja v a2 s . c o m*/ StringBuilder sb = new StringBuilder(); String prefix = ""; while (it.hasNext()) { sb.append(prefix); prefix = d; sb.append(it.next()); } return sb.toString(); }
From source file:Main.java
public static String toPathString(Iterable<File> files, String separator) { final StringBuilder builder = new StringBuilder(); final Iterator<File> fileIt = files.iterator(); while (fileIt.hasNext()) { builder.append(fileIt.next().getAbsolutePath()); if (fileIt.hasNext()) { builder.append(separator);//from ww w . j ava2 s .c o m } } return builder.toString(); }
From source file:Main.java
public static String getReqPama(Map<String, String> params) { StringBuffer sBuffer = new StringBuffer(); Iterator<?> iterator = params.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); sBuffer.append(key + "=" + params.get(key) + "&"); }/* www. j a v a 2 s . co m*/ String reqString = sBuffer.toString(); return reqString.substring(0, reqString.length() - 1); }
From source file:Main.java
/** * an alternative which returns slightly more granular info than boolean pass/fail. * @return the number of add operations which "succeed" (modify the collection) * @see Collection#addAll(Collection)//from w w w . ja va2s .c om */ public static <E> int addAll(Collection<E> collection, Iterator<? extends E> add) { int retVal = 0; while (add.hasNext()) if (collection.add(add.next())) ++retVal; return retVal; }
From source file:Main.java
public static boolean iteratesEqualSequence(Iterator<?> iter1, Iterator<?> iter2) { while (iter1.hasNext()) { if (!iter2.hasNext()) return false; Object o1 = iter1.next(); Object o2 = iter2.next(); if (!o1.equals(o2)) return false; }// ww w . j a v a 2s . c o m if (iter2.hasNext()) return false; return true; }
From source file:Main.java
public static String join(Collection<?> input, String sep) { if (input == null || input.size() == 0) { return ""; }/*ww w. ja v a2s .co m*/ StringBuilder sb = new StringBuilder(); int index = 0; int size = input.size(); Iterator<?> it = input.iterator(); while (it.hasNext()) { if (index == size - 1) { break; } Object o = it.next(); sb.append(o).append(sep); index++; } sb.append(it.next()); return sb.toString(); }
From source file:Main.java
/** * Returns the number of occurrences of <i>obj</i> in <i>col</i>. *///ww w.j a v a 2 s .c o m public static int cardinality(Object obj, final Collection col) { int count = 0; Iterator it = col.iterator(); while (it.hasNext()) { Object elt = it.next(); if ((null == obj && null == elt) || obj.equals(elt)) { count++; } } return count; }
From source file:Main.java
public static String toString(Iterable<?> it, String separator) { final StringBuilder builder = new StringBuilder(); final Iterator<?> iterator = it.iterator(); while (iterator.hasNext()) { builder.append(iterator.next().toString()); if (iterator.hasNext()) { builder.append(separator);/* w w w .j a v a 2 s .c om*/ } } return builder.toString(); }