public class CloseableIterators extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> CloseableIterator<T> |
autoClose(CloseableIterator<? extends T> iterator)
Autoclose the iterator when exhausted or if an exception is thrown.
|
static <T> CloseableIterator<T> |
chain(CloseableIterator<? extends T>... iterators)
Combines multiple closeable iterators into a single closeable iterator.
|
static <T> CloseableIterator<T> |
chain(Iterator<? extends CloseableIterator<? extends T>> iterator)
Combines multiple closeable iterators into a single closeable iterator.
|
static <T> CloseableIterator<T> |
concat(CloseableIterator<? extends Iterator<? extends T>> iterators)
Combines multiple iterators into a single closeable iterator.
|
static <T> CloseableIterator<T> |
distinct(CloseableIterator<T> iterator)
If we can assume the closeable iterator is sorted, return the distinct elements.
|
static <T> CloseableIterator<T> |
emptyIterator()
Returns an empty closeable iterator.
|
static <T> CloseableIterator<T> |
filter(CloseableIterator<?> iterator,
Class<T> type)
Returns all instances of class
type in unfiltered. |
static <T> CloseableIterator<T> |
filter(CloseableIterator<T> iterator,
Predicate<T> filter)
Returns the elements of
unfiltered that satisfy a predicate. |
static <T> CloseableIterator<List<T>> |
groupBy(CloseableIterator<? extends T> iterator,
Function<? super T,?> groupingFunction)
Divides a closeableiterator into unmodifiable sublists of equivalent elements.
|
static <T> CloseableIterator<T> |
limit(CloseableIterator<T> iterator,
int limitSize)
Creates a closeable iterator returning the first
limitSize elements of the
given closeable iterator. |
static <T> CloseableIterator<List<T>> |
paddedParition(CloseableIterator<T> iterator,
int size)
Divides a closeableiterator into unmodifiable sublists of the given size, padding
the final iterator with null values if necessary.
|
static <T> CloseableIterator<List<T>> |
partition(CloseableIterator<T> iterator,
int size)
Divides a closeableiterator into unmodifiable sublists of the given size (the final
list may be smaller).
|
static <T> PeekingCloseableIterator<T> |
peekingIterator(CloseableIterator<T> iterator)
Returns a
PeekingCloseableIterator backed by the given closeable iterator. |
static <T> CloseableIterator<T> |
singletonIterator(T value)
Returns an iterator containing only
value. |
static <F,T> CloseableIterator<T> |
transform(CloseableIterator<F> iterator,
Function<F,T> function)
Returns a closeable iterator that applies
function to each element of fromIterator. |
static <T> CloseableIterator<T> |
wrap(Iterator<T> iterator)
Creates a
CloseableIterator from a standard iterator. |
public static <T> CloseableIterator<T> distinct(CloseableIterator<T> iterator)
public static <T> CloseableIterator<List<T>> groupBy(CloseableIterator<? extends T> iterator, Function<? super T,?> groupingFunction)
[1, 3, 2, 4, 5] with a function grouping even and odd numbers
yields [[1, 3], [2, 4], [5] all in the original order.
The returned lists implement RandomAccess.
public static <T> CloseableIterator<T> concat(CloseableIterator<? extends Iterator<? extends T>> iterators)
inputs.
The input iterators are not polled until necessary.public static <T> CloseableIterator<T> emptyIterator()
public static <T> CloseableIterator<T> filter(CloseableIterator<T> iterator, Predicate<T> filter)
unfiltered that satisfy a predicate.public static <T> CloseableIterator<T> filter(CloseableIterator<?> iterator, Class<T> type)
type in unfiltered. The
returned closeable iterator has elements whose class is type or a subclass of
type.public static <T> CloseableIterator<T> limit(CloseableIterator<T> iterator, int limitSize)
limitSize elements of the
given closeable iterator. If the original closeable iterator does not contain that many
elements, the returned closeable iterator will have the same behavior as the original.public static <T> CloseableIterator<List<T>> paddedParition(CloseableIterator<T> iterator, int size)
[a, b, c, d, e] with a partition size of 3
yields [[a, b, c], [d, e, null]] -- an outer iterator containing
two inner lists of three elements each, all in the original order.
The returned lists implement RandomAccess.
public static <T> CloseableIterator<List<T>> partition(CloseableIterator<T> iterator, int size)
[a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer iterator containing two inner lists of
three and two elements, all in the original order.
The returned lists implement RandomAccess.
public static <T> PeekingCloseableIterator<T> peekingIterator(CloseableIterator<T> iterator)
PeekingCloseableIterator backed by the given closeable iterator.
Calls to peek do not change the state of the iterator. The subsequent call to next
after peeking will always return the same value.public static <T> CloseableIterator<T> singletonIterator(T value)
value.
The Iterable equivalent of this method is Collections.singleton(T).
public static <F,T> CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F,T> function)
function to each element of fromIterator.@SafeVarargs public static <T> CloseableIterator<T> chain(CloseableIterator<? extends T>... iterators)
inputs.
The input iterators are not polled until necessary.
As each closeable iterator is exhausted, it is closed before moving onto the next closeable
iterator. A call to close on the returned closeable iterator will quietly close all of
the closeable iterators in inputs which have not been exhausted.public static <T> CloseableIterator<T> chain(Iterator<? extends CloseableIterator<? extends T>> iterator)
inputs.
The input iterators are not polled until necessary.
As each closeable iterator is exhausted, it is closed before moving onto the next closeable
iterator. A call to close on the returned closeable iterator will quietly close all of
the closeable iterators in inputs which have not been exhausted.public static <T> CloseableIterator<T> autoClose(CloseableIterator<? extends T> iterator)
limit() is an example of one method which can
prevent the completion of an iterator. For instance limit(autoClose(iterator), 1) will not close the
resource if there is more than 1 element, but autoClose(limit(iterator, 1)) will close the underlying
resource.public static <T> CloseableIterator<T> wrap(Iterator<T> iterator)
CloseableIterator from a standard iterator.Copyright © 2018 Calrissian. All rights reserved.