public final class Interactive
extends java.lang.Object
Iterable based) counterparts
of the Reactive operators.
The implementations of the operators are partially derived from the Reactive operators.
Reactive| Modifier and Type | Class and Description |
|---|---|
static class |
Interactive.LinkedBuffer<T>
A linked buffer, which can be only filled and queried.
|
| Modifier and Type | Method and Description |
|---|---|
static <T,U,V> java.lang.Iterable<V> |
aggregate(java.lang.Iterable<? extends T> source,
Func2<? super U,? super T,? extends U> sum,
Func2<? super U,? super java.lang.Integer,? extends V> divide)
Creates an iterable which traverses the source iterable and maintains a running sum value based
on the
sum function parameter. |
static <T> java.lang.Iterable<java.lang.Boolean> |
all(java.lang.Iterable<? extends T> source,
Func1<? super T,java.lang.Boolean> predicate)
Returns an iterable which contains true if all
elements of the source iterable satisfy the predicate.
|
static <T> java.lang.Iterable<java.lang.Boolean> |
any(java.lang.Iterable<? extends T> source,
Func1<? super T,java.lang.Boolean> predicate)
Tests if there is any element of the source that satisfies the given predicate function.
|
static <T> java.lang.Iterable<java.lang.Boolean> |
any(java.lang.Iterable<T> source)
Determines if the given source has any elements at all.
|
static <T,V extends java.lang.Comparable<? super V>> |
argAndMax(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends V> valueSelector)
Returns a pair of the maximum argument and value from the given sequence.
|
static <T,V> Pair<T,V> |
argAndMax(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends V> valueSelector,
java.util.Comparator<? super V> valueComparator)
Returns a pair of the maximum argument and value from the given sequence.
|
static <T,V extends java.lang.Comparable<? super V>> |
argAndMin(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends V> valueSelector)
Returns a pair of the maximum argument and value from the given sequence.
|
static <T,V> Pair<T,V> |
argAndMin(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends V> valueSelector,
java.util.Comparator<? super V> valueComparator)
Returns a pair of the minimum argument and value from the given sequence.
|
static java.lang.Iterable<java.math.BigDecimal> |
averageBigDecimal(java.lang.Iterable<java.math.BigDecimal> source)
Returns an iterable which averages the source BigDecimal values.
|
static java.lang.Iterable<java.math.BigDecimal> |
averageBigInteger(java.lang.Iterable<java.math.BigInteger> source)
Returns an iterable which averages the source BigInteger values.
|
static java.lang.Iterable<java.lang.Double> |
averageDouble(java.lang.Iterable<java.lang.Double> source)
Returns an iterable which averages the source Double values.
|
static java.lang.Iterable<java.lang.Float> |
averageFloat(java.lang.Iterable<java.lang.Float> source)
Returns an iterable which averages the source Float values.
|
static java.lang.Iterable<java.lang.Double> |
averageInt(java.lang.Iterable<java.lang.Integer> source)
Returns an iterable which averages the source Integer values.
|
static java.lang.Iterable<java.lang.Double> |
averageLong(java.lang.Iterable<java.lang.Long> source)
Returns an iterable which averages the source Integer values.
|
static <T> java.lang.Iterable<java.util.List<T>> |
buffer(java.lang.Iterable<? extends T> source,
int bufferSize)
Returns an iterable which buffers the source elements
into
bufferSize lists. |
static <T> java.lang.Iterable<T> |
cast(java.lang.Iterable<?> source,
java.lang.Class<T> token)
Casts the source iterable into a different type by using a type token.
|
static <T> java.lang.Iterable<T> |
catchException(java.lang.Iterable<? extends T> source)
Creates an iterable which if iterates over the source and encounters an exception, it simply stops the iteration, consuming the exception.
|
static <T> java.lang.Iterable<T> |
catchException(java.lang.Iterable<? extends T> source,
Func1<? super java.lang.Throwable,? extends java.lang.Iterable<? extends T>> handler)
Creates an iterable which if iterates over the source and encounters an exception,
the iteration is continued on the new iterable returned by the handler function.
|
static <T> java.lang.Iterable<T> |
concat(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Concatenate the given iterable sources one
after another in a way, that calling the second
iterator()
only happens when there is no more element in the first iterator. |
static <T> java.lang.Iterable<T> |
concat(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Concatenate the given iterable sources one
after another in a way, that calling the second
iterator()
only happens when there is no more element in the first iterator. |
static <T> java.lang.Iterable<java.lang.Boolean> |
contains(java.lang.Iterable<? extends T> source,
T value)
Returns an iterable which checks for the existence of the supplied
value by comparing the elements of the source iterable using reference
and
equals(). |
static <T> java.lang.Iterable<java.lang.Integer> |
count(java.lang.Iterable<T> source)
Counts the elements of the iterable source by using a 32 bit
int. |
static <T> java.lang.Iterable<java.lang.Long> |
countLong(java.lang.Iterable<T> source)
Counts the elements of the iterable source by using a 64 bit
long. |
static <T> java.lang.Iterable<T> |
defer(Func0<? extends java.lang.Iterable<T>> func)
Defers the source iterable creation to registration time and
calls the given
func for the actual source. |
static <T> java.lang.Iterable<T> |
dematerialize(java.lang.Iterable<? extends Option<? extends T>> source)
Convert the source materialized elements into normal iterator behavior.
|
static <T> java.util.Iterator<T> |
differentAggregator(java.util.Iterator<? extends T> src,
Func2<? super T,? super T,java.lang.Boolean> isDifferent,
Action2<T,? super T> aggregate)
Aggregates subsequent elements (in place) as long as
isDifferent returns false. |
static <T> java.lang.Iterable<T> |
distinct(java.lang.Iterable<? extends T> source)
Returns an iterable which filters its elements based if they were ever seen before in
the current iteration.
|
static <T,U,V> java.lang.Iterable<V> |
distinct(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector,
Func1<? super T,? extends V> valueSelector)
Returns an iterable which filters its elements by an unique key
in a way that when multiple source items produce the same key, only
the first one ever seen gets relayed further on.
|
static <T> java.lang.Iterable<T> |
distinctNext(java.lang.Iterable<? extends T> source)
Creates an iterable which ensures that subsequent values of T are not equal (reference and equals).
|
static <T,U> java.lang.Iterable<T> |
distinctNext(java.lang.Iterable<? extends T> source,
Func1<T,U> keyExtractor)
Creates an iterable which ensures that subsequent values of
T are not equal in respect to the extracted keys (reference and equals).
|
static <T> java.lang.Iterable<T> |
doWhile(java.lang.Iterable<? extends T> source,
Func0<java.lang.Boolean> gate)
Returns an iterable which reiterates over and over again on
source
as long as the gate is true. |
static boolean |
elementsEqual(java.lang.Iterable<?> iterable1,
java.lang.Iterable<?> iterable2)
Determines whether two iterables contain equal elements in the same
order.
|
static boolean |
elementsEqual(java.util.Iterator<?> iterator1,
java.util.Iterator<?> iterator2)
Compares two iterators wether they contain the same element in terms of numbers
and nullsafe Object.equals().
|
static <T> java.lang.Iterable<T> |
empty()
Returns an empty iterable which will not produce elements.
|
static <T> java.lang.Iterable<T> |
endWith(java.lang.Iterable<? extends T> source,
T value)
Creates an iterable sequence which returns all elements from source
followed by the supplied value as last.
|
static <T> java.lang.Iterable<T> |
finish(java.lang.Iterable<? extends T> source,
Action0 action)
Returns an iterable which executes the given action after
the stream completes.
|
static <T> T |
first(java.lang.Iterable<? extends T> src)
Returns the first element from the iterable sequence or
throws a NoSuchElementException.
|
static <T,U> java.lang.Iterable<U> |
forEach(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Returns an iterable which runs the source iterable and
returns elements from the iterable returned by the function call.
|
static <T> java.lang.Iterable<T> |
generate(T seed,
Func1<? super T,java.lang.Boolean> predicate,
Func1<? super T,? extends T> next)
A generator function which returns Ts based on the termination condition and the way it computes the next values.
|
static <T> java.lang.Iterable<T> |
generate(T seed,
Func1<? super T,java.lang.Boolean> predicate,
Func1<? super T,? extends T> next,
long initialDelay,
long betweenDelay,
java.util.concurrent.TimeUnit unit)
A generator function which returns Ts based on the termination condition and the way it computes the next values,
but the first T to be returned is preceded by an
initialDelay amount of wait and each
subsequent element is then generated after betweenDelay sleep. |
static <T,V> java.lang.Iterable<GroupedIterable<V,T>> |
groupBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends V> keySelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values of T into GroupedIterables,
which can be iterated over later on.
|
static <T,U,V> java.lang.Iterable<GroupedIterable<V,U>> |
groupBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends V> keySelector,
Func1<? super T,? extends U> valueSelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values extracted by valueSelector into GroupedIterables,
which can be iterated over later on.
|
static <T> java.lang.Iterable<T> |
invoke(java.lang.Iterable<? extends T> source,
Action1<? super T> action)
Construct a new iterable which will invoke the specified action
before the source value gets relayed through it.
|
static <T> java.lang.Iterable<T> |
invoke(java.lang.Iterable<? extends T> source,
Action1<? super T> next,
Action0 finish)
Returns an iterable which invokes the given
next
action for each element and the finish action when
the source completes. |
static <T> java.lang.Iterable<T> |
invoke(java.lang.Iterable<? extends T> source,
Action1<? super T> next,
Action1<? super java.lang.Throwable> error)
Returns an iterable which invokes the given
next
action for each element and error when an exception is thrown. |
static <T> java.lang.Iterable<T> |
invoke(java.lang.Iterable<? extends T> source,
Action1<? super T> next,
Action1<? super java.lang.Throwable> error,
Action0 finish)
Returns an iterable which invokes the given
next
action for each element and the finish action when
the source completes and error when an exception is thrown. |
static java.lang.Iterable<java.lang.Boolean> |
isEmpty(java.lang.Iterable<?> source)
Returns a single true if the target iterable is empty.
|
static java.lang.Iterable<java.lang.String> |
join(java.lang.Iterable<?> source,
java.lang.String separator)
Concatenates the source strings one after another and uses the given separator.
|
static <T> T |
last(java.lang.Iterable<? extends T> source)
Returns the last element of the iterable or throws a
NoSuchElementException if the iterable is empty. |
static <T> java.lang.Iterable<Option<T>> |
materialize(java.lang.Iterable<? extends T> source)
Transforms the sequence of the source iterable into an option sequence of
Option.some(), Option.none() and Option.error() values, depending on
what the source's hasNext() and next() produces.
|
static <T extends java.lang.Comparable<? super T>> |
max(java.lang.Iterable<? extends T> source)
Returns the maximum value of the given iterable source.
|
static <T> java.lang.Iterable<T> |
max(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns the maximum value of the given iterable source in respect to the supplied comparator.
|
static <T extends java.lang.Comparable<? super T>> |
maxBy(java.lang.Iterable<? extends T> source)
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied key selector.
|
static <T> java.lang.Iterable<java.util.List<T>> |
maxBy(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied comparator.
|
static <T,U extends java.lang.Comparable<? super U>> |
maxBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector)
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied key selector.
|
static <T,U> java.lang.Iterable<java.util.List<T>> |
maxBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector,
java.util.Comparator<? super U> keyComparator)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector and comparator.
|
static <T> java.lang.Iterable<T> |
memoize(java.lang.Iterable<? extends T> source,
int bufferSize)
Enumerates the source iterable once and caches its results.
|
static <T> java.lang.Iterable<T> |
memoizeAll(java.lang.Iterable<? extends T> source)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the values.
|
static <T> java.lang.Iterable<T> |
merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Merges a bunch of iterable streams where each of the iterable will run by
a scheduler and their events are merged together in a single stream.
|
static <T> java.lang.Iterable<T> |
merge(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources,
Scheduler scheduler)
Merges a bunch of iterable streams where each of the iterable will run by
a scheduler and their events are merged together in a single stream.
|
static <T> java.lang.Iterable<T> |
merge(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Merges two iterable streams.
|
static <T extends java.lang.Comparable<? super T>> |
min(java.lang.Iterable<? extends T> source)
Returns the minimum value of the given iterable source.
|
static <T> java.lang.Iterable<T> |
min(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns the minimum value of the given iterable source in respect to the supplied comparator.
|
static <T extends java.lang.Comparable<? super T>> |
minBy(java.lang.Iterable<? extends T> source)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector.
|
static <T> java.lang.Iterable<java.util.List<T>> |
minBy(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied comparator.
|
static <T,U extends java.lang.Comparable<? super U>> |
minBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector.
|
static <T,U> java.lang.Iterable<java.util.List<T>> |
minBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector,
java.util.Comparator<? super U> keyComparator)
Returns an iterator which will produce a single List of the minimum values encountered
in the source stream based on the supplied key selector and comparator.
|
static <T> CloseableIterable<T> |
newCloseableIterable(java.lang.Iterable<? extends T> src,
Action0 close)
Wraps the given source sequence into a CloseableIterable instance
where the inner CloseableIterator.close() method calls the supplied action.
|
static <T> CloseableIterable<T> |
newCloseableIterable(java.lang.Iterable<? extends T> src,
Action1<? super java.util.Iterator<? extends T>> close)
Wraps the given source sequence into a CloseableIterable instance
where the inner CloseableIterator.close() method calls the supplied action.
|
static <T> CloseableIterable<T> |
newCloseableIterable(java.lang.Iterable<? extends T> src,
java.io.Closeable close)
Wraps the given source sequence into a CloseableIterable instance
where the inner CloseableIterator.close() method calls the supplied closeable object.
|
static <T> CloseableIterator<T> |
newCloseableIterator(java.util.Iterator<? extends T> src,
Action0 close)
Wraps the supplied iterator into a CloseableIterator which calls the supplied
close action.
|
static <T> CloseableIterator<T> |
newCloseableIterator(java.util.Iterator<? extends T> src,
Action1<? super java.util.Iterator<? extends T>> close)
Wraps the supplied iterator into a CloseableIterator which calls the supplied
close action with the given source iterator object.
|
static <T> CloseableIterator<T> |
newCloseableIterator(java.util.Iterator<? extends T> src,
java.io.Closeable close)
Wraps the supplied iterator into a CloseableIterator which calls the supplied
closeable instance.
|
static <T,U extends java.util.Iterator<T>> |
newIterable(Func0<U> body)
Creates a new iterable sequence by wrapping the given function to
provide the iterator.
|
static <T> java.util.Iterator<T> |
newIterator(Func0<java.lang.Boolean> hasNext,
Func0<? extends T> next)
A functional way of creating a new iterator from the supplied
hasNext and next callbacks.
|
static <T> java.util.Iterator<T> |
newIterator(Func0<java.lang.Boolean> hasNext,
Func0<? extends T> next,
Action0 remove)
Constructs an iterator instance by wrapping the supplied functions
into the same-named iterator methods.
|
static <T extends java.lang.Comparable<? super T>> |
orderBy(java.lang.Iterable<? extends T> source)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T> java.lang.Iterable<T> |
orderBy(java.lang.Iterable<? extends T> source,
java.util.Comparator<? super T> comparator)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T,U extends java.lang.Comparable<? super U>> |
orderBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T,U> java.lang.Iterable<T> |
orderBy(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> keySelector,
java.util.Comparator<? super U> keyComparator)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
static <T> Action1<T> |
print()
Creates an observer with debugging purposes.
|
static <T> Action1<T> |
print(java.lang.String separator,
int maxLineLength)
Creates an observer with debugging purposes.
|
static <T> Action1<T> |
println()
Creates an action for debugging purposes.
|
static <T> Action1<T> |
println(java.lang.String prefix)
Creates an action for debugging purposes.
|
static <T,U> java.lang.Iterable<U> |
prune(java.lang.Iterable<? extends T> source,
Func1<? super java.lang.Iterable<? extends T>,? extends java.lang.Iterable<U>> func)
Applies the
func function for a shared instance of the source,
e.g., func.invoke(share(source)). |
static <T,U> java.lang.Iterable<U> |
publish(java.lang.Iterable<? extends T> source,
Func1<? super java.lang.Iterable<? super T>,? extends java.lang.Iterable<? extends U>> func,
U initial)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the same cached values.
|
static <T,U> java.lang.Iterable<U> |
publish(java.lang.Iterable<? extends T> source,
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the values.
|
static java.lang.Iterable<java.lang.Integer> |
range(int start,
int count)
Creates an integer iterator which returns numbers from the start position in the count size.
|
static java.lang.Iterable<java.lang.Long> |
range(long start,
long count)
Creates an long iterator which returns numbers from the start position in the count size.
|
static <T> java.lang.Iterable<T> |
relayWhile(java.lang.Iterable<? extends T> source,
Func0<java.lang.Boolean> gate)
Relays the source iterable's values until the gate returns false.
|
static <T> java.lang.Iterable<T> |
repeat(T value)
Creates an iterable sequence which returns the given value indefinitely.
|
static <T> java.lang.Iterable<T> |
repeat(T value,
int count)
Returns an iterable which repeats the given single value the specified number of times.
|
static <T,U> java.lang.Iterable<U> |
replay(java.lang.Iterable<? extends T> source,
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator may only see one source element.
|
static <T,U> java.lang.Iterable<U> |
replay(java.lang.Iterable<? extends T> source,
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func,
int bufferSize)
The returned iterable ensures that the source iterable is only traversed once, regardless of
how many iterator attaches to it and each iterator see only the some cached values.
|
static <T> java.lang.Iterable<T> |
resumeAlways(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Creates an iterable which resumes with the next iterable from the sources when one throws an exception or completes normally.
|
static <T> java.lang.Iterable<T> |
resumeAlways(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Creates an iterable which resumes with the next iterable from the sources when one throws an exception.
|
static <T> java.lang.Iterable<T> |
resumeOnError(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
Creates an iterable which resumes with the next iterable from the sources when one throws an exception.
|
static <T> java.lang.Iterable<T> |
resumeOnError(java.lang.Iterable<? extends T> first,
java.lang.Iterable<? extends T> second)
Creates an iterable which resumes with the next iterable from the sources when one throws an exception.
|
static <T> java.lang.Iterable<T> |
retry(java.lang.Iterable<? extends T> source,
int count)
Creates an iterator which attempts to re-iterate the source if it threw an exception.
|
static void |
run(java.lang.Iterable<?> source)
Iterates over the given source without using its returned value.
|
static <T> void |
run(java.lang.Iterable<? extends T> source,
Action1<? super T> action)
Iterate over the source and submit each value to the
given action.
|
static <T,U> java.lang.Iterable<U> |
scan(java.lang.Iterable<? extends T> source,
Func2<? super U,? super T,? extends U> aggregator)
Generates an iterable which acts like a running sum when iterating over the source iterable, e.g.,
For each element in T, it computes a value by using the current aggregation value and returns it.
|
static <T,U> java.lang.Iterable<U> |
scan(java.lang.Iterable<? extends T> source,
U seed,
Func2<? super U,? super T,? extends U> aggregator)
Generates an iterable which acts like a running sum when iterating over the source iterable, e.g.,
For each element in T, it computes a value by using the current aggregation value and returns it.
|
static <T,U> java.lang.Iterable<U> |
select(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends U> selector)
Creates an iterable which is a transforms the source
elements by using the selector function.
|
static <T,U> java.lang.Iterable<U> |
select(java.lang.Iterable<? extends T> source,
Func2<? super java.lang.Integer,? super T,? extends U> selector)
Creates an iterable which is a transforms the source
elements by using the selector function.
|
static <T,U> java.lang.Iterable<U> |
selectMany(java.lang.Iterable<? extends T> source,
Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Creates an iterable which returns a stream of Us for each source Ts.
|
static <T> java.lang.Iterable<T> |
share(java.lang.Iterable<T> source)
Returns an iterable which ensures the source iterable is
only traversed once and clients may take values from each other,
e.g., they share the same iterator.
|
static <T,U> java.lang.Iterable<U> |
share(java.lang.Iterable<T> source,
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> selector)
Shares the source sequence within the specified
selector function where each iterator can fetch
the next element from the source.
|
static <T> java.lang.Iterable<T> |
singleton(T value)
Creates an iterable which returns only a single element.
|
static int |
size(java.lang.Iterable<?> iterable)
Immediately returns the number of elements in
iterable. |
static <T> java.lang.Iterable<T> |
skipLast(java.lang.Iterable<? extends T> source,
int num)
Returns an iterable which skips the last
num elements from the
source iterable. |
static <T> java.lang.Iterable<T> |
startWith(java.lang.Iterable<? extends T> source,
T... value)
Returns an iterable which prefixes the source iterable values
by a constant.
|
static <T> java.lang.Iterable<Pair<T,T>> |
subsequent(java.lang.Iterable<? extends T> source)
Creates an iterable which returns two subsequent items from the source
iterable as pairs of values.
|
static <T> java.lang.Iterable<java.lang.Iterable<T>> |
subsequent(java.lang.Iterable<? extends T> source,
int count)
Creates an iterable which returns
count subsequent items from the source
iterable as sequence of values. |
static java.lang.Iterable<java.math.BigDecimal> |
sumBigDecimal(java.lang.Iterable<java.math.BigDecimal> source)
Sum the source of Integer values and return it as a single element.
|
static java.lang.Iterable<java.math.BigInteger> |
sumBigInteger(java.lang.Iterable<java.math.BigInteger> source)
Sum the source of Integer values and return it as a single element.
|
static java.lang.Iterable<java.lang.Double> |
sumDouble(java.lang.Iterable<java.lang.Double> source)
Sum the source of Double values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Float> |
sumFloat(java.lang.Iterable<java.lang.Float> source)
Sum the source of Float values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Integer> |
sumInt(java.lang.Iterable<java.lang.Integer> source)
Sum the source of Integer values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Double> |
sumIntAsDouble(java.lang.Iterable<java.lang.Integer> source)
Computes and signals the sum of the values of the Integer source by using
a double intermediate representation.
|
static java.lang.Iterable<java.lang.Long> |
sumLong(java.lang.Iterable<java.lang.Long> source)
Sum the source of Long values and returns it as a single element.
|
static java.lang.Iterable<java.lang.Double> |
sumLongAsDouble(java.lang.Iterable<java.lang.Long> source)
Computes and signals the sum of the values of the Long sourceby using
a double intermediate representation.
|
static <T,U> java.lang.Iterable<U> |
switchCase(Func0<T> selector,
java.util.Map<T,java.lang.Iterable<U>> options)
Returns an iterable, which will query the selector for a key, then
queries the map for an Iterable.
|
static <T> java.lang.Iterable<T> |
take(java.lang.Iterable<? extends T> source,
int num)
Returns the iterable which returns the first
num element. |
static <T> java.lang.Iterable<T> |
takeLast(java.lang.Iterable<? extends T> source,
int num)
Returns an iterable which takes only the last
num elements from the
source iterable. |
static <T> java.lang.Iterable<T> |
throwException(java.lang.Throwable t)
Returns an iterator which will throw the given
Throwable exception when the client invokes
next() the first time. |
static <T> Enumerable<T> |
toEnumerable(java.lang.Iterable<? extends T> e)
Convert the source Iterable into the Enumerable semantics.
|
static <T> Enumerator<T> |
toEnumerator(java.util.Iterator<? extends T> it)
Convert the given iterator to the Enumerator semantics.
|
static <T> java.lang.Iterable<T> |
toIterable(Enumerable<? extends T> e)
Convert the source enumerable into the Iterable semantics.
|
static <T> java.lang.Iterable<T> |
toIterable(T... ts)
Takes the input elements and returns an iterable which
traverses the array.
|
static <T> java.lang.Iterable<T> |
toIterablePart(int from,
int to,
T... ts)
Takes the input elements and returns an iterable which
traverses the array between the two indexes.
|
static <T> java.util.Iterator<T> |
toIterator(Enumerator<? extends T> en)
Convert the given enumerator to the Iterator semantics.
|
static <T,U extends java.io.Closeable> |
using(Func0<U> resource,
Func1<? super U,java.lang.Iterable<? extends T>> usage)
Returns an iterable which is associated with a closeable handler.
|
static <T> java.lang.Iterable<T> |
where(java.lang.Iterable<? extends T> source,
Func0<? extends Func2<? super java.lang.Integer,? super T,java.lang.Boolean>> predicateFactory)
Creates an iterable which filters the source iterable with the
given predicate factory function.
|
static <T> java.lang.Iterable<T> |
where(java.lang.Iterable<? extends T> source,
Func1<? super T,java.lang.Boolean> predicate)
Creates an iterable which filters the source iterable with the
given predicate function.
|
static <T> java.lang.Iterable<T> |
where(java.lang.Iterable<? extends T> source,
Func2<? super java.lang.Integer,? super T,java.lang.Boolean> predicate)
Creates an iterable which filters the source iterable with the
given predicate factory function.
|
static <T> CloseableIterable<T> |
withClosing(java.lang.Iterable<? extends T> source,
java.io.Closeable closer)
Wraps the given source iterator into a closeable iterable
with the given closeable reference.
|
static <T> CloseableIterator<T> |
withClosing(java.util.Iterator<? extends T> source,
java.io.Closeable closer)
Wraps the given source iterator into a closeable iterable
with the given closeable reference.
|
static <T,U,V> java.lang.Iterable<V> |
zip(java.lang.Iterable<? extends T> left,
java.lang.Iterable<? extends U> right,
Func2<? super T,? super U,? extends V> combiner)
Pairs each element from both iterable sources and
combines them into a new value by using the
combiner
function. |
@Nonnull
public static <T,U,V> java.lang.Iterable<V> aggregate(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func2<? super U,? super T,? extends U> sum,
@Nonnull
Func2<? super U,? super java.lang.Integer,? extends V> divide)
sum function parameter. Once the source is depleted, it
applies the divide function and returns its result.
This operator is a general base for averaging (where sum(u, t) => u + t, divide(u, index) => u / index),
summing (where sum(u, t) => u + t, and divide(u, index) => u)),
minimum, maximum, etc.
If the traversal of the source fails due an exception, that exception is reflected on the
next() call of the returned iterator.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.T - the source element typeU - the intermediate aggregation typeV - the resulting aggregation typesource - the source of Tssum - the function which takes the current intermediate value,
the current source value and should produce a new intermediate value.
for the first element of T, the U parameter will receive nulldivide - the function which takes the last intermediate value and a total count of Ts seen and should return the final aggregation value.@Nonnull
public static <T> java.lang.Iterable<java.lang.Boolean> all(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,java.lang.Boolean> predicate)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typesource - the source of Tspredicate - the predicate@Nonnull
public static <T> java.lang.Iterable<java.lang.Boolean> any(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,java.lang.Boolean> predicate)
T - the source element typesource - the source of Tspredicate - the predicate tester function@Nonnull
public static <T> java.lang.Iterable<java.lang.Boolean> any(@Nonnull
java.lang.Iterable<T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element type, irrelevant heresource - the source of Ts@Nonnull
public static java.lang.Iterable<java.math.BigDecimal> averageBigDecimal(@Nonnull
java.lang.Iterable<java.math.BigDecimal> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source of BigDecimal values@Nonnull
public static java.lang.Iterable<java.math.BigDecimal> averageBigInteger(@Nonnull
java.lang.Iterable<java.math.BigInteger> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source of BigInteger values@Nonnull
public static java.lang.Iterable<java.lang.Double> averageDouble(@Nonnull
java.lang.Iterable<java.lang.Double> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source of Double values@Nonnull
public static java.lang.Iterable<java.lang.Float> averageFloat(@Nonnull
java.lang.Iterable<java.lang.Float> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source of Float values@Nonnull
public static java.lang.Iterable<java.lang.Double> averageInt(@Nonnull
java.lang.Iterable<java.lang.Integer> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source of Integer values@Nonnull
public static java.lang.Iterable<java.lang.Double> averageLong(@Nonnull
java.lang.Iterable<java.lang.Long> source)
UnsupportedOperationException
for its remove() method.source - the source of Integer values@Nonnull
public static <T> java.lang.Iterable<java.util.List<T>> buffer(@Nonnull
java.lang.Iterable<? extends T> source,
int bufferSize)
bufferSize lists.
FIXME what to do on empty source or last chunk?
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typesource - the source of TsbufferSize - the buffer size.@Nonnull
public static <T> java.lang.Iterable<T> cast(@Nonnull
java.lang.Iterable<?> source,
@Nonnull
java.lang.Class<T> token)
next()
will throw a ClassCastException.
The returned iterator forwards all remove() calls
to the source.
T - the result element typesource - the arbitrary sourcetoken - the type token@Nonnull
public static <T> java.lang.Iterable<T> catchException(@Nonnull
java.lang.Iterable<? extends T> source)
T - the element typesource - the source iterable.@Nonnull
public static <T> java.lang.Iterable<T> catchException(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super java.lang.Throwable,? extends java.lang.Iterable<? extends T>> handler)
The returned iterator forwards all remove() calls
to the source.
T - the element typesource - the source iterable.handler - the exception handler.@Nonnull
public static <T> java.lang.Iterable<T> concat(@Nonnull
java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
iterator()
only happens when there is no more element in the first iterator.
The returned iterator forwards all remove() calls
to the current source (e.g., you can remove the same elements from
multiple collections with a single traversal on the concat result).
T - the element typesources - the list of iterables to concatenate@Nonnull
public static <T> java.lang.Iterable<T> concat(@Nonnull
java.lang.Iterable<? extends T> first,
@Nonnull
java.lang.Iterable<? extends T> second)
iterator()
only happens when there is no more element in the first iterator.
The returned iterator forwards all remove() calls
to the current source (first or next).
T - the element typefirst - the first iterablesecond - the second iterable@Nonnull
public static <T> java.lang.Iterable<java.lang.Boolean> contains(@Nonnull
java.lang.Iterable<? extends T> source,
T value)
equals(). The iterable then returns a single true or false.T - the source element typesource - the sourcevalue - the value to check@Nonnull
public static <T> java.lang.Iterable<java.lang.Integer> count(@Nonnull
java.lang.Iterable<T> source)
int.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesource - the source iterable@Nonnull
public static <T> java.lang.Iterable<java.lang.Long> countLong(@Nonnull
java.lang.Iterable<T> source)
long.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesource - the source iterable@Nonnull
public static <T> java.lang.Iterable<T> defer(@Nonnull
Func0<? extends java.lang.Iterable<T>> func)
func for the actual source.T - the element typefunc - the function that returns an iterable.@Nonnull
public static <T> java.lang.Iterable<T> dematerialize(@Nonnull
java.lang.Iterable<? extends Option<? extends T>> source)
UnsupportedOperationException for its remove() method.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typessource - the source of T options@Nonnull
public static <T> java.lang.Iterable<T> distinctNext(@Nonnull
java.lang.Iterable<? extends T> source)
T - the element typesource - the source iterable@Nonnull
public static <T,U> java.lang.Iterable<T> distinctNext(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<T,U> keyExtractor)
T - the element typeU - the key typesource - the source iterablekeyExtractor - the function to extract the keys which will be compared@Nonnull
public static <T> java.lang.Iterable<T> distinct(@Nonnull
java.lang.Iterable<? extends T> source)
equals()T - the source element typesource - the source of Ts@Nonnull
public static <T,U,V> java.lang.Iterable<V> distinct(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector,
@Nonnull
Func1<? super T,? extends V> valueSelector)
equals()T - the source element typeU - the key element typeV - the output element typesource - the source of TskeySelector - the key selector for only-once filteringvalueSelector - the value select for the output of the first key cases@Nonnull
public static <T> java.lang.Iterable<T> doWhile(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func0<java.lang.Boolean> gate)
source
as long as the gate is true. The gate function is checked only
when a pass over the source stream was completed.
Note that using this operator on an empty iterable may result
in a direct infinite loop in hasNext() or next() calls depending on the gate function.
The returned iterator forwards all remove() calls
to the source.
T - the source element typesource - the source of Tsgate - the gate function to stop the repeatpublic static boolean elementsEqual(@Nonnull
java.lang.Iterable<?> iterable1,
@Nonnull
java.lang.Iterable<?> iterable2)
true if
iterable1 and iterable2 contain the same number of
elements and every element of iterable1 is equal to the
corresponding element of iterable2.iterable1 - the first iterableiterable2 - the second iterablepublic static boolean elementsEqual(@Nonnull
java.util.Iterator<?> iterator1,
@Nonnull
java.util.Iterator<?> iterator2)
iterator1 - the first iteratoriterator2 - the second interator@Nonnull public static <T> java.lang.Iterable<T> empty()
hasNext() returns always false,
next() throws a NoSuchElementException
and remove() throws an IllegalStateException.
Note that the Collections.emptyIterable() static method is introduced by Java 7.T - the element type, irrelevant@Nonnull
public static <T> java.lang.Iterable<T> finish(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Action0 action)
The returned iterator forwards all remove() calls
to the source.
T - the element typesource - the source of Tsaction - the action to invoke@Nonnull
public static <T,U> java.lang.Iterable<U> forEach(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Iterable<U>s are
created before their concatenation starts.T - the source element typeU - the output element typesource - the sourceselector - the result selector@Nonnull
public static <T> java.lang.Iterable<T> generate(T seed,
@Nonnull
Func1<? super T,java.lang.Boolean> predicate,
@Nonnull
Func1<? super T,? extends T> next)
T value = seed;
while (predicate(value)) {
yield value;
value = next(value);
}
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typeseed - the initial valuepredicate - the predicate to terminate the processnext - the function that computes the next value.@Nonnull
public static <T> java.lang.Iterable<T> generate(T seed,
@Nonnull
Func1<? super T,java.lang.Boolean> predicate,
@Nonnull
Func1<? super T,? extends T> next,
long initialDelay,
long betweenDelay,
@Nonnull
java.util.concurrent.TimeUnit unit)
initialDelay amount of wait and each
subsequent element is then generated after betweenDelay sleep.
The sleeping is blocking the current thread which invokes the hasNext()/next() methods.
This is equivalent to:
T value = seed;
sleep(initialDelay);
if (predicate(value)) {
yield value;
}
value = next(value);
sleep(betweenDelay);
while (predicate(value)) {
yield value;
value = next(value);
sleep(betweenDelay);
}
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typeseed - the initial valuepredicate - the predicate to terminate the processnext - the function that computes the next value.initialDelay - the initial delaybetweenDelay - the between delayunit - the time unit for initialDelay and betweenDelay@Nonnull public static <T,U,V> java.lang.Iterable<GroupedIterable<V,U>> groupBy(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull Func1<? super T,? extends V> keySelector, @Nonnull Func1<? super T,? extends U> valueSelector)
equals() equality.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeU - the result group element typeV - the result group keyssource - the source of TskeySelector - the key selectorvalueSelector - the value selector@Nonnull
public static <T> java.lang.Iterable<T> invoke(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Action1<? super T> action)
The returned iterator forwards all remove() calls
to the source.
T - the returned element typesource - the source iterableaction - the action to invoke before each next() is returned.@Nonnull
public static <T> java.lang.Iterable<T> invoke(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Action1<? super T> next,
@Nonnull
Action0 finish)
next
action for each element and the finish action when
the source completes.T - the source element typesource - the source of Tsnext - the action to invoke on each elementfinish - the action to invoke after the last element@Nonnull
public static <T> java.lang.Iterable<T> invoke(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Action1<? super T> next,
@Nonnull
Action1<? super java.lang.Throwable> error)
next
action for each element and error when an exception is thrown.T - the source element typesource - the source of Tsnext - the action to invoke on each elementerror - the error action to invoke for an error@Nonnull
public static <T> java.lang.Iterable<T> invoke(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Action1<? super T> next,
@Nonnull
Action1<? super java.lang.Throwable> error,
@Nonnull
Action0 finish)
next
action for each element and the finish action when
the source completes and error when an exception is thrown.
The returned iterator forwards all remove() calls
to the source.
T - the source element typesource - the source of Tsnext - the action to invoke on each elementerror - the error action to invoke for an errorfinish - the action to invoke after the last element@Nonnull
public static java.lang.Iterable<java.lang.Boolean> isEmpty(@Nonnull
java.lang.Iterable<?> source)
source - source iterable with any type@Nonnull
public static java.lang.Iterable<java.lang.String> join(@Nonnull
java.lang.Iterable<?> source,
java.lang.String separator)
The returned iterator forwards all remove() calls
to the source.
source - the sourceseparator - the separator to usepublic static <T> T last(@Nonnull
java.lang.Iterable<? extends T> source)
NoSuchElementException if the iterable is empty.T - the source element typesource - the source of Ts@Nonnull public static <T> java.lang.Iterable<Option<T>> materialize(@Nonnull java.lang.Iterable<? extends T> source)
UnsupportedOperationException for its remove() method.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typesource - the source of at least Ts.@Nonnull
public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> max(@Nonnull
java.lang.Iterable<? extends T> source)
T - the element type, which must be self comparablesource - the source elements@Nonnull
public static <T> java.lang.Iterable<T> max(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
java.util.Comparator<? super T> comparator)
T - the element type, which must be self comparablesource - the source elementscomparator - the comparator to use@Nonnull
public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<java.util.List<T>> maxBy(@Nonnull
java.lang.Iterable<? extends T> source)
T - the source element type, which must be self comparablesource - the source of Ts@Nonnull
public static <T> java.lang.Iterable<java.util.List<T>> maxBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
java.util.Comparator<? super T> comparator)
T - the source element typesource - the source of Tscomparator - the key comparator@Nonnull
public static <T,U extends java.lang.Comparable<? super U>> java.lang.Iterable<java.util.List<T>> maxBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector)
T - the source element typeU - the key type, which must be self-comparablesource - the source of TskeySelector - the selector for keys@Nonnull
public static <T,U> java.lang.Iterable<java.util.List<T>> maxBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector,
@Nonnull
java.util.Comparator<? super U> keyComparator)
T - the source element typeU - the key typesource - the source of TskeySelector - the selector for keyskeyComparator - the key comparator@Nonnull
public static <T> java.lang.Iterable<T> memoize(@Nonnull
java.lang.Iterable<? extends T> source,
int bufferSize)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typesource - the source of TsbufferSize - the size of the buffering@Nonnull
public static <T> java.lang.Iterable<T> memoizeAll(@Nonnull
java.lang.Iterable<? extends T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typesource - the source of Ts@Nonnull
public static <T> java.lang.Iterable<T> merge(@Nonnull
java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
UnsupportedOperationException in its remove() method.T - the element typesources - the iterable of source iterables.@Nonnull
public static <T> java.lang.Iterable<T> merge(@Nonnull
java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources,
@Nonnull
Scheduler scheduler)
UnsupportedOperationException in its remove() method.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesources - the iterable of source iterables.scheduler - the scheduler for running each inner iterable in parallel@Nonnull
public static <T> java.lang.Iterable<T> merge(@Nonnull
java.lang.Iterable<? extends T> first,
@Nonnull
java.lang.Iterable<? extends T> second)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typefirst - the first iterablesecond - the second iterable@Nonnull
public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> min(@Nonnull
java.lang.Iterable<? extends T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element type, which must be self comparablesource - the source elements@Nonnull
public static <T> java.lang.Iterable<T> min(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
java.util.Comparator<? super T> comparator)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element type, which must be self comparablesource - the source elementscomparator - the comparator to use@Nonnull
public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<java.util.List<T>> minBy(@Nonnull
java.lang.Iterable<? extends T> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element type, which must be self comparablesource - the source of Ts@Nonnull
public static <T> java.lang.Iterable<java.util.List<T>> minBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
java.util.Comparator<? super T> comparator)
T - the source element typesource - the source of Tscomparator - the key comparator@Nonnull
public static <T,U extends java.lang.Comparable<? super U>> java.lang.Iterable<java.util.List<T>> minBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeU - the key type, which must be self-comparablesource - the source of TskeySelector - the selector for keys@Nonnull
public static <T,U> java.lang.Iterable<java.util.List<T>> minBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector,
@Nonnull
java.util.Comparator<? super U> keyComparator)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeU - the key typesource - the source of TskeySelector - the selector for keyskeyComparator - the key comparator@Nonnull
public static <T extends java.lang.Comparable<? super T>> java.lang.Iterable<T> orderBy(@Nonnull
java.lang.Iterable<? extends T> source)
T - the source element type, must be self comparablesource - the source of Ts@Nonnull
public static <T> java.lang.Iterable<T> orderBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
java.util.Comparator<? super T> comparator)
T - the source element type, must be self comparablesource - the source of Tscomparator - the value comparator@Nonnull
public static <T,U extends java.lang.Comparable<? super U>> java.lang.Iterable<T> orderBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector)
T - the source element typeU - the key type for the ordering, must be self comparablesource - the source of TskeySelector - the key selector for comparison@Nonnull
public static <T,U> java.lang.Iterable<T> orderBy(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> keySelector,
@Nonnull
java.util.Comparator<? super U> keyComparator)
T - the source element typeU - the key type for the orderingsource - the source of TskeySelector - the key selector for comparisonkeyComparator - the key comparator function@Nonnull public static <T> Action1<T> print()
T - the value type@Nonnull public static <T> Action1<T> print(java.lang.String separator, int maxLineLength)
T - the value typeseparator - the separator to use between subsequent valuesmaxLineLength - how many characters to print into each line@Nonnull public static <T> Action1<T> println()
T - the value type@Nonnull public static <T> Action1<T> println(java.lang.String prefix)
T - the value typeprefix - the prefix to use when printing@Nonnull
public static <T,U> java.lang.Iterable<U> prune(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super java.lang.Iterable<? extends T>,? extends java.lang.Iterable<U>> func)
func function for a shared instance of the source,
e.g., func.invoke(share(source)).T - the source element typeU - the return typessource - the source of Tsfunc - invoke the function on the buffering iterable and return an iterator over it.@Nonnull
public static <T,U> java.lang.Iterable<U> publish(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super java.lang.Iterable<? super T>,? extends java.lang.Iterable<? extends U>> func,
U initial)
The returned iterator will throw an UnsupportedOperationException
for remove() method of its first element, then it might throw for any
subsequent element, depending on the source iterable.
T - the source element typeU - the return typessource - the source of Tsfunc - invoke the function on the buffering iterable and return an iterator over it.initial - the initial value to append to the output stream@Nonnull
public static <T,U> java.lang.Iterable<U> publish(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeU - the return typessource - the source of Tsfunc - invoke the function on the buffering iterable and return an iterator over it.@Nonnull
public static java.lang.Iterable<java.lang.Integer> range(int start,
int count)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
start - the starting value.count - the number of elements to return, negative count means counting down from the start.@Nonnull
public static java.lang.Iterable<java.lang.Long> range(long start,
long count)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
start - the starting value.count - the number of elements to return, negative count means counting down from the start.@Nonnull
public static <T> java.lang.Iterable<T> relayWhile(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func0<java.lang.Boolean> gate)
T - the source element typesource - the source of Tsgate - the gate to stop the relaying@Nonnull
public static <T,U> java.lang.Iterable<U> replay(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeU - the return typessource - the source of Tsfunc - invoke the function on the buffering iterable and return an iterator over it.@Nonnull
public static <T,U> java.lang.Iterable<U> replay(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func,
int bufferSize)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeU - the return typessource - the source of Tsfunc - invoke the function on the buffering iterable and return an iterator over it.bufferSize - the buffer size@Nonnull
public static <T> java.lang.Iterable<T> resumeAlways(@Nonnull
java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
The returned iterator forwards all remove() calls
to the source.
T - the source element typesources - the list of sources to try one after another@Nonnull
public static <T> java.lang.Iterable<T> resumeAlways(@Nonnull
java.lang.Iterable<? extends T> first,
@Nonnull
java.lang.Iterable<? extends T> second)
T - the source element typefirst - the first sourcesecond - the second source@Nonnull
public static <T> java.lang.Iterable<T> resumeOnError(@Nonnull
java.lang.Iterable<? extends java.lang.Iterable<? extends T>> sources)
The returned iterator forwards all remove() calls
to the source.
T - the source element typesources - the list of sources to try one after another@Nonnull
public static <T> java.lang.Iterable<T> resumeOnError(@Nonnull
java.lang.Iterable<? extends T> first,
@Nonnull
java.lang.Iterable<? extends T> second)
T - the source element typefirst - the first sourcesecond - the second source@Nonnull
public static <T> java.lang.Iterable<T> retry(@Nonnull
java.lang.Iterable<? extends T> source,
int count)
while (count-- > 0) {
try {
for (T t : source) {
yield t;
}
break;
} catch (Throwable t) {
if (count <= 0) {
throw t;
}
}
}
The returned iterator forwards all remove() calls
to the source.
T - the source typesource - the source of Tscount - the number of retry attemptspublic static <T> void run(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Action1<? super T> action)
T - the element type of the iterablesource - the iterableaction - the action to invoke on with elementpublic static void run(@Nonnull
java.lang.Iterable<?> source)
source - the source iterable to run through@Nonnull
public static <T,U> java.lang.Iterable<U> scan(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func2<? super U,? super T,? extends U> aggregator)
T - the source element typeU - the destination element typesource - the source of Tsaggregator - the function which takes the current running aggregation value, the current element and produces a new aggregation value.@Nonnull
public static <T,U> java.lang.Iterable<U> scan(@Nonnull
java.lang.Iterable<? extends T> source,
U seed,
@Nonnull
Func2<? super U,? super T,? extends U> aggregator)
The returned iterator forwards all remove() calls
to the source.
T - the source element typeU - the destination element typesource - the source of Tsseed - the initial value of the running aggregationaggregator - the function which takes the current running aggregation value, the current element and produces a new aggregation value.@Nonnull
public static <T,U> java.lang.Iterable<U> select(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends U> selector)
T - the source element typeU - the output element typesource - the source iterableselector - the selector function@Nonnull
public static <T,U> java.lang.Iterable<U> select(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func2<? super java.lang.Integer,? super T,? extends U> selector)
The returned iterator forwards all remove() calls
to the source.
T - the source element typeU - the output element typesource - the source iterableselector - the selector function@Nonnull
public static <T,U> java.lang.Iterable<U> selectMany(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
The returned iterator forwards all remove() calls
to the current source (which might not accept it).
T - the source element typeU - the output element typesource - the sourceselector - the selector for multiple Us for each T@Nonnull
public static <T> java.lang.Iterable<T> share(@Nonnull
java.lang.Iterable<T> source)
T - the source element typesource - the source iterable@Nonnull
public static <T,U> java.lang.Iterable<U> share(@Nonnull
java.lang.Iterable<T> source,
@Nonnull
Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> selector)
T - the source element typeU - the result element typesource - the source sequenceselector - the selector function@Nonnull public static <T> java.lang.Iterable<T> singleton(T value)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typevalue - the value to returnpublic static int size(@Nonnull
java.lang.Iterable<?> iterable)
iterable.iterable - the input sequence@Nonnull
public static <T> java.lang.Iterable<T> skipLast(@Nonnull
java.lang.Iterable<? extends T> source,
int num)
num elements from the
source iterable.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesource - the source iterablenum - the number of elements to skip at the end@Nonnull
public static <T> java.lang.Iterable<T> startWith(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
T... value)
concat(singleton(value), source).
The returned iterator will throw an UnsupportedOperationException
for its remove() method for the first element, and might
throw for subsequent elements, depending on the source iterable.
T - the element typesource - the source iterablevalue - the value to prefix@Nonnull
public static java.lang.Iterable<java.math.BigDecimal> sumBigDecimal(@Nonnull
java.lang.Iterable<java.math.BigDecimal> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source@Nonnull
public static java.lang.Iterable<java.math.BigInteger> sumBigInteger(@Nonnull
java.lang.Iterable<java.math.BigInteger> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source@Nonnull
public static java.lang.Iterable<java.lang.Double> sumDouble(@Nonnull
java.lang.Iterable<java.lang.Double> source)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
source - the source@Nonnull
public static java.lang.Iterable<java.lang.Float> sumFloat(@Nonnull
java.lang.Iterable<java.lang.Float> source)
source - the source@Nonnull
public static java.lang.Iterable<java.lang.Integer> sumInt(@Nonnull
java.lang.Iterable<java.lang.Integer> source)
source - the source@Nonnull
public static java.lang.Iterable<java.lang.Long> sumLong(@Nonnull
java.lang.Iterable<java.lang.Long> source)
source - the source@Nonnull
public static <T,U> java.lang.Iterable<U> switchCase(@Nonnull
Func0<T> selector,
@Nonnull
java.util.Map<T,java.lang.Iterable<U>> options)
T - the key typeU - the output typeselector - the key selectoroptions - the available options in@Nonnull
public static <T> java.lang.Iterable<T> take(@Nonnull
java.lang.Iterable<? extends T> source,
int num)
num element.
from the source iterable.
The returned iterator forwards all remove() calls
to the source.
T - the source element typesource - the source of Tsnum - the number of items to take@Nonnull
public static <T> java.lang.Iterable<T> takeLast(@Nonnull
java.lang.Iterable<? extends T> source,
int num)
num elements from the
source iterable.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesource - the source iterablenum - the number of elements to skip at the end@Nonnull
public static <T> java.lang.Iterable<T> throwException(@Nonnull
java.lang.Throwable t)
Throwable exception when the client invokes
next() the first time. Any subsequent
next() call will simply throw a NoSuchElementException.
Calling remove() will always throw a IllegalStateException.
If the given Throwable instance extends a RuntimeException, it is throws
as is, but when the throwable is a checked exception, it is wrapped
into a RuntimeException.
FIXME not sure about next() semanticsT - the element type, irrelevantt - the exception to throw@Nonnull public static <T> Enumerable<T> toEnumerable(@Nonnull java.lang.Iterable<? extends T> e)
T - the source element typee - the iterable@Nonnull public static <T> Enumerator<T> toEnumerator(@Nonnull java.util.Iterator<? extends T> it)
T - the element typeit - the source iterator@Nonnull
public static <T> java.lang.Iterable<T> toIterable(@Nonnull
Enumerable<? extends T> e)
T - the source element typee - the enumerable@Nonnull
public static <T> java.util.Iterator<T> toIterator(@Nonnull
Enumerator<? extends T> en)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typeen - the source enumerator@Nonnull
public static <T,U extends java.io.Closeable> java.lang.Iterable<T> using(@Nonnull
Func0<U> resource,
@Nonnull
Func1<? super U,java.lang.Iterable<? extends T>> usage)
Closeable.close() on the handler.
The returned iterator forwards all remove() calls
to the source.
T - the source element typeU - the closeable typeresource - the function which returns a resource tokenusage - the function which gives an iterable for a resource token.@Nonnull
public static <T> java.lang.Iterable<T> where(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func0<? extends Func2<? super java.lang.Integer,? super T,java.lang.Boolean>> predicateFactory)
The returned iterator forwards all remove() calls
to the source.
T - the element typesource - the source iterablepredicateFactory - the predicate factory which should return a new predicate function for each iterator.@Nonnull
public static <T> java.lang.Iterable<T> where(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func1<? super T,java.lang.Boolean> predicate)
T - the element typesource - the source iterablepredicate - the predicate function@Nonnull
public static <T> java.lang.Iterable<T> where(@Nonnull
java.lang.Iterable<? extends T> source,
@Nonnull
Func2<? super java.lang.Integer,? super T,java.lang.Boolean> predicate)
T - the element typesource - the source iterablepredicate - the predicate@Nonnull
public static <T,U,V> java.lang.Iterable<V> zip(@Nonnull
java.lang.Iterable<? extends T> left,
@Nonnull
java.lang.Iterable<? extends U> right,
@Nonnull
Func2<? super T,? super U,? extends V> combiner)
combiner
function.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the left source typeU - the right source typeV - the result typeleft - the left sourceright - the right sourcecombiner - the combiner functionpublic static <T> T first(@Nonnull
java.lang.Iterable<? extends T> src)
T - the value typesrc - the source sequence@Nonnull
public static <T> java.lang.Iterable<T> toIterable(@Nonnull
T... ts)
The resulting Iterable does not support remove().
T - the element typets - the input array@Nonnull
public static <T> java.lang.Iterable<T> toIterablePart(int from,
int to,
@Nonnull
T... ts)
The resulting Iterable does not support remove().
T - the element typefrom - the starting index inclusiveto - the end index exclusivets - the input arraypublic static <T,V> Pair<T,V> argAndMax(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull Func1<? super T,? extends V> valueSelector, @Nonnull java.util.Comparator<? super V> valueComparator)
T - the element typeV - the value typesource - the source sequence of TsvalueSelector - the selector to extract the value from TvalueComparator - the comparator to compare two valuespublic static <T,V extends java.lang.Comparable<? super V>> Pair<T,V> argAndMax(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull Func1<? super T,? extends V> valueSelector)
T - the element type of the sequenceV - the value type for the comparison, must be self comparablesource - the source sequencevalueSelector - the value selector functionpublic static <T,V extends java.lang.Comparable<? super V>> Pair<T,V> argAndMin(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull Func1<? super T,? extends V> valueSelector)
T - the element type of the sequenceV - the value type for the comparison, must be self comparablesource - the source sequencevalueSelector - the value selector functionpublic static <T,V> Pair<T,V> argAndMin(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull Func1<? super T,? extends V> valueSelector, @Nonnull java.util.Comparator<? super V> valueComparator)
T - the element typeV - the value typesource - the source sequence of TsvalueSelector - the selector to extract the value from TvalueComparator - the comparator to compare two valuespublic static <T> java.lang.Iterable<T> repeat(T value)
(E.g., having the hasNext() always return true and the next() always return the value.
The returned iterable does not support the remove() method.
T - the value typevalue - the value to repeatpublic static <T> java.lang.Iterable<T> repeat(T value,
int count)
The returned iterable does not support the remove() method.
T - the value typevalue - the value to repeatcount - the repeat amount@Nonnull
public static <T> java.lang.Iterable<T> endWith(@Nonnull
java.lang.Iterable<? extends T> source,
T value)
The returned iterable forwards all remove()
methods to the source iterable, except the last element where it
throws UnsupportedOperationException.
T - the element typesource - the source sequencevalue - the value to append@Nonnull
public static java.lang.Iterable<java.lang.Double> sumIntAsDouble(@Nonnull
java.lang.Iterable<java.lang.Integer> source)
source - the source of integers to aggregate.@Nonnull
public static java.lang.Iterable<java.lang.Double> sumLongAsDouble(@Nonnull
java.lang.Iterable<java.lang.Long> source)
source - the source of longs to aggregate.@Nonnull public static <T,V> java.lang.Iterable<GroupedIterable<V,T>> groupBy(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull Func1<? super T,? extends V> keySelector)
equals() equality.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the source element typeV - the result group keyssource - the source of TskeySelector - the key selectorpublic static <T> java.lang.Iterable<Pair<T,T>> subsequent(@Nonnull java.lang.Iterable<? extends T> source)
source contains zero or one elements, this
iterable will be empty.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesource - the source iterablepublic static <T> java.lang.Iterable<java.lang.Iterable<T>> subsequent(@Nonnull
java.lang.Iterable<? extends T> source,
int count)
count subsequent items from the source
iterable as sequence of values.
If the source contains less than count elements, this
iterable will be empty.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
T - the element typesource - the source iterablecount - the element countpublic static <T,U extends java.util.Iterator<T>> java.lang.Iterable<T> newIterable(@Nonnull
Func0<U> body)
T - the element typeU - the iterator typebody - the body function returning an iteratorpublic static <T> java.util.Iterator<T> newIterator(@Nonnull
Func0<java.lang.Boolean> hasNext,
@Nonnull
Func0<? extends T> next)
The returned iterator throws a UnsupportedOperationException
in its remove method.
T - the element typehasNext - function that returns true if more elements are available.next - function that returns the next elementpublic static <T> java.util.Iterator<T> newIterator(@Nonnull
Func0<java.lang.Boolean> hasNext,
@Nonnull
Func0<? extends T> next,
@Nonnull
Action0 remove)
T - the element typehasNext - function that returns true if more elements are available.next - function that returns the next elementremove - function to remove the current element@Nonnull public static <T> CloseableIterable<T> newCloseableIterable(@Nonnull java.lang.Iterable<? extends T> src, @Nonnull Action1<? super java.util.Iterator<? extends T>> close)
T - the element typesrc - the source sequenceclose - the close action.@Nonnull public static <T> CloseableIterable<T> newCloseableIterable(@Nonnull java.lang.Iterable<? extends T> src, @Nonnull Action0 close)
T - the element typesrc - the source sequenceclose - the close action.@Nonnull public static <T> CloseableIterable<T> newCloseableIterable(@Nonnull java.lang.Iterable<? extends T> src, @Nonnull java.io.Closeable close)
T - the element typesrc - the source sequenceclose - the closeable object.@Nonnull public static <T> CloseableIterator<T> newCloseableIterator(@Nonnull java.util.Iterator<? extends T> src, @Nonnull Action0 close)
T - the element typesrc - the source iteratorclose - the close action@Nonnull public static <T> CloseableIterator<T> newCloseableIterator(@Nonnull java.util.Iterator<? extends T> src, @Nonnull java.io.Closeable close)
T - the element typesrc - the source iteratorclose - the closeable instance@Nonnull public static <T> CloseableIterator<T> newCloseableIterator(@Nonnull java.util.Iterator<? extends T> src, @Nonnull Action1<? super java.util.Iterator<? extends T>> close)
T - the element typesrc - the source iteratorclose - the close action@Nonnull
public static <T> java.util.Iterator<T> differentAggregator(@Nonnull
java.util.Iterator<? extends T> src,
@Nonnull
Func2<? super T,? super T,java.lang.Boolean> isDifferent,
@Nonnull
Action2<T,? super T> aggregate)
isDifferent returns false.
Once two different subsequent elements are found or the stream terminates, a single, aggregated value
is emitted.
For example, given a stream of [1, 1, 2, 2, 3, 3], the output will be [2, 4, 6].
The returned iterator does not support remove().
T - the source and result typesrc - the source sequenceisDifferent - the differenceaggregate - the aggregator@Nonnull public static <T> CloseableIterator<T> withClosing(@Nonnull java.util.Iterator<? extends T> source, @Nonnull java.io.Closeable closer)
T - the source and result typesource - the source iteratorcloser - the close handle@Nonnull public static <T> CloseableIterable<T> withClosing(@Nonnull java.lang.Iterable<? extends T> source, @Nonnull java.io.Closeable closer)
T - the source and result typesource - the source iteratorcloser - the close handle