Class Iterators

java.lang.Object
com.landawn.abacus.util.Iterators

public final class Iterators extends Object

Note: This class includes codes copied from Apache Commons Lang, Google Guava and other open source projects under the Apache License 2.0. The methods copied from other libraries/frameworks/projects may be modified in this class.



When to throw exception? It's designed to avoid throwing any unnecessary exception if the contract defined by method is not broken. for example, if user tries to reverse a null or empty String. the input String will be returned. But exception will be thrown if try to add element to a null Object array or collection.

An empty String/Array/Collection/Map/Iterator/Iterable/InputStream/Reader will always be a preferred choice than a null for the return value of a method.

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.

See Also:
  • Method Summary

    Modifier and Type
    Method
    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.
    concat(boolean[]... a)
    Concatenates multiple boolean arrays into a single BooleanIterator.
    concat(byte[]... a)
    Concatenates multiple byte arrays into a single ByteIterator.
    concat(char[]... a)
    Concatenates multiple char arrays into a single CharIterator.
    concat(double[]... a)
    Concatenates multiple double arrays into a single DoubleIterator.
    concat(float[]... a)
    Concatenates multiple float arrays into a single FloatIterator.
    concat(int[]... a)
    Concatenates multiple int arrays into a single IntIterator.
    concat(long[]... a)
    Concatenates multiple long arrays into a single LongIterator.
    concat(short[]... a)
    Concatenates multiple short arrays into a single ShortIterator.
    static <A, B> BiIterator<A,B>
    concat(BiIterator<A,B>... a)
    Concatenates multiple BiIterators into a single BiIterator.
    Concatenates multiple BooleanIterators into a single BooleanIterator.
    Concatenates multiple ByteIterators into a single ByteIterator.
    Concatenates multiple CharIterators into a single CharIterator.
    Concatenates multiple DoubleIterators into a single DoubleIterator.
    Concatenates multiple FloatIterators into a single FloatIterator.
    Concatenates multiple IntIterators into a single IntIterator.
    Concatenates multiple LongIterators into a single LongIterator.
    Concatenates multiple ShortIterators into a single ShortIterator.
    static <A, B, C> TriIterator<A,B,C>
    concat(TriIterator<A,B,C>... a)
    Concatenates multiple TriIterators into a single TriIterator.
    static <T> ObjIterator<T>
    concat(Iterable<? extends T>... a)
    Concatenates multiple Iterable objects into a single ObjIterator.
    static <T> ObjIterator<T>
    concat(Collection<? extends Iterator<? extends T>> c)
    Concatenates multiple Iterators into a single ObjIterator.
    static <T> ObjIterator<T>
    concat(Iterator<? extends T>... a)
    Concatenates multiple Iterators into a single ObjIterator.
    static <K, V> ObjIterator<Map.Entry<K,V>>
    concat(Map<? extends K,? extends V>... a)
    Concatenates multiple Maps into a single ObjIterator of Map.Entry.
    static <T> ObjIterator<T>
    concat(T[]... a)
    Concatenates multiple arrays into a single ObjIterator.
    static <T> ObjIterator<T>
    concatIterables(Collection<? extends Iterable<? extends T>> c)
    Concatenates multiple Iterable objects into a single ObjIterator.
    static long
    count(Iterator<?> iter)
    Counts the number of elements in the given iterator.
    static <T> long
    count(Iterator<? extends T> iter, Predicate<? super T> predicate)
    Counts the number of elements in the given iterator that match the provided predicate.
    static <T> ObjIterator<T>
    cycle(Iterable<? extends T> iterable)
    Returns an infinite iterator cycling over the elements of the provided iterable.
    static <T> ObjIterator<T>
    cycle(Iterable<? extends T> iterable, long rounds)
    Returns an iterator that cycles over the elements of the provided iterable for a specified number of rounds.
    static <T> ObjIterator<T>
    cycle(T... elements)
    Returns an infinite iterator cycling over the provided elements.
    static <T> ObjIterator<T>
    distinct(Iterable<? extends T> c)
    Returns a new ObjIterator with distinct elements from the original Iterable.
    static <T> ObjIterator<T>
    distinct(Iterator<? extends T> iter)
    Returns a new ObjIterator with distinct elements from the original Iterator.
    static <T> ObjIterator<T>
    distinctBy(Iterable<? extends T> c, Function<? super T,?> keyMapper)
    Returns a new ObjIterator with distinct elements from the original Iterable based on a key derived from each element.
    static <T> ObjIterator<T>
    distinctBy(Iterator<? extends T> iter, Function<? super T,?> keyMapper)
    Returns a new ObjIterator with distinct elements from the original Iterator based on a key derived from each element.
    static <T> ObjIterator<T>
    dropWhile(Iterable<? extends T> c, Predicate<? super T> predicate)
    Returns a new ObjIterator that skips elements from the original Iterable as long as they satisfy the provided Predicate.
    static <T> ObjIterator<T>
    dropWhile(Iterator<? extends T> iter, Predicate<? super T> predicate)
    Returns a new ObjIterator that skips elements from the original Iterator as long as they satisfy the provided Predicate.
    static boolean
    elementsEqual(Iterator<?> iterator1, Iterator<?> iterator2)
    Note: Copied from Google Guava under the Apache License 2.0.
    static <T> ObjIterator<T>
    filter(Iterable<? extends T> c, Predicate<? super T> predicate)
    Returns a new ObjIterator that only includes elements from the original Iterable that satisfy the provided Predicate.
    static <T> ObjIterator<T>
    filter(Iterator<? extends T> iter, Predicate<? super T> predicate)
    Returns a new ObjIterator that only includes elements from the original Iterator that satisfy the provided Predicate.
    static <T, U> ObjIterator<U>
    flatmap(Iterable<? extends T> c, Function<? super T,? extends U[]> mapper)
    Transforms the elements of the given Iterable into arrays using the provided Function and flattens the result into a new ObjIterator.
    static <T, U> ObjIterator<U>
    flatmap(Iterator<? extends T> iter, Function<? super T,? extends U[]> mapper)
    Transforms the elements of the given Iterator into arrays using the provided Function and flattens the result into a new ObjIterator.
    static <T, U> ObjIterator<U>
    flatMap(Iterable<? extends T> c, Function<? super T,? extends Iterable<? extends U>> mapper)
    Transforms the elements of the given Iterable into Iterables using the provided Function and flattens the result into a new ObjIterator.
    static <T, U> ObjIterator<U>
    flatMap(Iterator<? extends T> iter, Function<? super T,? extends Iterable<? extends U>> mapper)
    Transforms the elements of the given Iterator into Iterables using the provided Function and flattens the result into a new ObjIterator.
    static <T, E extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Collection of Iterators.
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Collection of Iterators.
    static <T, E extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count.
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count.
    static <T, E extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count.
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count.
    static <T, E extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Collection of Iterators.
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Collection<? extends Iterator<? extends T>> iterators, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Collection of Iterators.
    static <T, E extends Exception>
    void
    forEach(Iterator<? extends T> iter, long offset, long count, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count.
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Iterator<? extends T> iter, long offset, long count, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count.
    static <T, E extends Exception>
    void
    forEach(Iterator<? extends T> iter, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count.
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Iterator<? extends T> iter, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count.
    static <T, E extends Exception>
    void
    forEach(Iterator<? extends T> iter, Throwables.Consumer<? super T,E> elementConsumer)
    Performs an action for each element of the given Iterator
    static <T, E extends Exception, E2 extends Exception>
    void
    forEach(Iterator<? extends T> iter, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete)
    Performs an action for each element of the given Iterator and executes a final action upon completion.
    static <T> u.Nullable<T>
    get(Iterator<? extends T> iter, long index)
    Retrieves the element at the specified position in the given iterator.
    static long
    indexOf(Iterator<?> iter, Object valueToFind)
    Returns the index of the first occurrence of the specified value in the given iterator.
    static long
    indexOf(Iterator<?> iter, Object valueToFind, long fromIndex)
    Returns the index of the first occurrence of the specified value in the given iterator, starting the search from the specified index.
    static <T> ObjIterator<T>
    limit(Iterator<? extends T> iter, long count)
    Returns a new ObjIterator that is limited to the specified count of elements from the original Iterator.
    static <T, U> ObjIterator<U>
    map(Iterable<? extends T> c, Function<? super T,U> mapper)
    Transforms the elements of the given Iterable using the provided Function and returns a new ObjIterator with the transformed elements.
    static <T, U> ObjIterator<U>
    map(Iterator<? extends T> iter, Function<? super T,U> mapper)
    Transforms the elements of the given Iterator using the provided Function and returns a new ObjIterator with the transformed elements.
    static <T> ObjIterator<T>
    merge(Iterable<? extends T> a, Iterable<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
    Merges two Iterable objects into a single ObjIterator.
    static <T> ObjIterator<T>
    merge(Collection<? extends Iterator<? extends T>> c, BiFunction<? super T,? super T,MergeResult> nextSelector)
    Merges multiple Iterators into a single ObjIterator.
    static <T> ObjIterator<T>
    merge(Iterator<? extends T> a, Iterator<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
    Merges two Iterators into a single ObjIterator.
    static <T> ObjIterator<T>
    mergeIterables(Collection<? extends Iterable<? extends T>> iterables, BiFunction<? super T,? super T,MergeResult> nextSelector)
    Merges multiple Iterable objects into a single ObjIterator.
    static <T extends Comparable>
    ObjIterator<T>
    mergeSorted(Iterable<? extends T> sortedA, Iterable<? extends T> sortedB)
    Merges two sorted Iterable objects into a single ObjIterato, which will iterate over the elements of each Iterable in a sorted order.
    static <T> ObjIterator<T>
    mergeSorted(Iterable<? extends T> sortedA, Iterable<? extends T> sortedB, Comparator<? super T> cmp)
    Merges two sorted Iterable objects into a single ObjIterator, which will iterate over the elements of each Iterable in the order determined by the provided Comparator 'cmp'.
    static <T extends Comparable>
    ObjIterator<T>
    mergeSorted(Iterator<? extends T> sortedA, Iterator<? extends T> sortedB)
    Merges two sorted Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in a sorted order.
    static <T> ObjIterator<T>
    mergeSorted(Iterator<? extends T> sortedA, Iterator<? extends T> sortedB, Comparator<? super T> cmp)
    Merges two sorted Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in a sorted order.
    static long
    occurrencesOf(Iterator<?> iter, Object valueToFind)
    Counts the occurrences of a specific value in the given iterator.
    static <T> ObjIterator<T>
    repeat(T e, int n)
     
    static <T> ObjIterator<T>
    repeat(T e, long n)
     
    static <T> ObjIterator<T>
    repeatCollection(Collection<? extends T> c, long n)
    Repeats the entire collectionntimes.
    static <T> ObjIterator<T>
    repeatCollectionToSize(Collection<? extends T> c, long size)
    Repeats the entire specified Collection till reach the specified size.
    static <T> ObjIterator<T>
    repeatElements(Collection<? extends T> c, long n)
    Repeats each element in the specified Collection n times.
    static <T> ObjIterator<T>
    repeatElementsToSize(Collection<? extends T> c, long size)
    Repeats each element in the specified Collection n times till reach the specified size.
    static <T> ObjIterator<T>
    skip(Iterator<? extends T> iter, long n)
    Skips the firstnelements of the provided Iterator and returns a new ObjIterator starting from the (n+1)th element.
    static <T> ObjIterator<T>
    skipAndLimit(Iterable<? extends T> iter, long offset, long count)
    Returns a new ObjIterator that starts from the specified offset and is limited to the specified count of elements from the original Iterable.
    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>
    skipNulls(Iterable<? extends T> c)
    Returns a new ObjIterator with null elements removed.
    static <T> ObjIterator<T>
    skipNulls(Iterator<? extends T> iter)
    Returns a new ObjIterator with null elements removed.
    static <T> ObjIterator<T>
    skipUntil(Iterable<? extends T> c, Predicate<? super T> predicate)
    Skips elements in the provided Iterable until the provided Predicate returns true.
    static <T> ObjIterator<T>
    skipUntil(Iterator<? extends T> iter, Predicate<? super T> predicate)
    Skips elements in the provided Iterator until the provided Predicate returns true.
    static <T> ObjIterator<T>
    takeWhile(Iterable<? extends T> c, Predicate<? super T> predicate)
    Returns a new ObjIterator that includes elements from the original Iterable as long as they satisfy the provided Predicate.
    static <T> ObjIterator<T>
    takeWhile(Iterator<? extends T> iter, Predicate<? super T> predicate)
    Returns a new ObjIterator that includes elements from the original Iterator as long as they satisfy the provided Predicate.
    static <T> ObjIterator<T>
    takeWhileInclusive(Iterable<? extends T> c, Predicate<? super T> predicate)
    Returns a new ObjIterator that includes elements from the original Iterable as long as they satisfy the provided Predicate.
    static <T> ObjIterator<T>
    takeWhileInclusive(Iterator<? extends T> iter, Predicate<? super T> predicate)
    Returns a new ObjIterator that includes elements from the original Iterator as long as they satisfy the provided Predicate.
    static <T, A, B> BiIterator<A,B>
    unzip(Iterable<? extends T> c, BiConsumer<? super T,Pair<A,B>> unzip)
    Unzips an Iterable into a BiIterator.
    static <T, A, B> BiIterator<A,B>
    unzip(Iterator<? extends T> iter, BiConsumer<? super T,Pair<A,B>> unzip)
    Unzips an Iterator into a BiIterator.
    static <T, A, B, C>
    TriIterator<A,B,C>
    unzipp(Iterable<? extends T> c, BiConsumer<? super T,Triple<A,B,C>> unzip)
    static <T, A, B, C>
    TriIterator<A,B,C>
    unzipp(Iterator<? extends T> iter, BiConsumer<? super T,Triple<A,B,C>> unzip)
    static <A, B, R> ObjIterator<R>
    zip(Iterable<A> a, Iterable<B> b, A valueForNoneA, B valueForNoneB, BiFunction<? super A,? super B,? extends R> zipFunction)
    Zips two Iterable objects into a single ObjIterator, using default values when one iterator is exhausted.
    static <A, B, C, R>
    ObjIterator<R>
    zip(Iterable<A> a, Iterable<B> b, Iterable<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, TriFunction<? super A,? super B,? super C,? extends R> zipFunction)
    Zips three Iterable objects into a single ObjIterator, using default values when one iterator is exhausted.
    static <A, B, C, R>
    ObjIterator<R>
    zip(Iterable<A> a, Iterable<B> b, Iterable<C> c, TriFunction<? super A,? super B,? super C,? extends R> zipFunction)
    Zips three Iterable objects into a single ObjIterator, which will iterate over the elements of each Iterable in parallel.
    static <A, B, R> ObjIterator<R>
    zip(Iterable<A> a, Iterable<B> b, BiFunction<? super A,? super B,? extends R> zipFunction)
    Zips two Iterable objects into a single ObjIterator, which will iterate over the elements of each Iterable in parallel.
    static <A, B, R> ObjIterator<R>
    zip(Iterator<A> a, Iterator<B> b, A valueForNoneA, B valueForNoneB, BiFunction<? super A,? super B,? extends R> zipFunction)
    Zips two Iterators into a single ObjIterator, using default values when one iterator is exhausted.
    static <A, B, R> ObjIterator<R>
    zip(Iterator<A> a, Iterator<B> b, BiFunction<? super A,? super B,? extends R> zipFunction)
    Zips two Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in parallel.
    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,? extends R> zipFunction)
    Zips three Iterators into a single ObjIterator, using default values when one iterator is exhausted.
    static <A, B, C, R>
    ObjIterator<R>
    zip(Iterator<A> a, Iterator<B> b, Iterator<C> c, TriFunction<? super A,? super B,? super C,? extends R> zipFunction)
    Zips three Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in parallel.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public static <T> u.Nullable<T> get(Iterator<? extends T> iter, long index) throws IllegalArgumentException
      Retrieves the element at the specified position in the given iterator. The method will advance the iterator to the specified index and return the element at that position wrapped in a Nullable. If the index is out of bounds (greater than the number of elements in the iterator), a Nullable.empty() is returned.
      Type Parameters:
      T - The type of elements in the iterator.
      Parameters:
      iter - The iterator from which to retrieve the element.
      index - The position in the iterator of the element to be returned. Indexing starts from 0.
      Returns:
      A Nullable containing the element at the specified position in the iterator, or Nullable.empty() if the index is out of bounds.
      Throws:
      IllegalArgumentException - if the index is negative.
    • occurrencesOf

      public static long occurrencesOf(Iterator<?> iter, Object valueToFind)
      Counts the occurrences of a specific value in the given iterator. This method can be used to find the frequency of a particular value in the iterator.
      Parameters:
      iter - The iterator to be searched.
      valueToFind - The value to count occurrences of.
      Returns:
      The number of occurrences of the value in the iterator.
      See Also:
    • count

      public static long count(Iterator<?> iter)
      Counts the number of elements in the given iterator.
      Parameters:
      iter - The iterator to be counted.
      Returns:
      The number of elements in the iterator.
      See Also:
    • count

      public static <T> long count(Iterator<? extends T> iter, Predicate<? super T> predicate) throws IllegalArgumentException
      Counts the number of elements in the given iterator that match the provided predicate.
      Type Parameters:
      T - The type of elements in the iterator.
      Parameters:
      iter - The iterator to be searched.
      predicate - The predicate to apply to each element in the iterator.
      Returns:
      The number of elements in the iterator that match the provided predicate.
      Throws:
      IllegalArgumentException - if the predicate is null.
      See Also:
    • indexOf

      public static long indexOf(Iterator<?> iter, Object valueToFind)
      Returns the index of the first occurrence of the specified value in the given iterator. This method starts searching from the beginning of the iterator.
      Parameters:
      iter - The iterator to be searched.
      valueToFind - The value to find in the iterator.
      Returns:
      The index of the first occurrence of the specified value in the iterator, or -1 if the value is not found.
    • indexOf

      public static long indexOf(Iterator<?> iter, Object valueToFind, long fromIndex)
      Returns the index of the first occurrence of the specified value in the given iterator, starting the search from the specified index.
      Parameters:
      iter - The iterator to be searched.
      valueToFind - The value to find in the iterator.
      fromIndex - The index to start the search from.
      Returns:
      The index of the first occurrence of the specified value in the iterator, or -1 if the value is not found.
    • elementsEqual

      public static boolean elementsEqual(Iterator<?> iterator1, Iterator<?> iterator2)
      Note: Copied from Google Guava under the Apache License 2.0.

      Determines whether two iterators contain equal elements in the same order. More specifically, this method returns true if iterator1 and iterator2 contain the same number of elements and every element of iterator1 is equal to the corresponding element of iterator2.

      Note that this will modify the supplied iterators, since they will have been advanced some number of elements forward.

    • repeat

      public static <T> ObjIterator<T> repeat(T e, int n) throws IllegalArgumentException
      Type Parameters:
      T -
      Parameters:
      e -
      n -
      Returns:
      Throws:
      IllegalArgumentException
    • repeat

      public static <T> ObjIterator<T> repeat(T e, long n) throws IllegalArgumentException
      Type Parameters:
      T -
      Parameters:
      e -
      n -
      Returns:
      Throws:
      IllegalArgumentException
    • repeatElements

      public static <T> ObjIterator<T> repeatElements(Collection<? extends T> c, long n) throws IllegalArgumentException
      Repeats each element in the specified Collection n times.
      Type Parameters:
      T - The type of elements in the collection.
      Parameters:
      c - The collection whose elements are to be repeated.
      n - The number of times the collection's elements are to be repeated.
      Returns:
      An iterator over the elements in the collection, repeatedntimes.
      Throws:
      IllegalArgumentException - ifnis negative.
      See Also:
      • CommonUtil.repeatElements(Collection, int)
    • repeatCollection

      public static <T> ObjIterator<T> repeatCollection(Collection<? extends T> c, long n) throws IllegalArgumentException
      Repeats the entire collectionntimes.
      Type Parameters:
      T - The type of elements in the collection.
      Parameters:
      c - The collection to be repeated.
      n - The number of times the collection is to be repeated.
      Returns:
      An iterator over the collection, repeatedntimes.
      Throws:
      IllegalArgumentException - ifnis negative.
      See Also:
      • CommonUtil.repeatCollection(Collection, int)
    • repeatElementsToSize

      public static <T> ObjIterator<T> repeatElementsToSize(Collection<? extends T> c, long size) throws IllegalArgumentException
      Repeats each element in the specified Collection n times till reach the specified size.
      Type Parameters:
      T -
      Parameters:
      c -
      size -
      Returns:
      Throws:
      IllegalArgumentException
      See Also:
      • CommonUtil.repeatElementsToSize(Collection, int)
    • repeatCollectionToSize

      public static <T> ObjIterator<T> repeatCollectionToSize(Collection<? extends T> c, long size) throws IllegalArgumentException
      Repeats the entire specified Collection till reach the specified size.
      Type Parameters:
      T -
      Parameters:
      c -
      size -
      Returns:
      Throws:
      IllegalArgumentException
      See Also:
      • CommonUtil.repeatCollectionToSize(Collection, int)
    • cycle

      @SafeVarargs public static <T> ObjIterator<T> cycle(T... elements)
      Returns an infinite iterator cycling over the provided elements. However if the provided elements are empty, an empty iterator will be returned.
      Type Parameters:
      T - The type of elements in the array.
      Parameters:
      elements - The array whose elements are to be cycled over.
      Returns:
      An iterator cycling over the elements of the array.
    • cycle

      public static <T> ObjIterator<T> cycle(Iterable<? extends T> iterable)
      Returns an infinite iterator cycling over the elements of the provided iterable. However if the provided elements are empty, an empty iterator will be returned.
      Type Parameters:
      T - The type of elements in the iterable.
      Parameters:
      iterable - The iterable whose elements are to be cycled over.
      Returns:
      An iterator cycling over the elements of the iterable.
    • cycle

      public static <T> ObjIterator<T> cycle(Iterable<? extends T> iterable, long rounds)
      Returns an iterator that cycles over the elements of the provided iterable for a specified number of rounds. If the provided iterable is empty, an empty iterator will be returned. If the number of rounds is zero, an empty iterator will be returned.
      Type Parameters:
      T - The type of elements in the iterable.
      Parameters:
      iterable - The iterable whose elements are to be cycled over.
      rounds - The number of times to cycle over the iterable's elements.
      Returns:
      An iterator cycling over the elements of the iterable for the specified number of rounds.
      Throws:
      IllegalArgumentException - if 'rounds' is negative.
    • concat

      @SafeVarargs public static BooleanIterator concat(boolean[]... a)
      Concatenates multiple boolean arrays into a single BooleanIterator.
      Parameters:
      a - The boolean arrays to be concatenated.
      Returns:
      A BooleanIterator that will iterate over the elements of each provided boolean array in order.
    • concat

      @SafeVarargs public static CharIterator concat(char[]... a)
      Concatenates multiple char arrays into a single CharIterator.
      Parameters:
      a - The char arrays to be concatenated.
      Returns:
      A CharIterator that will iterate over the elements of each provided char array in order.
    • concat

      @SafeVarargs public static ByteIterator concat(byte[]... a)
      Concatenates multiple byte arrays into a single ByteIterator.
      Parameters:
      a - The byte arrays to be concatenated.
      Returns:
      A ByteIterator that will iterate over the elements of each provided byte array in order.
    • concat

      @SafeVarargs public static ShortIterator concat(short[]... a)
      Concatenates multiple short arrays into a single ShortIterator.
      Parameters:
      a - The short arrays to be concatenated.
      Returns:
      A ShortIterator that will iterate over the elements of each provided short array in order.
    • concat

      @SafeVarargs public static IntIterator concat(int[]... a)
      Concatenates multiple int arrays into a single IntIterator.
      Parameters:
      a - The int arrays to be concatenated.
      Returns:
      An IntIterator that will iterate over the elements of each provided int array in order.
    • concat

      @SafeVarargs public static LongIterator concat(long[]... a)
      Concatenates multiple long arrays into a single LongIterator.
      Parameters:
      a - The long arrays to be concatenated.
      Returns:
      A LongIterator that will iterate over the elements of each provided long array in order.
    • concat

      @SafeVarargs public static FloatIterator concat(float[]... a)
      Concatenates multiple float arrays into a single FloatIterator.
      Parameters:
      a - The float arrays to be concatenated.
      Returns:
      A FloatIterator that will iterate over the elements of each provided float array in order.
    • concat

      @SafeVarargs public static DoubleIterator concat(double[]... a)
      Concatenates multiple double arrays into a single DoubleIterator.
      Parameters:
      a - The double arrays to be concatenated.
      Returns:
      A DoubleIterator that will iterate over the elements of each provided double array in order.
    • concat

      @SafeVarargs public static BooleanIterator concat(BooleanIterator... a)
      Concatenates multiple BooleanIterators into a single BooleanIterator.
      Parameters:
      a - The BooleanIterators to be concatenated.
      Returns:
      A BooleanIterator that will iterate over the elements of each provided BooleanIterator in order.
    • concat

      @SafeVarargs public static CharIterator concat(CharIterator... a)
      Concatenates multiple CharIterators into a single CharIterator.
      Parameters:
      a - The CharIterators to be concatenated.
      Returns:
      A CharIterator that will iterate over the elements of each provided CharIterator in order.
    • concat

      @SafeVarargs public static ByteIterator concat(ByteIterator... a)
      Concatenates multiple ByteIterators into a single ByteIterator.
      Parameters:
      a - The ByteIterators to be concatenated.
      Returns:
      A ByteIterator that will iterate over the elements of each provided ByteIterator in order.
    • concat

      @SafeVarargs public static ShortIterator concat(ShortIterator... a)
      Concatenates multiple ShortIterators into a single ShortIterator.
      Parameters:
      a - The ShortIterators to be concatenated.
      Returns:
      A ShortIterator that will iterate over the elements of each provided ShortIterator in order.
    • concat

      @SafeVarargs public static IntIterator concat(IntIterator... a)
      Concatenates multiple IntIterators into a single IntIterator.
      Parameters:
      a - The IntIterators to be concatenated.
      Returns:
      An IntIterator that will iterate over the elements of each provided IntIterator in order.
    • concat

      @SafeVarargs public static LongIterator concat(LongIterator... a)
      Concatenates multiple LongIterators into a single LongIterator.
      Parameters:
      a - The LongIterators to be concatenated.
      Returns:
      A LongIterator that will iterate over the elements of each provided LongIterator in order.
    • concat

      @SafeVarargs public static FloatIterator concat(FloatIterator... a)
      Concatenates multiple FloatIterators into a single FloatIterator.
      Parameters:
      a - The FloatIterators to be concatenated.
      Returns:
      A FloatIterator that will iterate over the elements of each provided FloatIterator in order.
    • concat

      @SafeVarargs public static DoubleIterator concat(DoubleIterator... a)
      Concatenates multiple DoubleIterators into a single DoubleIterator.
      Parameters:
      a - The DoubleIterators to be concatenated.
      Returns:
      A DoubleIterator that will iterate over the elements of each provided DoubleIterator in order.
    • concat

      @SafeVarargs public static <T> ObjIterator<T> concat(T[]... a)
      Concatenates multiple arrays into a single ObjIterator.
      Type Parameters:
      T - The type of elements in the arrays.
      Parameters:
      a - The arrays to be concatenated.
      Returns:
      An ObjIterator that will iterate over the elements of each provided array in order.
    • concat

      @SafeVarargs public static <T> ObjIterator<T> concat(Iterator<? extends T>... a)
      Concatenates multiple Iterators into a single ObjIterator.
      Type Parameters:
      T - The type of elements in the Iterators.
      Parameters:
      a - The Iterators to be concatenated.
      Returns:
      An ObjIterator that will iterate over the elements of each provided Iterator in order.
    • concat

      @SafeVarargs public static <T> ObjIterator<T> concat(Iterable<? extends T>... a)
      Concatenates multiple Iterable objects into a single ObjIterator.
      Type Parameters:
      T - The type of elements in the Iterable objects.
      Parameters:
      a - The Iterable objects to be concatenated.
      Returns:
      An ObjIterator that will iterate over the elements of each provided Iterable.
    • concat

      @SafeVarargs public static <K, V> ObjIterator<Map.Entry<K,V>> concat(Map<? extends K,? extends V>... a)
      Concatenates multiple Maps into a single ObjIterator of Map.Entry.
      Type Parameters:
      K - The type of keys in the Maps.
      V - The type of values in the Maps.
      Parameters:
      a - The Maps to be concatenated.
      Returns:
      An ObjIterator of Map.Entry that will iterate over the entries of each provided Map.
    • concat

      public static <T> ObjIterator<T> concat(Collection<? extends Iterator<? extends T>> c)
      Concatenates multiple Iterators into a single ObjIterator.
      Type Parameters:
      T - The type of elements in the Iterators.
      Parameters:
      c - The collection of Iterators to be concatenated.
      Returns:
      An ObjIterator that will iterate over the elements of each provided Iterator in order.
    • concatIterables

      public static <T> ObjIterator<T> concatIterables(Collection<? extends Iterable<? extends T>> c)
      Concatenates multiple Iterable objects into a single ObjIterator.
      Type Parameters:
      T - The type of elements in the Iterable objects.
      Parameters:
      c - The collection of Iterable objects to be concatenated.
      Returns:
      An ObjIterator that will iterate over the elements of each provided Iterable.
    • concat

      @SafeVarargs public static <A, B> BiIterator<A,B> concat(BiIterator<A,B>... a)
      Concatenates multiple BiIterators into a single BiIterator.
      Type Parameters:
      A - The type of the first element in the BiIterator.
      B - The type of the second element in the BiIterator.
      Parameters:
      a - The BiIterators to be concatenated.
      Returns:
      A BiIterator that will iterate over the elements of each provided BiIterator in order.
    • concat

      @SafeVarargs public static <A, B, C> TriIterator<A,B,C> concat(TriIterator<A,B,C>... a)
      Concatenates multiple TriIterators into a single TriIterator.
      Type Parameters:
      A - The type of the first element in the TriIterator.
      B - The type of the second element in the TriIterator.
      C - The type of the third element in the TriIterator.
      Parameters:
      a - The TriIterators to be concatenated.
      Returns:
      A TriIterator that will iterate over the elements of each provided TriIterator in order.
    • merge

      public static <T> ObjIterator<T> merge(Iterator<? extends T> a, Iterator<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector) throws IllegalArgumentException
      Merges two Iterators into a single ObjIterator. The order of elements in the resulting iterator is determined by the provided BiFunction 'nextSelector'.
      Type Parameters:
      T - The type of elements in the Iterators.
      Parameters:
      a - The first Iterator to be merged.
      b - The second Iterator to be merged.
      nextSelector - A BiFunction that determines the order of elements in the resulting iterator.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterators in the order determined by 'nextSelector'.
      Throws:
      IllegalArgumentException - if 'nextSelector' is null.
    • merge

      public static <T> ObjIterator<T> merge(Collection<? extends Iterator<? extends T>> c, BiFunction<? super T,? super T,MergeResult> nextSelector) throws IllegalArgumentException
      Merges multiple Iterators into a single ObjIterator. The order of elements in the resulting iterator is determined by the provided BiFunction 'nextSelector'.
      Type Parameters:
      T - The type of elements in the Iterators.
      Parameters:
      c - The collection of Iterators to be merged.
      nextSelector - A BiFunction that determines the order of elements in the resulting iterator. The first parameter is selected if MergeResult.TAKE_FIRST is returned, otherwise the second parameter is selected.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterators in the order determined by 'nextSelector'.
      Throws:
      IllegalArgumentException - if 'nextSelector' is null.
    • merge

      public static <T> ObjIterator<T> merge(Iterable<? extends T> a, Iterable<? extends T> b, BiFunction<? super T,? super T,MergeResult> nextSelector)
      Merges two Iterable objects into a single ObjIterator. The order of elements in the resulting iterator is determined by the provided BiFunction 'nextSelector'.
      Type Parameters:
      T - The type of elements in the Iterable objects.
      Parameters:
      a - The first Iterable object to be merged.
      b - The second Iterable object to be merged.
      nextSelector - A BiFunction that determines the order of elements in the resulting iterator.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterable objects in the order determined by 'nextSelector'.
      Throws:
      IllegalArgumentException - if 'nextSelector' is null.
    • mergeIterables

      public static <T> ObjIterator<T> mergeIterables(Collection<? extends Iterable<? extends T>> iterables, BiFunction<? super T,? super T,MergeResult> nextSelector) throws IllegalArgumentException
      Merges multiple Iterable objects into a single ObjIterator. The order of elements in the resulting iterator is determined by the provided BiFunction 'nextSelector'.
      Type Parameters:
      T - The type of elements in the Iterable objects.
      Parameters:
      iterables - The collection of Iterable objects to be merged.
      nextSelector - A BiFunction that determines the order of elements in the resulting iterator. The first parameter is selected if MergeResult.TAKE_FIRST is returned, otherwise the second parameter is selected.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterable objects in the order determined by 'nextSelector'.
      Throws:
      IllegalArgumentException - if 'nextSelector' is null.
    • mergeSorted

      public static <T extends Comparable> ObjIterator<T> mergeSorted(Iterator<? extends T> sortedA, Iterator<? extends T> sortedB)
      Merges two sorted Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in a sorted order. The elements in the Iterators should implement Comparable interface.
      Type Parameters:
      T - The type of elements in the Iterators, which should implement Comparable interface.
      Parameters:
      sortedA - The first Iterator to be merged. It should be in non-descending order.
      sortedB - The second Iterator to be merged. It should be in non-descending order.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterators in a sorted order.
    • mergeSorted

      public static <T> ObjIterator<T> mergeSorted(Iterator<? extends T> sortedA, Iterator<? extends T> sortedB, Comparator<? super T> cmp) throws IllegalArgumentException
      Merges two sorted Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in a sorted order. The order of elements in the resulting iterator is determined by the provided Comparator 'cmp'.
      Type Parameters:
      T - The type of elements in the Iterators.
      Parameters:
      sortedA - The first Iterator to be merged. It should be in non-descending order.
      sortedB - The second Iterator to be merged. It should be in non-descending order.
      cmp - The Comparator to determine the order of elements in the resulting iterator.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterators in a sorted order.
      Throws:
      IllegalArgumentException - if 'cmp' is null.
    • mergeSorted

      public static <T extends Comparable> ObjIterator<T> mergeSorted(Iterable<? extends T> sortedA, Iterable<? extends T> sortedB)
      Merges two sorted Iterable objects into a single ObjIterato, which will iterate over the elements of each Iterable in a sorted order. The elements in the Iterable objects should implement Comparable interface.
      Type Parameters:
      T - The type of elements in the Iterable objects, which should implement Comparable interface.
      Parameters:
      sortedA - The first Iterable object to be merged. It should be in non-descending order.
      sortedB - The second Iterable object to be merged. It should be in non-descending order.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterable objects in a sorted order.
    • mergeSorted

      public static <T> ObjIterator<T> mergeSorted(Iterable<? extends T> sortedA, Iterable<? extends T> sortedB, Comparator<? super T> cmp)
      Merges two sorted Iterable objects into a single ObjIterator, which will iterate over the elements of each Iterable in the order determined by the provided Comparator 'cmp'.
      Type Parameters:
      T - The type of elements in the Iterable objects.
      Parameters:
      sortedA - The first Iterable object to be merged. It should be in non-descending order.
      sortedB - The second Iterable object to be merged. It should be in non-descending order.
      cmp - The Comparator to determine the order of elements in the resulting iterator.
      Returns:
      An ObjIterator that will iterate over the elements of the provided Iterable objects in a sorted order.
      Throws:
      IllegalArgumentException - if 'cmp' is null.
    • zip

      public static <A, B, R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, BiFunction<? super A,? super B,? extends R> zipFunction)
      Zips two Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in parallel. The resulting elements are determined by the provided BiFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterator.
      B - The type of elements in the second Iterator.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterator to be zipped.
      b - The second Iterator to be zipped.
      zipFunction - A BiFunction that takes an element from each Iterator and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • zip

      public static <A, B, R> ObjIterator<R> zip(Iterable<A> a, Iterable<B> b, BiFunction<? super A,? super B,? extends R> zipFunction)
      Zips two Iterable objects into a single ObjIterator, which will iterate over the elements of each Iterable in parallel. The resulting elements are determined by the provided BiFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterable.
      B - The type of elements in the second Iterable.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterable to be zipped.
      b - The second Iterable to be zipped.
      zipFunction - A BiFunction that takes an element from each Iterable and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • 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,? extends R> zipFunction)
      Zips three Iterators into a single ObjIterator, which will iterate over the elements of each Iterator in parallel. The resulting elements are determined by the provided TriFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterator.
      B - The type of elements in the second Iterator.
      C - The type of elements in the third Iterator.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterator to be zipped.
      b - The second Iterator to be zipped.
      c - The third Iterator to be zipped.
      zipFunction - A TriFunction that takes an element from each Iterator and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • zip

      public static <A, B, C, R> ObjIterator<R> zip(Iterable<A> a, Iterable<B> b, Iterable<C> c, TriFunction<? super A,? super B,? super C,? extends R> zipFunction)
      Zips three Iterable objects into a single ObjIterator, which will iterate over the elements of each Iterable in parallel. The resulting elements are determined by the provided TriFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterable.
      B - The type of elements in the second Iterable.
      C - The type of elements in the third Iterable.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterable to be zipped.
      b - The second Iterable to be zipped.
      c - The third Iterable to be zipped.
      zipFunction - A TriFunction that takes an element from each Iterable and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • zip

      public static <A, B, R> ObjIterator<R> zip(Iterator<A> a, Iterator<B> b, A valueForNoneA, B valueForNoneB, BiFunction<? super A,? super B,? extends R> zipFunction)
      Zips two Iterators into a single ObjIterator, using default values when one iterator is exhausted. This method can be used to combine two Iterators into one, which will iterate over the elements of each Iterator in parallel. When one iterator is exhausted, the provided default values are used. The resulting elements are determined by the provided BiFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterator.
      B - The type of elements in the second Iterator.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterator to be zipped.
      b - The second Iterator to be zipped.
      valueForNoneA - The default value to be used when the first Iterator is exhausted.
      valueForNoneB - The default value to be used when the second Iterator is exhausted.
      zipFunction - A BiFunction that takes an element from each Iterator and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • zip

      public static <A, B, R> ObjIterator<R> zip(Iterable<A> a, Iterable<B> b, A valueForNoneA, B valueForNoneB, BiFunction<? super A,? super B,? extends R> zipFunction)
      Zips two Iterable objects into a single ObjIterator, using default values when one iterator is exhausted. This method can be used to combine two Iterable objects into one, which will iterate over the elements of each Iterable in parallel. When one iterator is exhausted, the provided default values are used. The resulting elements are determined by the provided BiFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterable.
      B - The type of elements in the second Iterable.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterable to be zipped.
      b - The second Iterable to be zipped.
      valueForNoneA - The default value to be used when the first Iterable is exhausted.
      valueForNoneB - The default value to be used when the second Iterable is exhausted.
      zipFunction - A BiFunction that takes an element from each Iterable and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • 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,? extends R> zipFunction)
      Zips three Iterators into a single ObjIterator, using default values when one iterator is exhausted. This method can be used to combine three Iterators into one, which will iterate over the elements of each Iterator in parallel. When one iterator is exhausted, the provided default values are used. The resulting elements are determined by the provided TriFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterator.
      B - The type of elements in the second Iterator.
      C - The type of elements in the third Iterator.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterator to be zipped.
      b - The second Iterator to be zipped.
      c - The third Iterator to be zipped.
      valueForNoneA - The default value to be used when the first Iterator is exhausted.
      valueForNoneB - The default value to be used when the second Iterator is exhausted.
      zipFunction - A TriFunction that takes an element from each Iterator and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • zip

      public static <A, B, C, R> ObjIterator<R> zip(Iterable<A> a, Iterable<B> b, Iterable<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, TriFunction<? super A,? super B,? super C,? extends R> zipFunction)
      Zips three Iterable objects into a single ObjIterator, using default values when one iterator is exhausted. This method can be used to combine three Iterable objects into one, which will iterate over the elements of each Iterable in parallel. When one iterator is exhausted, the provided default values are used. The resulting elements are determined by the provided TriFunction 'zipFunction'.
      Type Parameters:
      A - The type of elements in the first Iterable.
      B - The type of elements in the second Iterable.
      C - The type of elements in the third Iterable.
      R - The type of elements in the resulting ObjIterator.
      Parameters:
      a - The first Iterable to be zipped.
      b - The second Iterable to be zipped.
      c - The third Iterable to be zipped.
      valueForNoneA - The default value to be used when the first Iterable is exhausted.
      valueForNoneB - The default value to be used when the second Iterable is exhausted.
      valueForNoneC - The default value to be used when the third Iterable is exhausted.
      zipFunction - A TriFunction that takes an element from each Iterable and returns a new element for the resulting ObjIterator.
      Returns:
      An ObjIterator that will iterate over the elements created by 'zipFunction'.
    • unzip

      public static <T, A, B> BiIterator<A,B> unzip(Iterator<? extends T> iter, BiConsumer<? super T,Pair<A,B>> unzip)
      Unzips an Iterator into a BiIterator. The transformation is determined by the provided BiConsumer 'unzip'.
      Type Parameters:
      T - The type of elements in the original Iterator.
      A - The type of the first element in the resulting BiIterator.
      B - The type of the second element in the resulting BiIterator.
      Parameters:
      iter - The original Iterator to be unzipped.
      unzip - A BiConsumer that takes an element from the original Iterator and a Pair to be filled with the resulting elements for the BiIterator.
      Returns:
      A BiIterator that will iterate over the elements created by 'unzip'.
      See Also:
    • unzip

      public static <T, A, B> BiIterator<A,B> unzip(Iterable<? extends T> c, BiConsumer<? super T,Pair<A,B>> unzip)
      Unzips an Iterable into a BiIterator. The transformation is determined by the provided BiConsumer 'unzip'.
      Type Parameters:
      T - The type of elements in the original Iterable.
      A - The type of the first element in the resulting BiIterator.
      B - The type of the second element in the resulting BiIterator.
      Parameters:
      c - The original Iterable to be unzipped.
      unzip - A BiConsumer that takes an element from the original Iterable and a Pair to be filled with the resulting elements for the BiIterator.
      Returns:
      A BiIterator that will iterate over the elements created by 'unzip'.
      See Also:
    • unzipp

      @Deprecated @Beta public static <T, A, B, C> TriIterator<A,B,C> unzipp(Iterator<? extends T> iter, BiConsumer<? super T,Triple<A,B,C>> unzip)
      Unzips an Iterator into a TriIterator. The transformation is determined by the provided BiConsumer 'unzip'.
      Type Parameters:
      T - The type of elements in the original Iterator.
      A - The type of the first element in the resulting TriIterator.
      B - The type of the second element in the resulting TriIterator.
      C - The type of the third element in the resulting TriIterator.
      Parameters:
      iter - The original Iterator to be unzipped.
      unzip - A BiConsumer that takes an element from the original Iterator and a Triple to be filled with the resulting elements for the TriIterator.
      Returns:
      A TriIterator that will iterate over the elements created by 'unzip'.
      See Also:
    • unzipp

      @Deprecated @Beta public static <T, A, B, C> TriIterator<A,B,C> unzipp(Iterable<? extends T> c, BiConsumer<? super T,Triple<A,B,C>> unzip)
      Unzips an Iterable into a TriIterator. The transformation is determined by the provided BiConsumer 'unzip'.
      Type Parameters:
      T - The type of elements in the original Iterable.
      A - The type of the first element in the resulting TriIterator.
      B - The type of the second element in the resulting TriIterator.
      C - The type of the third element in the resulting TriIterator.
      Parameters:
      c - The original Iterable to be unzipped.
      unzip - A BiConsumer that takes an element from the original Iterable and a Triple to be filled with the resulting elements for the TriIterator.
      Returns:
      A TriIterator that will iterate over the elements created by 'unzip'.
      See Also:
    • advance

      public static long advance(Iterator<?> iterator, long numberToAdvance) throws IllegalArgumentException
      Note: copied from Google Guava under Apache license v2
      Calls next() on iterator, either numberToAdvance times or until hasNext() returns false, whichever comes first.
      Parameters:
      iterator -
      numberToAdvance -
      Returns:
      Throws:
      IllegalArgumentException
    • skip

      public static <T> ObjIterator<T> skip(Iterator<? extends T> iter, long n) throws IllegalArgumentException
      Skips the firstnelements of the provided Iterator and returns a new ObjIterator starting from the (n+1)th element. Ifnis greater than the size of the Iterator, an empty ObjIterator will be returned.
      This is a lazy evaluation operation. The skip action is only triggered when Iterator.hasNext() or Iterator.next() is called.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be skipped.
      n - The number of elements to skip from the beginning of the Iterator.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterator starting from the (n+1)th element.
      Throws:
      IllegalArgumentException - ifnis negative.
    • limit

      public static <T> ObjIterator<T> limit(Iterator<? extends T> iter, long count) throws IllegalArgumentException
      Returns a new ObjIterator that is limited to the specified count of elements from the original Iterator.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be limited.
      count - The maximum number of elements to be iterated over from the original Iterator.
      Returns:
      A new ObjIterator that will iterate over up to 'count' elements of the original Iterator.
      Throws:
      IllegalArgumentException - if 'count' is negative.
    • skipAndLimit

      public 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. This is a lazy evaluation operation. The skip action is only triggered when Iterator.hasNext() or Iterator.next() is called.
      Type Parameters:
      T -
      Parameters:
      iter -
      offset -
      count -
      Returns:
    • skipAndLimit

      public static <T> ObjIterator<T> skipAndLimit(Iterable<? extends T> iter, long offset, long count)
      Returns a new ObjIterator that starts from the specified offset and is limited to the specified count of elements from the original Iterable.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      iter - The original Iterable to be skipped and limited.
      offset - The number of elements to skip from the beginning of the Iterable.
      count - The maximum number of elements to be iterated over from the Iterable after skipping.
      Returns:
      A new ObjIterator that will iterate over up to 'count' elements of the original Iterable starting from the (offset+1)th element.
      Throws:
      IllegalArgumentException - if 'offset' or 'count' is negative.
    • skipNulls

      @Beta public static <T> ObjIterator<T> skipNulls(Iterable<? extends T> c)
      Returns a new ObjIterator with null elements removed.
      Type Parameters:
      T -
      Parameters:
      c -
      Returns:
    • skipNulls

      public static <T> ObjIterator<T> skipNulls(Iterator<? extends T> iter)
      Returns a new ObjIterator with null elements removed.
      Type Parameters:
      T -
      Parameters:
      iter -
      Returns:
    • distinct

      @Beta public static <T> ObjIterator<T> distinct(Iterable<? extends T> c)
      Returns a new ObjIterator with distinct elements from the original Iterable.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be processed for distinct elements.
      Returns:
      A new ObjIterator that will iterate over the distinct elements of the original Iterable.
    • distinct

      public static <T> ObjIterator<T> distinct(Iterator<? extends T> iter)
      Returns a new ObjIterator with distinct elements from the original Iterator.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be processed for distinct elements.
      Returns:
      A new ObjIterator that will iterate over the distinct elements of the original Iterator.
    • distinctBy

      @Beta public static <T> ObjIterator<T> distinctBy(Iterable<? extends T> c, Function<? super T,?> keyMapper) throws IllegalArgumentException
      Returns a new ObjIterator with distinct elements from the original Iterable based on a key derived from each element. The key for each element is determined by the provided Function 'keyMapper'.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be processed for distinct elements.
      keyMapper - A Function that takes an element from the Iterable and returns a key. Elements with the same key are considered duplicates.
      Returns:
      A new ObjIterator that will iterate over the distinct elements of the original Iterable based on the keys derived from 'keyMapper'.
      Throws:
      IllegalArgumentException
    • distinctBy

      public static <T> ObjIterator<T> distinctBy(Iterator<? extends T> iter, Function<? super T,?> keyMapper) throws IllegalArgumentException
      Returns a new ObjIterator with distinct elements from the original Iterator based on a key derived from each element. The key for each element is determined by the provided Function 'keyMapper'.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be processed for distinct elements.
      keyMapper - A Function that takes an element from the Iterator and returns a key. Elements with the same key are considered duplicates.
      Returns:
      A new ObjIterator that will iterate over the distinct elements of the original Iterator based on the keys derived from 'keyMapper'.
      Throws:
      IllegalArgumentException
    • filter

      @Beta public static <T> ObjIterator<T> filter(Iterable<? extends T> c, Predicate<? super T> predicate)
      Returns a new ObjIterator that only includes elements from the original Iterable that satisfy the provided Predicate.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be filtered.
      predicate - A Predicate that tests each element from the Iterable. Only elements that return 'true' are included in the resulting ObjIterator.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterable that satisfy the provided Predicate.
    • filter

      public static <T> ObjIterator<T> filter(Iterator<? extends T> iter, Predicate<? super T> predicate)
      Returns a new ObjIterator that only includes elements from the original Iterator that satisfy the provided Predicate.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be filtered.
      predicate - A Predicate that tests each element from the Iterator. Only elements that return 'true' are included in the resulting ObjIterator.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterator that satisfy the provided Predicate.
    • takeWhile

      @Beta public static <T> ObjIterator<T> takeWhile(Iterable<? extends T> c, Predicate<? super T> predicate)
      Returns a new ObjIterator that includes elements from the original Iterable as long as they satisfy the provided Predicate. The iteration stops when an element that does not satisfy the Predicate is encountered.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be processed.
      predicate - A Predicate that tests each element from the Iterable. The iteration continues as long as the Predicate returns 'true'.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterable as long as they satisfy the provided Predicate.
    • takeWhile

      public static <T> ObjIterator<T> takeWhile(Iterator<? extends T> iter, Predicate<? super T> predicate)
      Returns a new ObjIterator that includes elements from the original Iterator as long as they satisfy the provided Predicate. The iteration stops when an element that does not satisfy the Predicate is encountered.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be processed.
      predicate - A Predicate that tests each element from the Iterator. The iteration continues as long as the Predicate returns 'true'.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterator as long as they satisfy the provided Predicate.
    • takeWhileInclusive

      @Beta public static <T> ObjIterator<T> takeWhileInclusive(Iterable<? extends T> c, Predicate<? super T> predicate)
      Returns a new ObjIterator that includes elements from the original Iterable as long as they satisfy the provided Predicate. The iteration stops after the first element that does not satisfy the Predicate is encountered, but includes that element.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be processed.
      predicate - A Predicate that tests each element from the Iterable. The iteration continues as long as the Predicate returns 'true', including the first element that returns 'false'.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterable as long as they satisfy the provided Predicate, including the first element that does not satisfy the Predicate.
    • takeWhileInclusive

      public static <T> ObjIterator<T> takeWhileInclusive(Iterator<? extends T> iter, Predicate<? super T> predicate)
      Returns a new ObjIterator that includes elements from the original Iterator as long as they satisfy the provided Predicate. The iteration stops after the first element that does not satisfy the Predicate is encountered, but includes that element.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be processed.
      predicate - A Predicate that tests each element from the Iterator. The iteration continues as long as the Predicate returns 'true', including the first element that returns 'false'.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterator as long as they satisfy the provided Predicate, including the first element that does not satisfy the Predicate.
    • dropWhile

      @Beta public static <T> ObjIterator<T> dropWhile(Iterable<? extends T> c, Predicate<? super T> predicate)
      Returns a new ObjIterator that skips elements from the original Iterable as long as they satisfy the provided Predicate. The iteration begins when an element that does not satisfy the Predicate is encountered.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be processed.
      predicate - A Predicate that tests each element from the Iterable. The iteration skips elements as long as the Predicate returns 'true'.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterable starting from the first element that does not satisfy the provided Predicate.
    • dropWhile

      public static <T> ObjIterator<T> dropWhile(Iterator<? extends T> iter, Predicate<? super T> predicate)
      Returns a new ObjIterator that skips elements from the original Iterator as long as they satisfy the provided Predicate. The iteration begins when an element that does not satisfy the Predicate is encountered.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be processed.
      predicate - A Predicate that tests each element from the Iterator. The iteration skips elements as long as the Predicate returns 'true'.
      Returns:
      A new ObjIterator that will iterate over the elements of the original Iterator starting from the first element that does not satisfy the provided Predicate.
    • skipUntil

      @Beta public static <T> ObjIterator<T> skipUntil(Iterable<? extends T> c, Predicate<? super T> predicate)
      Skips elements in the provided Iterable until the provided Predicate returns true. This method can be used to ignore elements in an Iterable until a certain condition is met.
      Type Parameters:
      T - The type of elements in the original Iterable.
      Parameters:
      c - The original Iterable to be processed.
      predicate - A Predicate that tests elements from the original Iterable.
      Returns:
      An ObjIterator that will iterate over the remaining elements after the Predicate returns true for the first time.
    • skipUntil

      public static <T> ObjIterator<T> skipUntil(Iterator<? extends T> iter, Predicate<? super T> predicate)
      Skips elements in the provided Iterator until the provided Predicate returns true. This method can be used to ignore elements in an Iterator until a certain condition is met.
      Type Parameters:
      T - The type of elements in the original Iterator.
      Parameters:
      iter - The original Iterator to be processed.
      predicate - A Predicate that tests elements from the original Iterator.
      Returns:
      An ObjIterator that will iterate over the remaining elements after the Predicate returns true for the first time.
    • map

      @Beta public static <T, U> ObjIterator<U> map(Iterable<? extends T> c, Function<? super T,U> mapper)
      Transforms the elements of the given Iterable using the provided Function and returns a new ObjIterator with the transformed elements.
      Type Parameters:
      T - The type of elements in the original Iterable.
      U - The type of elements in the resulting ObjIterator.
      Parameters:
      c - The original Iterable to be transformed.
      mapper - A Function that takes an element from the Iterable and returns a transformed element for the resulting ObjIterator.
      Returns:
      A new ObjIterator that will iterate over the transformed elements of the original Iterable.
    • map

      public static <T, U> ObjIterator<U> map(Iterator<? extends T> iter, Function<? super T,U> mapper)
      Transforms the elements of the given Iterator using the provided Function and returns a new ObjIterator with the transformed elements.
      Type Parameters:
      T - The type of elements in the original Iterator.
      U - The type of elements in the resulting ObjIterator.
      Parameters:
      iter - The original Iterator to be transformed.
      mapper - A Function that takes an element from the Iterator and returns a transformed element for the resulting ObjIterator.
      Returns:
      A new ObjIterator that will iterate over the transformed elements of the original Iterator.
    • flatMap

      @Beta public static <T, U> ObjIterator<U> flatMap(Iterable<? extends T> c, Function<? super T,? extends Iterable<? extends U>> mapper)
      Transforms the elements of the given Iterable into Iterables using the provided Function and flattens the result into a new ObjIterator.
      Type Parameters:
      T - The type of elements in the original Iterable.
      U - The type of elements in the resulting ObjIterator.
      Parameters:
      c - The original Iterable to be transformed.
      mapper - A Function that takes an element from the Iterable and returns an Iterable of transformed elements.
      Returns:
      A new ObjIterator that will iterate over the transformed elements of the original Iterable.
    • flatMap

      public static <T, U> ObjIterator<U> flatMap(Iterator<? extends T> iter, Function<? super T,? extends Iterable<? extends U>> mapper)
      Transforms the elements of the given Iterator into Iterables using the provided Function and flattens the result into a new ObjIterator.
      Type Parameters:
      T - The type of elements in the original Iterator.
      U - The type of elements in the resulting ObjIterator.
      Parameters:
      iter - The original Iterator to be transformed.
      mapper - A Function that takes an element from the Iterator and returns an Iterable of transformed elements.
      Returns:
      A new ObjIterator that will iterate over the transformed elements of the original Iterator.
    • flatmap

      @Beta public static <T, U> ObjIterator<U> flatmap(Iterable<? extends T> c, Function<? super T,? extends U[]> mapper)
      Transforms the elements of the given Iterable into arrays using the provided Function and flattens the result into a new ObjIterator.
      Type Parameters:
      T - The type of elements in the original Iterable.
      U - The type of elements in the resulting ObjIterator.
      Parameters:
      c - The original Iterable to be transformed.
      mapper - A Function that takes an element from the Iterable and returns an array of transformed elements.
      Returns:
      A new ObjIterator that will iterate over the transformed elements of the original Iterable.
    • flatmap

      public static <T, U> ObjIterator<U> flatmap(Iterator<? extends T> iter, Function<? super T,? extends U[]> mapper)
      Transforms the elements of the given Iterator into arrays using the provided Function and flattens the result into a new ObjIterator.
      Type Parameters:
      T - The type of elements in the original Iterator.
      U - The type of elements in the resulting ObjIterator.
      Parameters:
      iter - The original Iterator to be transformed.
      mapper - A Function that takes an element from the Iterator and returns an array of transformed elements.
      Returns:
      A new ObjIterator that will iterate over the transformed elements of the original Iterator.
    • forEach

      public static <T, E extends Exception> void forEach(Iterator<? extends T> iter, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Iterator
      Type Parameters:
      T - The type of elements in the original Iterator.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iter - The original Iterator to be processed.
      elementConsumer - A Consumer that performs an action on each element in the Iterator.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Iterator<? extends T> iter, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws E, E2
      Performs an action for each element of the given Iterator and executes a final action upon completion.
      Type Parameters:
      T - The type of elements in the original Iterator.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iter - The original Iterator to be processed.
      elementConsumer - A Consumer that performs an action on each element in the Iterator.
      onComplete - A Runnable action to be executed after all elements in the Iterator have been processed.
      Throws:
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.
    • forEach

      public static <T, E extends Exception> void forEach(Iterator<? extends T> iter, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count.
      Type Parameters:
      T - The type of elements in the original Iterator.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iter - The original Iterator to be processed.
      offset - The starting point in the Iterator from where elements will be processed.
      count - The maximum number of elements to be processed from the Iterator.
      elementConsumer - A Consumer that performs an action on each element in the Iterator.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Iterator<? extends T> iter, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws E, E2
      Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count. After all elements have been processed, a final action is executed.
      Type Parameters:
      T - The type of elements in the original Iterator.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iter - The original Iterator to be processed.
      offset - The starting point in the Iterator from where elements will be processed.
      count - The maximum number of elements to be processed from the Iterator.
      elementConsumer - A Consumer that performs an action on each element in the Iterator.
      onComplete - A Runnable action to be executed after all elements in the Iterator have been processed.
      Throws:
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.
    • forEach

      public static <T, E extends Exception> void forEach(Iterator<? extends T> iter, long offset, long count, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count. This method also supports multi-threading with a specified number of threads and queue size.
      Type Parameters:
      T - The type of elements in the original Iterator.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iter - The original Iterator to be processed.
      offset - The starting point in the Iterator from where elements will be processed.
      count - The maximum number of elements to be processed from the Iterator.
      processThreadNum - The number of threads to be used for processing.
      queueSize - The size of the queue for holding elements before processing.
      elementConsumer - A Consumer that performs an action on each element in the Iterator.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Iterator<? extends T> iter, long offset, long count, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws E, E2
      Performs an action for each element of the given Iterator, starting from a specified offset and up to a specified count. This method also supports multi-threading with a specified number of threads and queue size.
      Type Parameters:
      T - The type of elements in the original Iterator.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iter - The original Iterator to be processed.
      offset - The starting point in the Iterator from where processing should begin.
      count - The maximum number of elements to process.
      processThreadNum - The number of threads to be used for processing.
      queueSize - The size of the queue to hold the processing records. Default size is 1024.
      elementConsumer - A Consumer that performs an action on each element in the Iterator.
      onComplete - A Runnable action to be performed once all elements have been processed.
      Throws:
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.
    • forEach

      public static <T, E extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Collection of Iterators.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws E, E2
      Performs an action for each element of the given Collection of Iterators. After all elements have been processed, a final action is executed.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      onComplete - A Runnable action to be executed after all elements in the Iterators have been processed.
      Throws:
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.
    • forEach

      public static <T, E extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      offset - The starting point in the Iterators from where elements will be processed.
      count - The maximum number of elements to be processed from the Iterators.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws E, E2
      Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count. After all elements have been processed, a final action is executed.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      offset - The starting point in the Iterators from where elements will be processed.
      count - The maximum number of elements to be processed from the Iterators.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      onComplete - A Runnable action to be executed after all elements in the Iterators have been processed.
      Throws:
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.
    • forEach

      public static <T, E extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Collection of Iterators. This method also supports multi-threading with a specified number of threads for reading.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      readThreadNum - The number of threads to be used for reading elements from the Iterators.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws E, E2
      Performs an action for each element of the given Collection of Iterators. This method also supports multi-threading with a specified number of threads for reading and processing, and a queue for holding elements before processing. After all elements have been processed, a final action is executed.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      readThreadNum - The number of threads to be used for reading elements from the Iterators.
      processThreadNum - The number of threads to be used for processing elements.
      queueSize - The size of the queue for holding elements before processing.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      onComplete - A Runnable action to be executed after all elements in the Iterators have been processed.
      Throws:
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.
    • forEach

      public static <T, E extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer) throws E
      Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count. This method also supports multi-threading with a specified number of threads for reading and processing, and a queue for holding elements before processing.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      offset - The starting point in the Iterators from where elements will be processed.
      count - The maximum number of elements to be processed from the Iterators.
      readThreadNum - The number of threads to be used for reading elements from the Iterators.
      processThreadNum - The number of threads to be used for processing elements.
      queueSize - The size of the queue for holding elements before processing.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      Throws:
      E - if the elementConsumer encounters an exception.
    • forEach

      public static <T, E extends Exception, E2 extends Exception> void forEach(Collection<? extends Iterator<? extends T>> iterators, long offset, long count, int readThreadNum, int processThreadNum, int queueSize, Throwables.Consumer<? super T,E> elementConsumer, Throwables.Runnable<E2> onComplete) throws IllegalArgumentException, E, E2
      Performs an action for each element of the given Collection of Iterators, starting from a specified offset and up to a specified count. This method also supports multi-threading with a specified number of threads for reading and processing, and a queue size for holding the processing records.
      Type Parameters:
      T - The type of elements in the original Iterators.
      E - The type of exception that can be thrown by the elementConsumer.
      E2 - The type of exception that can be thrown by the onComplete action.
      Parameters:
      iterators - The original Collection of Iterators to be processed.
      offset - The starting point in the Iterators from where processing should begin.
      count - The maximum number of elements to process.
      readThreadNum - The number of threads to be used for reading.
      processThreadNum - The number of threads to be used for processing.
      queueSize - The size of the queue to hold the processing records.
      elementConsumer - A Consumer that performs an action on each element in the Iterators.
      onComplete - A Runnable action to be performed once all elements have been processed.
      Throws:
      IllegalArgumentException - if 'offset' or 'count' is negative.
      E - if the elementConsumer encounters an exception.
      E2 - if the onComplete action encounters an exception.