java.lang.Object
org.elasticsearch.common.collect.Iterators
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Iterator<T> static <T,U> Iterator <U> enumerate(Iterator<? extends T> input, BiFunction<Integer, T, ? extends U> fn) Enumerates the elements of an iterator together with their index, using a function to combine the pair together into the final items produced by the iterator.static <T> booleanequals(Iterator<? extends T> iterator1, Iterator<? extends T> iterator2, BiPredicate<T, T> itemComparer) static <T> Iterator<T> failFast(Iterator<T> input, BooleanSupplier isFailingSupplier) Returns an iterator over the same items as the providedinputexcept that it stops yielding items (i.e.static <T> Iterator<T> static <T,U> Iterator <U> static <T> Iterator<T> forArray(T[] array) static <T> Iterator<T> forRange(int lowerBoundInclusive, int upperBoundExclusive, IntFunction<? extends T> fn) static <T> Iterator<T> fromSupplier(Supplier<? extends T> input) Adapts aSupplierobject into an iterator.static <T> inthashCode(Iterator<? extends T> iterator, ToIntFunction<T> itemHashcode) static <T> Iterator<T> Returns an iterator that yields at most the firstnelements of the providedinputiterator.static <T,U> Iterator <U> static <T> Iterator<T> single(T element) Returns a single element iterator over the supplied value.static <T> List<T> Returns a list containing the elements of the providediterator.
-
Constructor Details
-
Iterators
public Iterators()
-
-
Method Details
-
single
Returns a single element iterator over the supplied value. -
concat
-
forArray
-
forRange
public static <T> Iterator<T> forRange(int lowerBoundInclusive, int upperBoundExclusive, IntFunction<? extends T> fn) -
map
-
filter
- Parameters:
input- An iterator over non-null values.predicate- The predicate with which to filter the input.- Returns:
- an iterator which returns the values from
inputwhich matchpredicate.
-
limit
Returns an iterator that yields at most the firstnelements of the providedinputiterator. -
toList
Returns a list containing the elements of the providediterator. -
flatMap
-
failFast
Returns an iterator over the same items as the providedinputexcept that it stops yielding items (i.e. starts returningfalsefromIterator.hasNext()on failure. -
enumerate
public static <T,U> Iterator<U> enumerate(Iterator<? extends T> input, BiFunction<Integer, T, ? extends U> fn) Enumerates the elements of an iterator together with their index, using a function to combine the pair together into the final items produced by the iterator.An example of its usage to enumerate a list of names together with their positional index in the list:
Iterator<String> nameIterator = ...; Iterator<Tuple<Integer, String>> enumeratedNames = Iterators.enumerate(nameIterator, Tuple::new); enumeratedNames.forEachRemaining(tuple -> System.out.println("Index: " + t.v1() + ", Name: " + t.v2()));- Type Parameters:
T- The object type contained in the original iteratorU- The object type that results from combining the original entry with its index in the iterator- Parameters:
input- The iterator to wrapfn- A function that takes the index for an entry and the entry itself, returning an item that combines them together- Returns:
- An iterator that combines elements together with their indices in the underlying collection
-
fromSupplier
Adapts aSupplierobject into an iterator. The resulting iterator will return values from the delegate Supplier until the delegate returns anullvalue. Once the delegate returnsnull, the iterator will claim to be empty.An example of its usage to iterate over a queue while draining it at the same time:
LinkedList<String> names = ...; assert names.size() != 0; Iterator<String> nameIterator = Iterator.fromSupplier(names::pollFirst); nameIterator.forEachRemaining(System.out::println) assert names.size() == 0;- Type Parameters:
T- The object type returned from the supplier function- Parameters:
input- ASupplierthat returns null when no more elements should be returned from the iterator- Returns:
- An iterator that returns elements by calling the supplier until a null value is returned
-
equals
public static <T> boolean equals(Iterator<? extends T> iterator1, Iterator<? extends T> iterator2, BiPredicate<T, T> itemComparer) -
hashCode
-