Package com.landawn.abacus.util
Class Iterators
- java.lang.Object
-
- com.landawn.abacus.util.Iterators
-
public final class Iterators extends Object
The methods in this class should only read the inputCollections/Arrays
, not modify any of them.- Since:
- 0.9
- Author:
- Haiyang Li
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
advance(Iterator<?> iterator, long numberToAdvance)
Note: copied from Google Guava under Apache license v2
Callsnext()
oniterator
, eithernumberToAdvance
times or untilhasNext()
returnsfalse
, whichever comes first.static BooleanIterator
concat(boolean[]... a)
static ByteIterator
concat(byte[]... a)
static DoubleIterator
concat(double[]... a)
static FloatIterator
concat(float[]... a)
static IntIterator
concat(int[]... a)
static LongIterator
concat(long[]... a)
static ShortIterator
concat(short[]... a)
static <A,B>
BiIterator<A,B>concat(BiIterator<A,B>... a)
static BooleanIterator
concat(BooleanIterator... a)
static ByteIterator
concat(ByteIterator... a)
static CharIterator
concat(CharIterator... a)
static DoubleIterator
concat(DoubleIterator... a)
static FloatIterator
concat(FloatIterator... a)
static IntIterator
concat(IntIterator... a)
static LongIterator
concat(LongIterator... a)
static ShortIterator
concat(ShortIterator... a)
static <A,B,C>
TriIterator<A,B,C>concat(TriIterator<A,B,C>... 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 <T> ObjIterator<T>
concat(T[]... a)
static <T> ObjIterator<T>
concatt(Collection<? extends Collection<? extends T>> c)
static boolean
contains(Iterator<?> iter, Object objToFind)
static boolean
containsAll(Iterator<?> iter, Collection<?> objsToFind)
static boolean
containsAny(Iterator<?> iter, Set<?> objsToFind)
static long
count(Iterator<?> iter)
static <T> long
count(Iterator<T> iter, Predicate<? super T> filter)
static <T> ObjIterator<T>
filter(Iterator<T> iter, Predicate<? super T> filter)
static <T> u.Nullable<T>
first(Iterator<T> iter)
static <T> u.Optional<T>
firstNonNull(Iterator<T> iter)
First non null.static <T,U>
ObjIterator<U>flatMap(Iterator<T> iter, Function<? super T,? extends Collection<? extends U>> mapper)
static <A,B,E extends Exception>
voidforEach(Iterator<A> a, Iterator<B> b, A valueForNoneA, B valueForNoneB, Throwables.BiConsumer<? super A,? super B,E> action)
static <A,B,E extends Exception>
voidforEach(Iterator<A> a, Iterator<B> b, Throwables.BiConsumer<? super A,? super B,E> action)
static <A,B,C,E extends Exception>
voidforEach(Iterator<A> a, Iterator<B> b, Iterator<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, Throwables.TriConsumer<? super A,? super B,? super C,E> action)
static <A,B,C,E extends Exception>
voidforEach(Iterator<A> a, Iterator<B> b, Iterator<C> c, Throwables.TriConsumer<? super A,? super B,? super C,E> action)
static <T,E extends Exception>
voidforEach(Iterator<T> iter, Throwables.Consumer<? super T,E> action)
static <T,T2,T3,E extends Exception,E2 extends Exception,E3 extends Exception>
voidforEach(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<T2>,E> flatMapper, Throwables.Function<? super T2,? extends Collection<T3>,E2> flatMapper2, Throwables.TriConsumer<? super T,? super T2,? super T3,E3> action)
static <T,U,E extends Exception,E2 extends Exception>
voidforEach(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<U>,E> flatMapper, Throwables.BiConsumer<? super T,? super U,E2> action)
static <T,E extends Exception>
voidforEachIndexed(Iterator<T> iter, Throwables.IndexedConsumer<? super T,E> action)
static <T,T2,T3,E extends Exception,E2 extends Exception,E3 extends Exception>
voidforEachNonNull(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<T2>,E> flatMapper, Throwables.Function<? super T2,? extends Collection<T3>,E2> flatMapper2, Throwables.TriConsumer<? super T,? super T2,? super T3,E3> action)
For each non null.static <T,U,E extends Exception,E2 extends Exception>
voidforEachNonNull(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<U>,E> flatMapper, Throwables.BiConsumer<? super T,? super U,E2> action)
For each non null.static <T,E extends Exception>
voidforEachPair(Iterator<T> iter, Throwables.BiConsumer<? super T,? super T,E> action)
For each pair.static <T,E extends Exception>
voidforEachPair(Iterator<T> iter, Throwables.BiConsumer<? super T,? super T,E> action, int increment)
For each pair.static <T,E extends Exception>
voidforEachTriple(Iterator<T> iter, Throwables.TriConsumer<? super T,? super T,? super T,E> action)
For each triple.static <T,E extends Exception>
voidforEachTriple(Iterator<T> iter, Throwables.TriConsumer<? super T,? super T,? super T,E> action, int increment)
For each triple.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<T> iter, int index)
static <T> u.Nullable<T>
getOnlyElement(Iterator<? extends T> iter)
Gets the only element.static long
indexOf(Iterator<?> iter, Object objToFind)
static <T> u.Nullable<T>
last(Iterator<T> iter)
static <T> u.Optional<T>
lastNonNull(Iterator<T> iter)
Last non null.static <T> ObjIterator<T>
limit(Iterator<T> iter, long count)
Returns a newIterator
.static <T,U>
ObjIterator<U>map(Iterator<T> iter, Function<? super T,U> mapper)
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 long
occurrencesOf(Iterator<?> iter, Object objToFind)
static <T> ObjIterator<T>
repeat(T e, int n)
static <T> ObjIterator<T>
repeatAll(Collection<T> c, int n)
static <T> ObjIterator<T>
repeatAllToSize(Collection<T> c, int size)
Repeat all to size.static <T> ObjIterator<T>
repeatEach(Collection<T> c, int n)
static <T> ObjIterator<T>
repeatEachToSize(Collection<T> c, int size)
Repeat each to size.static <T> ObjIterator<T>
skip(Iterator<T> iter, long n)
Callsnext()
oniterator
, eithern
times or untilhasNext()
returnsfalse
, whichever comes first.static <T> ObjIterator<T>
skipAndLimit(Iterator<T> iter, long offset, long count)
Callsnext()
oniterator
, eitheroffset
times or untilhasNext()
returnsfalse
, whichever comes first.static <T> ObjIterator<T>
skipNull(Iterator<T> iter)
Returns a newObjIterator
withnull
elements removed.static <T> ObjIterator<T>
slice(Iterator<T> iter, long fromIndex, long toIndex)
static <T> ObjIterator<List<T>>
split(Iterator<? extends T> iter, int chunkSize)
static <T,C extends Collection<T>>
CtoCollection(Iterator<? extends T> iter, Supplier<? extends C> collectionFactory)
static <T> List<T>
toList(Iterator<? extends T> iter)
static <T,K,E extends Exception>
Map<K,T>toMap(Iterator<? extends T> iter, Throwables.Function<? super T,K,E> keyMapper)
static <T,K,V,E extends Exception,E2 extends Exception>
Map<K,V>toMap(Iterator<? extends T> iter, Throwables.Function<? super T,K,E> keyMapper, Throwables.Function<? super T,? extends V,E2> valueExtractor)
static <T,K,V,M extends Map<K,V>,E extends Exception,E2 extends Exception>
MtoMap(Iterator<? extends T> iter, Throwables.Function<? super T,K,E> keyMapper, Throwables.Function<? super T,? extends V,E2> valueExtractor, Supplier<? extends M> mapSupplier)
static <T> Set<T>
toSet(Iterator<? extends T> iter)
static <T,L,R>
BiIterator<L,R>unzip(Iterator<? extends T> iter, BiConsumer<? super T,Pair<L,R>> unzip)
static <T,L,M,R>
TriIterator<L,M,R>unzipp(Iterator<? extends T> iter, BiConsumer<? super T,Triple<L,M,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)
-
-
-
Method Detail
-
contains
public static boolean contains(Iterator<?> iter, Object objToFind)
- Parameters:
iter
-objToFind
-- Returns:
- true, if successful
-
containsAny
public static boolean containsAny(Iterator<?> iter, Set<?> objsToFind)
- Parameters:
iter
-objToFind
-- Returns:
- true, if successful
-
containsAll
public static boolean containsAll(Iterator<?> iter, Collection<?> objsToFind)
- Parameters:
iter
-objToFind
-- Returns:
- true, if successful
-
indexOf
public static long indexOf(Iterator<?> iter, Object objToFind)
- Parameters:
iter
-objToFind
-- Returns:
-
occurrencesOf
public static long occurrencesOf(Iterator<?> iter, Object objToFind)
- Parameters:
iter
-objToFind
-- Returns:
-
count
public static long count(Iterator<?> iter)
- Parameters:
iter
-- Returns:
-
count
public static <T> long count(Iterator<T> iter, Predicate<? super T> filter)
- Type Parameters:
T
-- Parameters:
iter
-filter
-- Returns:
-
toList
public static <T> List<T> toList(Iterator<? extends T> iter)
- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
toSet
public static <T> Set<T> toSet(Iterator<? extends T> iter)
- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
toCollection
public static <T,C extends Collection<T>> C toCollection(Iterator<? extends T> iter, Supplier<? extends C> collectionFactory)
- Type Parameters:
T
-C
-- Parameters:
iter
-collectionFactory
-- Returns:
-
toMap
public static <T,K,E extends Exception> Map<K,T> toMap(Iterator<? extends T> iter, Throwables.Function<? super T,K,E> keyMapper) throws E extends Exception
- Type Parameters:
T
-K
- the key typeE
-- Parameters:
iter
-keyMapper
-- Returns:
- Throws:
E
- the eE extends Exception
-
toMap
public static <T,K,V,E extends Exception,E2 extends Exception> Map<K,V> toMap(Iterator<? extends T> iter, Throwables.Function<? super T,K,E> keyMapper, Throwables.Function<? super T,? extends V,E2> valueExtractor) throws E extends Exception, E2 extends Exception
- Type Parameters:
T
-K
- the key typeV
- the value typeE
-E2
-- Parameters:
iter
-keyMapper
-valueExtractor
-- Returns:
- Throws:
E
- the eE2
- the e2E extends Exception
-
toMap
public static <T,K,V,M extends Map<K,V>,E extends Exception,E2 extends Exception> M toMap(Iterator<? extends T> iter, Throwables.Function<? super T,K,E> keyMapper, Throwables.Function<? super T,? extends V,E2> valueExtractor, Supplier<? extends M> mapSupplier) throws E extends Exception, E2 extends Exception
- Type Parameters:
T
-K
- the key typeV
- the value typeM
-E
-E2
-- Parameters:
iter
-keyMapper
-valueExtractor
-mapSupplier
-- Returns:
- Throws:
E
- the eE2
- the e2E extends Exception
-
forEach
public static <T,E extends Exception> void forEach(Iterator<T> iter, Throwables.Consumer<? super T,E> action) throws E extends Exception
- Type Parameters:
T
-E
-- Parameters:
iter
-action
-- Throws:
E
- the eE extends Exception
-
forEachIndexed
public static <T,E extends Exception> void forEachIndexed(Iterator<T> iter, Throwables.IndexedConsumer<? super T,E> action) throws E extends Exception
- Type Parameters:
T
-E
-- Parameters:
iter
-action
-- Throws:
E
- the eE extends Exception
-
forEach
public static <T,U,E extends Exception,E2 extends Exception> void forEach(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<U>,E> flatMapper, Throwables.BiConsumer<? super T,? super U,E2> action) throws E extends Exception, E2 extends Exception
- Type Parameters:
T
-U
-E
-E2
-- Parameters:
iter
-flatMapper
-action
-- Throws:
E
- the eE2
- the e2E extends Exception
-
forEach
public static <T,T2,T3,E extends Exception,E2 extends Exception,E3 extends Exception> void forEach(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<T2>,E> flatMapper, Throwables.Function<? super T2,? extends Collection<T3>,E2> flatMapper2, Throwables.TriConsumer<? super T,? super T2,? super T3,E3> action) throws E extends Exception, E2 extends Exception, E3 extends Exception
- Type Parameters:
T
-T2
-T3
-E
-E2
-E3
-- Parameters:
iter
-flatMapper
-flatMapper2
-action
-- Throws:
E
- the eE2
- the e2E3
- the e3E extends Exception
-
forEach
public static <A,B,E extends Exception> void forEach(Iterator<A> a, Iterator<B> b, Throwables.BiConsumer<? super A,? super B,E> action) throws E extends Exception
- Type Parameters:
A
-B
-E
-- Parameters:
a
-b
-action
-- Throws:
E
- the eE extends Exception
-
forEach
public static <A,B,C,E extends Exception> void forEach(Iterator<A> a, Iterator<B> b, Iterator<C> c, Throwables.TriConsumer<? super A,? super B,? super C,E> action) throws E extends Exception
- Type Parameters:
A
-B
-C
-E
-- Parameters:
a
-b
-c
-action
-- Throws:
E
- the eE extends Exception
-
forEach
public static <A,B,E extends Exception> void forEach(Iterator<A> a, Iterator<B> b, A valueForNoneA, B valueForNoneB, Throwables.BiConsumer<? super A,? super B,E> action) throws E extends Exception
- Type Parameters:
A
-B
-E
-- Parameters:
a
-b
-valueForNoneA
-valueForNoneB
-action
-- Throws:
E
- the eE extends Exception
-
forEach
public static <A,B,C,E extends Exception> void forEach(Iterator<A> a, Iterator<B> b, Iterator<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, Throwables.TriConsumer<? super A,? super B,? super C,E> action) throws E extends Exception
- Type Parameters:
A
-B
-C
-E
-- Parameters:
a
-b
-c
-valueForNoneA
-valueForNoneB
-valueForNoneC
-action
-- Throws:
E
- the eE extends Exception
-
forEachNonNull
public static <T,U,E extends Exception,E2 extends Exception> void forEachNonNull(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<U>,E> flatMapper, Throwables.BiConsumer<? super T,? super U,E2> action) throws E extends Exception, E2 extends Exception
For each non null.- Type Parameters:
T
-U
-E
-E2
-- Parameters:
iter
-flatMapper
-action
-- Throws:
E
- the eE2
- the e2E extends Exception
-
forEachNonNull
public static <T,T2,T3,E extends Exception,E2 extends Exception,E3 extends Exception> void forEachNonNull(Iterator<T> iter, Throwables.Function<? super T,? extends Collection<T2>,E> flatMapper, Throwables.Function<? super T2,? extends Collection<T3>,E2> flatMapper2, Throwables.TriConsumer<? super T,? super T2,? super T3,E3> action) throws E extends Exception, E2 extends Exception, E3 extends Exception
For each non null.- Type Parameters:
T
-T2
-T3
-E
-E2
-E3
-- Parameters:
iter
-flatMapper
-flatMapper2
-action
-- Throws:
E
- the eE2
- the e2E3
- the e3E extends Exception
-
forEachPair
public static <T,E extends Exception> void forEachPair(Iterator<T> iter, Throwables.BiConsumer<? super T,? super T,E> action) throws E extends Exception
For each pair.- Type Parameters:
T
-E
-- Parameters:
iter
-action
-- Throws:
E
- the eE extends Exception
-
forEachPair
public static <T,E extends Exception> void forEachPair(Iterator<T> iter, Throwables.BiConsumer<? super T,? super T,E> action, int increment) throws E extends Exception
For each pair.- Type Parameters:
T
-E
-- Parameters:
iter
-action
-increment
-- Throws:
E
- the eE extends Exception
-
forEachTriple
public static <T,E extends Exception> void forEachTriple(Iterator<T> iter, Throwables.TriConsumer<? super T,? super T,? super T,E> action) throws E extends Exception
For each triple.- Type Parameters:
T
-E
-- Parameters:
iter
-action
-- Throws:
E
- the eE extends Exception
-
forEachTriple
public static <T,E extends Exception> void forEachTriple(Iterator<T> iter, Throwables.TriConsumer<? super T,? super T,? super T,E> action, int increment) throws E extends Exception
For each triple.- Type Parameters:
T
-E
-- Parameters:
iter
-action
-increment
-- Throws:
E
- the eE extends Exception
-
repeat
public static <T> ObjIterator<T> repeat(T e, int n)
- Type Parameters:
T
-- Parameters:
e
-n
-- Returns:
-
repeatEach
public static <T> ObjIterator<T> repeatEach(Collection<T> c, int n)
- Type Parameters:
T
-- Parameters:
c
-n
-- Returns:
-
repeatAll
public static <T> ObjIterator<T> repeatAll(Collection<T> c, int n)
- Type Parameters:
T
-- Parameters:
c
-n
-- Returns:
-
repeatEachToSize
public static <T> ObjIterator<T> repeatEachToSize(Collection<T> c, int size)
Repeat each to size.- Type Parameters:
T
-- Parameters:
c
-size
-- Returns:
-
repeatAllToSize
public static <T> ObjIterator<T> repeatAllToSize(Collection<T> c, int size)
Repeat all to size.- Type Parameters:
T
-- Parameters:
c
-size
-- Returns:
-
concat
@SafeVarargs public static BooleanIterator concat(boolean[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static ShortIterator concat(short[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static ByteIterator concat(byte[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static IntIterator concat(int[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static LongIterator concat(long[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static FloatIterator concat(float[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static DoubleIterator concat(double[]... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static BooleanIterator concat(BooleanIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static CharIterator concat(CharIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static ByteIterator concat(ByteIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static ShortIterator concat(ShortIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static IntIterator concat(IntIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static LongIterator concat(LongIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static FloatIterator concat(FloatIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static DoubleIterator concat(DoubleIterator... a)
- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static <T> ObjIterator<T> concat(T[]... a)
- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static <T> ObjIterator<T> concat(Collection<? extends T>... a)
- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
concatt
public static <T> ObjIterator<T> concatt(Collection<? extends Collection<? extends T>> c)
- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
concat
@SafeVarargs public static <T> ObjIterator<T> concat(Iterator<? extends T>... a)
- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
concat
public static <T> ObjIterator<T> concat(Collection<? extends Iterator<? extends T>> c)
- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
concat
@SafeVarargs public static <A,B> BiIterator<A,B> concat(BiIterator<A,B>... a)
- Type Parameters:
A
-B
-- Parameters:
a
-- Returns:
-
concat
@SafeVarargs public static <A,B,C> TriIterator<A,B,C> concat(TriIterator<A,B,C>... a)
- Type Parameters:
A
-B
-C
-- Parameters:
a
-- Returns:
-
merge
public static <T> ObjIterator<T> merge(Collection<? extends T> a, Collection<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
- Type Parameters:
T
-- Parameters:
a
-b
-nextSelector
-- Returns:
-
merge
public static <T> ObjIterator<T> merge(Iterator<? extends T> a, Iterator<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
- Type Parameters:
T
-- Parameters:
a
-b
-nextSelector
-- Returns:
-
zip
public static <A,B,R> ObjIterator<R> zip(Collection<A> a, Collection<B> b, BiFunction<? super A,? super B,R> zipFunction)
- Type Parameters:
A
-B
-R
-- Parameters:
a
-b
-zipFunction
-- Returns:
-
zip
public static <A,B,R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, BiFunction<? super A,? super B,R> zipFunction)
- Type Parameters:
A
-B
-R
-- Parameters:
a
-b
-zipFunction
-- Returns:
-
zip
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)
- Type Parameters:
A
-B
-C
-R
-- Parameters:
a
-b
-c
-zipFunction
-- Returns:
-
zip
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)
- Type Parameters:
A
-B
-C
-R
-- Parameters:
a
-b
-c
-zipFunction
-- Returns:
-
zip
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)
- Type Parameters:
A
-B
-R
-- Parameters:
a
-b
-valueForNoneA
-valueForNoneB
-zipFunction
-- Returns:
-
zip
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)
- Type Parameters:
A
-B
-R
-- Parameters:
a
-b
-valueForNoneA
-valueForNoneB
-zipFunction
-- Returns:
-
zip
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)
- Type Parameters:
A
-B
-C
-R
-- Parameters:
a
-b
-c
-valueForNoneA
-valueForNoneB
-valueForNoneC
-zipFunction
-- Returns:
-
zip
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)
- Type Parameters:
A
-B
-C
-R
-- Parameters:
a
-b
-c
-valueForNoneA
-valueForNoneB
-valueForNoneC
-zipFunction
-- Returns:
-
unzip
public static <T,L,R> BiIterator<L,R> unzip(Iterator<? extends T> iter, BiConsumer<? super T,Pair<L,R>> unzip)
- Type Parameters:
T
-L
-R
-- Parameters:
iter
-unzip
- the second parameter is an output parameter.- Returns:
-
unzipp
public static <T,L,M,R> TriIterator<L,M,R> unzipp(Iterator<? extends T> iter, BiConsumer<? super T,Triple<L,M,R>> unzip)
- Type Parameters:
T
-L
-M
-R
-- Parameters:
iter
-unzip
- the second parameter is an output parameter.- Returns:
-
split
public static <T> ObjIterator<List<T>> split(Iterator<? extends T> iter, int chunkSize)
- Type Parameters:
T
-- Parameters:
iter
-chunkSize
- the desired size of each sub sequence (the last may be smaller).- Returns:
-
get
public static <T> u.Nullable<T> get(Iterator<T> iter, int index)
- Type Parameters:
T
-- Parameters:
iter
-index
-- Returns:
-
first
public static <T> u.Nullable<T> first(Iterator<T> iter)
- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
firstNonNull
public static <T> u.Optional<T> firstNonNull(Iterator<T> iter)
First non null.- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
last
public static <T> u.Nullable<T> last(Iterator<T> iter)
- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
lastNonNull
public static <T> u.Optional<T> lastNonNull(Iterator<T> iter)
Last non null.- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
advance
public static long advance(Iterator<?> iterator, long numberToAdvance)
Note: copied from Google Guava under Apache license v2
Callsnext()
oniterator
, eithernumberToAdvance
times or untilhasNext()
returnsfalse
, whichever comes first.- Parameters:
iterator
-numberToAdvance
-- Returns:
-
skip
public static <T> ObjIterator<T> skip(Iterator<T> iter, long n)
Callsnext()
oniterator
, eithern
times or untilhasNext()
returnsfalse
, whichever comes first. This is a lazy evaluation operation. Theskip
action is only triggered whenIterator.hasNext()
orIterator.next()
is called.- Type Parameters:
T
-- Parameters:
iter
-n
-- Returns:
-
limit
public static <T> ObjIterator<T> limit(Iterator<T> iter, long count)
Returns a newIterator
.- Type Parameters:
T
-- Parameters:
iter
-count
-- Returns:
-
skipAndLimit
public static <T> ObjIterator<T> skipAndLimit(Iterator<T> iter, long offset, long count)
Callsnext()
oniterator
, eitheroffset
times or untilhasNext()
returnsfalse
, whichever comes first. This is a lazy evaluation operation. Theskip
action is only triggered whenIterator.hasNext()
orIterator.next()
is called.- Type Parameters:
T
-- Parameters:
iter
-offset
-count
-- Returns:
-
slice
public static <T> ObjIterator<T> slice(Iterator<T> iter, long fromIndex, long toIndex)
- Type Parameters:
T
-- Parameters:
iter
-fromIndex
-toIndex
-- Returns:
-
skipNull
public static <T> ObjIterator<T> skipNull(Iterator<T> iter)
Returns a newObjIterator
withnull
elements removed.- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
getOnlyElement
public static <T> u.Nullable<T> getOnlyElement(Iterator<? extends T> iter) throws DuplicatedResultException
Gets the only element.- Type Parameters:
T
-- Parameters:
iter
-- Returns:
- throws DuplicatedResultException if there are more than one elements in the specified
iter
. - Throws:
DuplicatedResultException
- the duplicated result exception
-
filter
public static <T> ObjIterator<T> filter(Iterator<T> iter, Predicate<? super T> filter)
- Type Parameters:
T
-- Parameters:
iter
-filter
-- Returns:
-
map
public static <T,U> ObjIterator<U> map(Iterator<T> iter, Function<? super T,U> mapper)
- Type Parameters:
T
-U
-- Parameters:
iter
-mapper
-- Returns:
-
flatMap
public static <T,U> ObjIterator<U> flatMap(Iterator<T> iter, Function<? super T,? extends Collection<? extends U>> mapper)
- Type Parameters:
T
-U
-- Parameters:
iter
-mapper
-- Returns:
-
generate
public static <T,U> ObjIterator<T> generate(U init, Predicate<? super U> hasNext, Function<? super U,T> supplier)
- Type Parameters:
T
-U
-- Parameters:
init
-hasNext
-supplier
-- Returns:
-
generate
public static <T,U> ObjIterator<T> generate(U init, BiPredicate<? super U,T> hasNext, BiFunction<? super U,T,T> supplier)
- Type Parameters:
T
-U
-- Parameters:
init
-hasNext
-supplier
-- Returns:
-
-