List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:Main.java
static String tocsv(Iterable<String> set) { Iterator<String> iter = set.iterator(); StringBuffer buf = new StringBuffer(); if (iter.hasNext()) { buf.append(iter.next());/*from w w w . j a v a 2 s. c om*/ } while (iter.hasNext()) { buf.append(","); buf.append(iter.next()); } return buf.toString(); }
From source file:Main.java
/** * Get the first element of a an {@link Iterable} in iteration order, or null if empty. * * @param <T> the type//from w w w. j a va 2 s .co m * @param iterable the thing to get something from. * @return the first thing the iterator spits out. May */ public static <T> T first(@Nonnull final Iterable<? extends T> iterable) { final Iterator<? extends T> iterator = iterable.iterator(); return (iterator.hasNext()) ? iterator.next() : null; }
From source file:Main.java
public static boolean isNotEmpty(@Nullable final Iterable<?> aCont) { return aCont != null && aCont.iterator().hasNext(); }
From source file:Main.java
public static boolean isEmpty(@Nullable final Iterable<?> aCont) { return aCont == null || !aCont.iterator().hasNext(); }
From source file:Main.java
/** * Adds all of the items from a given {@code Iterable} into a * {@code Collection}./*ww w . j av a2 s . c om*/ * * @param <T> * the element type of the given {@code Iterable} and * {@code Collection} * @param <C> * the type of the given {@code Collection} * @param c * the {@code Collection} to add items to * @param i * the {@code Iterable} to take items from * @return {@code c} */ public static <T, C extends Collection<T>> C fillFromIterable(C c, Iterable<T> i) { return fillFromIterator(c, i.iterator()); }
From source file:Main.java
/** * Appends the contents of an iterable object to the passed collection. *///from w ww.j a v a 2 s . com public static <T> void addAll(Collection<T> coll, Iterable<T> src) { addAll(coll, src.iterator()); }
From source file:Main.java
public static <T> Set<T> toSet(final Iterable<T> iterable) { final Set<T> set = new TreeSet<T>(); for (Iterator<T> i = iterable.iterator(); i.hasNext();) { set.add(i.next());/*from www . ja v a2s. c o m*/ } return set; }
From source file:Main.java
public static String join(Iterable<? extends CharSequence> s, String delimiter) { Iterator<? extends CharSequence> iter = s.iterator(); if (!iter.hasNext()) return ""; StringBuilder buffer = new StringBuilder(iter.next()); while (iter.hasNext()) buffer.append(delimiter).append(iter.next()); return buffer.toString(); }
From source file:Main.java
public static <T> Iterable<T> openIntervalIterable(Iterable<T> iterable, T start, T end) { return () -> openIntervalIterator(iterable.iterator(), start, end); }
From source file:edu.byu.nlp.util.Counters.java
public static <E> Counter<E> count(Iterable<E> it) { return count(it.iterator()); }