List of utility methods to do Iterable
boolean | isEmpty(Iterable is Empty return !i.iterator().hasNext();
|
Iterable | iterable(final Iterable iterable return new Iterable<T>() { @Override public Iterator<T> iterator() { return in.iterator(); }; |
double | max(Iterable max Iterator<Double> iterator = iterable.iterator(); double max = Double.MIN_VALUE; while (iterator.hasNext()) { double d = iterator.next(); if (d > max) { max = d; return max; |
Iterable | mergeConsecutiveTokens(Iterable merge Consecutive Tokens return new Iterable<String>() { @Override public Iterator<String> iterator() { final Iterator<String> token_iter = tokens.iterator(); return new Iterator<String>() { Iterator<String> iter = token_iter; String _last_token = null; String _token; ... |
String | prettyPrintComma(Iterable a) pretty Print Comma String res = ""; if (a == null) { return res; Iterator<Object> it = a.iterator(); if (it.hasNext()) { res += it.next(); while (it.hasNext()) { res += ","; res += it.next(); return res; |
DataType | removeElement(final Iterable Removes and returns the indexed value into the Iterable . if (iterable instanceof List<?>) { return ((List<DataType>) iterable).remove(index); } else { if (index < 0) { throw new IndexOutOfBoundsException("index must be >= 0"); Iterator<DataType> iterator = iterable.iterator(); while (iterator.hasNext()) { ... |
boolean | removeIgnoreCase(Iterable Remove the first occurrence of needle (ignoring case)
Iterator<String> iterator = haystack.iterator(); while (iterator.hasNext()) { String string = iterator.next(); if (needle.equalsIgnoreCase(string)) { iterator.remove(); return true; return false; |
T | secondOf(final Iterable second Of return nthOf(iterable, 1);
|
boolean | sequenceEqual(Iterable Compares two sequences of values and returns true if sequence members are equal and in the same order Iterator<T> iter1 = one.iterator(); Iterator<T> iter2 = two.iterator(); while (iter1.hasNext() && iter2.hasNext()) { if (iter1.next() != iter2.next()) { return false; return (!iter1.hasNext() && !iter2.hasNext()); ... |
List | shallowCopy(Iterable Generates a new Iterable that references the items of the given Iterable . ArrayList<T> copy = new ArrayList<T>(); for (T t : ori) { copy.add(t); return copy; |