public class CloseableIterables extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> CloseableIterable<T> |
autoClose(CloseableIterable<? extends T> iterable)
Autoclose the
iterable when its iterator is exhausted or if an exception is thrown. |
static <T> CloseableIterable<T> |
chain(CloseableIterable<? extends T>... iterables)
Combines multiple closeable iterables into a single closeable iterable.
|
static <T> CloseableIterable<T> |
chain(Iterable<? extends CloseableIterable<? extends T>> iterables)
Combines multiple closeable iterables into a single closeable iterable.
|
static <T> CloseableIterable<T> |
concat(CloseableIterable<? extends Iterable<? extends T>> inputs)
Combines multiple iterables into a single closeable iterable.
|
static <T> CloseableIterable<T> |
cycle(CloseableIterable<T> iterable)
Returns a closeable iterable whose iterators cycle indefinitely over the elements of
iterable. |
static <T> CloseableIterable<T> |
distinct(CloseableIterable<T> iterable)
If we can assume the closeable iterable is sorted, return the distinct elements.
|
static <T> CloseableIterable<T> |
emptyIterable()
Returns an empty closeable iterable
|
static <T> CloseableIterable<T> |
filter(CloseableIterable<?> iterable,
Class<T> type)
Returns all instances of class
type in unfiltered. |
static <T> CloseableIterable<T> |
filter(CloseableIterable<T> iterable,
Predicate<? super T> filter)
Returns the elements of
unfiltered that satisfy a predicate. |
static <T> CloseableIterable<List<T>> |
groupBy(CloseableIterable<? extends T> iterable,
Function<? super T,?> groupingFunction)
Divides an iterable into unmodifiable sublists of equivalent elements.
|
static <T> CloseableIterable<T> |
limit(CloseableIterable<T> iterable,
int limitSize)
Creates a closeable iterable with the first
limitSize elements of the given
closeable iterable. |
static <T> CloseableIterable<List<T>> |
paddedParition(CloseableIterable<T> iterable,
int size)
Divides a closeable iterable into unmodifiable sublists of the given size, padding
the final list with null values if necessary.
|
static <T> CloseableIterable<List<T>> |
partition(CloseableIterable<T> iterable,
int size)
Divides a closeable iterable into unmodifiable sublists of the given size (the final
iterable may be smaller).
|
static <T> CloseableIterable<T> |
singleton(T value)
Returns a closeable iterable containing only
value. |
static <T> CloseableIterable<T> |
skip(CloseableIterable<T> iterable,
int numberToSkip)
Returns a view of
iterable that skips its first
numberToSkip elements. |
static <F,T> CloseableIterable<T> |
transform(CloseableIterable<F> iterable,
Function<? super F,? extends T> function)
Returns an iterable that applies
function to each element of fromIterable. |
static <T> CloseableIterable<T> |
wrap(Iterable<T> iterable)
Creates a
CloseableIterable from a standard iterable. |
public static <T> CloseableIterable<T> distinct(CloseableIterable<T> iterable)
public static <T> CloseableIterable<List<T>> groupBy(CloseableIterable<? extends T> iterable, 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> CloseableIterable<T> concat(CloseableIterable<? extends Iterable<? extends T>> inputs)
inputs. The input iterators are not polled until
necessary.public static <T> CloseableIterable<T> cycle(CloseableIterable<T> iterable)
iterable.
That iterator supports remove() if iterable.iterator()
does. After remove() is called, subsequent cycles omit the removed
element, which is no longer in iterable. The iterator's
hasNext() method returns true until iterable is
empty.
Warning: Typical uses of the resulting iterator may produce an
infinite loop. You should use an explicit break or be certain that
you will eventually remove all the elements. The close method should be expicitly
called when done with iteration. Tools such as CloseableIterables.autoClose()
will not work.
public static <T> CloseableIterable<T> filter(CloseableIterable<?> iterable, Class<T> type)
type in unfiltered. The
returned closeable iterable has elements whose class is type or a subclass of
type. The returned iterable's iterator does not support
remove().public static <T> CloseableIterable<T> filter(CloseableIterable<T> iterable, Predicate<? super T> filter)
unfiltered that satisfy a predicate. The
resulting closeable iterable's iterator does not support remove().public static <T> CloseableIterable<T> limit(CloseableIterable<T> iterable, int limitSize)
limitSize elements of the given
closeable iterable. If the original closeable iterable does not contain that many
elements, the returned iterator will have the same behavior as the original
closeable iterable. The returned closeable iterable's iterator supports remove()
if the original iterator does.public static <T> CloseableIterable<List<T>> paddedParition(CloseableIterable<T> iterable, int size)
[a, b, c, d, e] with a partition size of 3
yields [[a, b, c], [d, e, null]] -- an outer iterable containing
two inner lists of three elements each, all in the original order.
Iterators returned by the returned closeableiterable do not support the Iterator.remove() method.
public static <T> CloseableIterable<List<T>> partition(CloseableIterable<T> iterable, int size)
[a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer iterable containing two inner lists of
three and two elements, all in the original order.
Iterators returned by the returned iterable do not support the Iterator.remove() method.
public static <T> CloseableIterable<T> skip(CloseableIterable<T> iterable, int numberToSkip)
iterable that skips its first
numberToSkip elements. If iterable contains fewer than
numberToSkip elements, the returned closeableiterable skips all of its
elements.
Modifications to the underlying CloseableIterable before a call to
iterator() are reflected in the returned iterator. That is, the
iterator skips the first numberToSkip elements that exist when the
Iterator is created, not when skip() is called.
The returned closeableiterable's iterator supports remove() if the
iterator of the underlying iterable supports it. Note that it is
not possible to delete the last skipped element by immediately
calling remove() on that iterator, as the Iterator
contract states that a call to remove() before a call to
next() will throw an IllegalStateException.
public static <F,T> CloseableIterable<T> transform(CloseableIterable<F> iterable, Function<? super F,? extends T> function)
function to each element of fromIterable.@SafeVarargs public static <T> CloseableIterable<T> chain(CloseableIterable<? extends T>... iterables)
inputs. The input iterators are not polled until
necessary.public static <T> CloseableIterable<T> chain(Iterable<? extends CloseableIterable<? extends T>> iterables)
inputs. The input iterators are not polled until
necessary.public static <T> CloseableIterable<T> autoClose(CloseableIterable<? extends T> iterable)
iterable when its iterator is exhausted or if an exception is thrown.
Note that when using this method the order of calls matters. limit() is an example of one method which can
prevent the completion of an iterator. For instance limit(autoClose(iterable), 1) will not close the
resource if there is more than 1 element, but autoClose(limit(iterable, 1)) will close the underlying
resource.public static <T> CloseableIterable<T> emptyIterable()
The equivalent of this method is Collections.emptySet().
public static <T> CloseableIterable<T> singleton(T value)
value.
The equivalent of this method is Collections.singleton(T).
public static <T> CloseableIterable<T> wrap(Iterable<T> iterable)
CloseableIterable from a standard iterable. If iterable is already
a CloseableIterable it will simply be returned as is.Copyright © 2018 Calrissian. All rights reserved.