public final class Iterators extends Object
This is a utility class mostly for Iterator.
The methods in this class should only read the input Collection/Array/Iterator parameters, not modify them.
N,
Iterables,
Maps,
StringUtil| Modifier and Type | Method and Description |
|---|---|
static long |
advance(Iterator<?> iterator,
long numberToAdvance)
Note: copied from Google Guava under Apache license v2
Calls next() on iterator, either numberToAdvance times
or until hasNext() returns false, whichever comes first. |
static <A,B> BiIterator<A,B> |
concat(BiIterator<A,B>... a) |
static <T> ObjIterator<T> |
concat(Collection<? extends Iterator<? extends T>> c) |
static <T> ObjIterator<T> |
concat(Collection<? extends T>... a) |
static <T> ObjIterator<T> |
concat(Iterator<? extends T>... a) |
static <K,V> ObjIterator<Map.Entry<K,V>> |
concat(Map<? extends K,? extends V>... a) |
static <T> ObjIterator<T> |
concat(T[]... a) |
static <T> ObjIterator<T> |
concatt(Collection<? extends Collection<? extends T>> c) |
static long |
count(Iterator<?> iter) |
static <T,E extends Exception> |
count(Iterator<? extends T> iter,
Throwables.Predicate<? super T,E> filter) |
static <T> ObjIterator<T> |
distinct(Iterator<? extends T> iter) |
static <T> ObjIterator<T> |
distinctBy(Iterator<? extends T> iter,
Function<? super T,?> keyMapper) |
static <T> ObjIterator<T> |
dropWhile(Iterator<? extends T> iter,
Predicate<? super T> filter) |
static <T> ObjIterator<T> |
filter(Iterator<? extends T> iter,
Predicate<? super T> filter) |
static <T,U> ObjIterator<U> |
flatMap(Iterator<? extends T> iter,
Function<? super T,? extends Collection<? extends U>> mapper) |
static <T,U> ObjIterator<U> |
flattMap(Iterator<? extends T> iter,
Function<? super T,? extends U[]> mapper) |
static <T,U> ObjIterator<T> |
generate(U init,
BiPredicate<? super U,T> hasNext,
BiFunction<? super U,T,T> supplier) |
static <T,U> ObjIterator<T> |
generate(U init,
Predicate<? super U> hasNext,
Function<? super U,T> supplier) |
static <T> u.Nullable<T> |
get(Iterator<? extends T> iter,
long index) |
static <T> ObjIterator<T> |
limit(Iterator<? extends T> iter,
long count)
Returns a new
Iterator. |
static <T,U> ObjIterator<U> |
map(Iterator<? extends T> iter,
Function<? super T,U> mapper) |
static <T> ObjIterator<T> |
merge(Collection<? extends Iterator<? extends T>> c,
BiFunction<? super T,? super T,MergeResult> nextSelector) |
static <T> ObjIterator<T> |
merge(Collection<? extends T> a,
Collection<? extends T> b,
BiFunction<? super T,? super T,MergeResult> nextSelector) |
static <T> ObjIterator<T> |
merge(Iterator<? extends T> a,
Iterator<? extends T> b,
BiFunction<? super T,? super T,MergeResult> nextSelector) |
static <T> ObjIterator<T> |
merge(List<? extends Collection<? extends T>> c,
BiFunction<? super T,? super T,MergeResult> nextSelector) |
static <T extends Comparable> |
mergeSorted(Collection<? extends T> a,
Collection<? extends T> b) |
static <T> ObjIterator<T> |
mergeSorted(Collection<? extends T> a,
Collection<? extends T> b,
Comparator<? super T> cmp) |
static <T extends Comparable> |
mergeSorted(Iterator<? extends T> a,
Iterator<? extends T> b) |
static <T> ObjIterator<T> |
mergeSorted(Iterator<? extends T> a,
Iterator<? extends T> b,
Comparator<? super T> cmp) |
static <T> ObjIterator<T> |
mergge(Collection<? extends Collection<? extends T>> c,
BiFunction<? super T,? super T,MergeResult> nextSelector) |
static <T> ObjIterator<T> |
repeat(T e,
int n) |
static <T> ObjIterator<T> |
repeatAll(Collection<? extends T> c,
int n) |
static <T> ObjIterator<T> |
repeatAllToSize(Collection<? extends T> c,
int size)
Repeat all to size.
|
static <T> ObjIterator<T> |
repeatEach(Collection<? extends T> c,
int n) |
static <T> ObjIterator<T> |
repeatEachToSize(Collection<? extends T> c,
int size)
Repeat each to size.
|
static <T> ObjIterator<T> |
skip(Iterator<? extends T> iter,
long n)
Calls
next() on iterator, either n times
or until hasNext() returns false, whichever comes first. |
static <T> ObjIterator<T> |
skipAndLimit(Iterator<? extends T> iter,
long offset,
long count)
Calls
next() on iterator, either offset times
or until hasNext() returns false, whichever comes first. |
static <T> ObjIterator<T> |
skipNull(Iterator<? extends T> iter)
Returns a new
ObjIterator with null elements removed. |
static <T> ObjIterator<T> |
skipUntil(Iterator<? extends T> iter,
Predicate<? super T> filter) |
static <T> ObjIterator<T> |
takeWhile(Iterator<? extends T> iter,
Predicate<? super T> filter) |
static <T> ObjIterator<T> |
takeWhileInclusive(Iterator<? extends T> iter,
Predicate<? super T> filter) |
static <T,L,R> BiIterator<L,R> |
unzip(Collection<? extends T> c,
BiConsumer<? super T,Pair<L,R>> unzip) |
static <T,L,R> BiIterator<L,R> |
unzip(Iterator<? extends T> iter,
BiConsumer<? super T,Pair<L,R>> unzip) |
static <A,B,R> ObjIterator<R> |
zip(Collection<A> a,
Collection<B> b,
A valueForNoneA,
B valueForNoneB,
BiFunction<? super A,? super B,R> zipFunction) |
static <A,B,R> ObjIterator<R> |
zip(Collection<A> a,
Collection<B> b,
BiFunction<? super A,? super B,R> zipFunction) |
static <A,B,C,R> ObjIterator<R> |
zip(Collection<A> a,
Collection<B> b,
Collection<C> c,
A valueForNoneA,
B valueForNoneB,
C valueForNoneC,
TriFunction<? super A,? super B,? super C,R> zipFunction) |
static <A,B,C,R> ObjIterator<R> |
zip(Collection<A> a,
Collection<B> b,
Collection<C> c,
TriFunction<? super A,? super B,? super C,R> zipFunction) |
static <A,B,R> ObjIterator<R> |
zip(Iterator<A> a,
Iterator<B> b,
A valueForNoneA,
B valueForNoneB,
BiFunction<? super A,? super B,R> zipFunction) |
static <A,B,R> ObjIterator<R> |
zip(Iterator<A> a,
Iterator<B> b,
BiFunction<? super A,? super B,R> zipFunction) |
static <A,B,C,R> ObjIterator<R> |
zip(Iterator<A> a,
Iterator<B> b,
Iterator<C> c,
A valueForNoneA,
B valueForNoneB,
C valueForNoneC,
TriFunction<? super A,? super B,? super C,R> zipFunction) |
static <A,B,C,R> ObjIterator<R> |
zip(Iterator<A> a,
Iterator<B> b,
Iterator<C> c,
TriFunction<? super A,? super B,? super C,R> zipFunction) |
public static <T> u.Nullable<T> get(Iterator<? extends T> iter, long index)
T - iter - index - public static long count(Iterator<?> iter)
iter - public static <T,E extends Exception> long count(Iterator<? extends T> iter, Throwables.Predicate<? super T,E> filter) throws E extends Exception
iter - filter - E extends Exceptionpublic static <T> ObjIterator<T> repeat(T e, int n)
T - e - n - public static <T> ObjIterator<T> repeatEach(Collection<? extends T> c, int n)
T - c - n - public static <T> ObjIterator<T> repeatAll(Collection<? extends T> c, int n)
T - c - n - public static <T> ObjIterator<T> repeatEachToSize(Collection<? extends T> c, int size)
T - c - size - public static <T> ObjIterator<T> repeatAllToSize(Collection<? extends T> c, int size)
T - c - size - @SafeVarargs public static <T> ObjIterator<T> concat(T[]... a)
T - a - @SafeVarargs public static <T> ObjIterator<T> concat(Collection<? extends T>... a)
T - a - @SafeVarargs public static <K,V> ObjIterator<Map.Entry<K,V>> concat(Map<? extends K,? extends V>... a)
T - a - public static <T> ObjIterator<T> concatt(Collection<? extends Collection<? extends T>> c)
T - c - @SafeVarargs public static <T> ObjIterator<T> concat(Iterator<? extends T>... a)
T - a - public static <T> ObjIterator<T> concat(Collection<? extends Iterator<? extends T>> c)
T - c - @SafeVarargs public static <A,B> BiIterator<A,B> concat(BiIterator<A,B>... a)
A - B - a - public static <T> ObjIterator<T> merge(Collection<? extends T> a, Collection<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
T - a - b - nextSelector - public static <T> ObjIterator<T> merge(Iterator<? extends T> a, Iterator<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
T - a - b - nextSelector - public static <T> ObjIterator<T> merge(List<? extends Collection<? extends T>> c, BiFunction<? super T,? super T,MergeResult> nextSelector)
public static <T> ObjIterator<T> mergge(Collection<? extends Collection<? extends T>> c, BiFunction<? super T,? super T,MergeResult> nextSelector)
public static <T> ObjIterator<T> merge(Collection<? extends Iterator<? extends T>> c, BiFunction<? super T,? super T,MergeResult> nextSelector)
c - nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.public static <T extends Comparable> ObjIterator<T> mergeSorted(Collection<? extends T> a, Collection<? extends T> b)
T - a - should be in non-descending order as this method does not sort its input.b - should be in non-descending order as this method does not sort its input.public static <T> ObjIterator<T> mergeSorted(Collection<? extends T> a, Collection<? extends T> b, Comparator<? super T> cmp)
T - a - should be in non-descending order as this method does not sort its input.b - should be in non-descending order as this method does not sort its input.cmp - public static <T extends Comparable> ObjIterator<T> mergeSorted(Iterator<? extends T> a, Iterator<? extends T> b)
T - a - should be in non-descending order as this method does not sort its input.b - should be in non-descending order as this method does not sort its input.public static <T> ObjIterator<T> mergeSorted(Iterator<? extends T> a, Iterator<? extends T> b, Comparator<? super T> cmp)
T - a - should be in non-descending order as this method does not sort its input.b - should be in non-descending order as this method does not sort its input.cmp - public static <A,B,R> ObjIterator<R> zip(Collection<A> a, Collection<B> b, BiFunction<? super A,? super B,R> zipFunction)
A - B - R - a - b - zipFunction - public static <A,B,R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, BiFunction<? super A,? super B,R> zipFunction)
A - B - R - a - b - zipFunction - public static <A,B,C,R> ObjIterator<R> zip(Collection<A> a, Collection<B> b, Collection<C> c, TriFunction<? super A,? super B,? super C,R> zipFunction)
A - B - C - R - a - b - c - zipFunction - public static <A,B,C,R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, Iterator<C> c, TriFunction<? super A,? super B,? super C,R> zipFunction)
A - B - C - R - a - b - c - zipFunction - public static <A,B,R> ObjIterator<R> zip(Collection<A> a, Collection<B> b, A valueForNoneA, B valueForNoneB, BiFunction<? super A,? super B,R> zipFunction)
A - B - R - a - b - valueForNoneA - valueForNoneB - zipFunction - public static <A,B,R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, A valueForNoneA, B valueForNoneB, BiFunction<? super A,? super B,R> zipFunction)
A - B - R - a - b - valueForNoneA - valueForNoneB - zipFunction - public static <A,B,C,R> ObjIterator<R> zip(Collection<A> a, Collection<B> b, Collection<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, TriFunction<? super A,? super B,? super C,R> zipFunction)
A - B - C - R - a - b - c - valueForNoneA - valueForNoneB - valueForNoneC - zipFunction - public static <A,B,C,R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, Iterator<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, TriFunction<? super A,? super B,? super C,R> zipFunction)
A - B - C - R - a - b - c - valueForNoneA - valueForNoneB - valueForNoneC - zipFunction - public static <T,L,R> BiIterator<L,R> unzip(Iterator<? extends T> iter, BiConsumer<? super T,Pair<L,R>> unzip)
T - L - R - iter - unzip - the second parameter is an output parameter.public static <T,L,R> BiIterator<L,R> unzip(Collection<? extends T> c, BiConsumer<? super T,Pair<L,R>> unzip)
T - L - R - c - unzip - the second parameter is an output parameter.public static long advance(Iterator<?> iterator, long numberToAdvance)
next() on iterator, either numberToAdvance times
or until hasNext() returns false, whichever comes first.iterator - numberToAdvance - public static <T> ObjIterator<T> skip(Iterator<? extends T> iter, long n)
next() on iterator, either n times
or until hasNext() returns false, whichever comes first.
This is a lazy evaluation operation. The skip action is only triggered when Iterator.hasNext() or Iterator.next() is called.T - iter - n - public static <T> ObjIterator<T> limit(Iterator<? extends T> iter, long count)
Iterator.T - iter - count - public static <T> ObjIterator<T> skipAndLimit(Iterator<? extends T> iter, long offset, long count)
next() on iterator, either offset times
or until hasNext() returns false, whichever comes first.
This is a lazy evaluation operation. The skip action is only triggered when Iterator.hasNext() or Iterator.next() is called.T - iter - offset - count - public static <T> ObjIterator<T> skipNull(Iterator<? extends T> iter)
ObjIterator with null elements removed.T - iter - public static <T> ObjIterator<T> distinct(Iterator<? extends T> iter)
public static <T> ObjIterator<T> distinctBy(Iterator<? extends T> iter, Function<? super T,?> keyMapper)
public static <T> ObjIterator<T> filter(Iterator<? extends T> iter, Predicate<? super T> filter)
T - iter - filter - public static <T> ObjIterator<T> takeWhile(Iterator<? extends T> iter, Predicate<? super T> filter)
public static <T> ObjIterator<T> takeWhileInclusive(Iterator<? extends T> iter, Predicate<? super T> filter)
public static <T> ObjIterator<T> dropWhile(Iterator<? extends T> iter, Predicate<? super T> filter)
public static <T> ObjIterator<T> skipUntil(Iterator<? extends T> iter, Predicate<? super T> filter)
public static <T,U> ObjIterator<U> map(Iterator<? extends T> iter, Function<? super T,U> mapper)
T - U - iter - mapper - public static <T,U> ObjIterator<U> flatMap(Iterator<? extends T> iter, Function<? super T,? extends Collection<? extends U>> mapper)
T - U - iter - mapper - public static <T,U> ObjIterator<U> flattMap(Iterator<? extends T> iter, Function<? super T,? extends U[]> mapper)
public static <T,U> ObjIterator<T> generate(U init, Predicate<? super U> hasNext, Function<? super U,T> supplier)
T - U - init - hasNext - supplier - public static <T,U> ObjIterator<T> generate(U init, BiPredicate<? super U,T> hasNext, BiFunction<? super U,T,T> supplier)
T - U - init - hasNext - supplier - Copyright © 2021. All rights reserved.