List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:Main.java
/** * Returns an iterable as an enumeration (some older library code excepts * these)//from ww w. j a v a 2 s. c o m * @param iterable the iterable * @return an enumeration returning the same sequence of elements as the * parameter iterable * @precondition iterable != null * @postcondition result != null */ public static <T> Enumeration<T> asEnumeration(final Iterable<T> iterable) { final Iterator<T> it = iterable.iterator(); return new Enumeration<T>() { @Override public boolean hasMoreElements() { return it.hasNext(); } @Override public T nextElement() { return it.next(); } }; }
From source file:Main.java
public static <T> T getFirst(Iterable<? extends T> iterable, T def) { final Iterator<? extends T> iter = iterable.iterator(); return iter.hasNext() ? iter.next() : def; }
From source file:Main.java
public static <ELEM, COLL extends Collection<? super ELEM>> COLL addAll2(COLL dest, Iterable<? extends ELEM> source) { return addAllFromIterator(dest, source.iterator()); }
From source file:Main.java
public static boolean isNullOrEmpty(final Iterable<?> iterable) { return (iterable == null) || (!iterable.iterator().hasNext()); }
From source file:Main.java
/** * Setzt die Daten des Iterables in das ComboBoxModel. * /*from ww w. j av a 2s . c om*/ * @param comboBox {@link JComboBox} * @param iterable {@link Iterable} */ public static void fillComboBox(final JComboBox<?> comboBox, final Iterable<?> iterable) { fillComboBox(comboBox, iterable.iterator()); }
From source file:Main.java
public static <T> T removeFrom(Iterable<T> collection, Predicate<T> predicate) { Iterator<T> it = collection.iterator(); while (it.hasNext()) { T o = it.next();/*w ww.j ava 2 s . c o m*/ if (predicate.test(o)) { it.remove(); return o; } } return null; }
From source file:Main.java
public static <T> Iterator<T> safeIterator(Iterable<T> iterable) { return iterable == null ? Collections.<T>emptyList().iterator() : iterable.iterator(); }
From source file:Main.java
public static <T, Tout> List<Tout> select(Iterable<T> source, Function<T, Tout> action) { if (source == null || !source.iterator().hasNext()) return Collections.emptyList(); List<Tout> result = new ArrayList<Tout>(); for (T item : source) { result.add(action.apply(item));/*from w w w . j a v a2 s . c o m*/ } return result; }
From source file:Main.java
public static <T> T getByIndex(Iterable<T> iterable, int index) { T el = null;// w ww . j a v a 2 s. c om Iterator<T> it = iterable.iterator(); for (int i = 0; it.hasNext(); i++) { T cur = it.next(); if (i == index) { el = cur; break; } } return el; }
From source file:Main.java
public static final <T> List<T> collect(Iterable<? extends T> it, Comparator<? super T> cmp) { return collect(it.iterator(), cmp); }