T - the element typepublic final class IterableBuilder<T>
extends java.lang.Object
implements java.lang.Iterable<T>
This builder is the dual of the
ObservableBuilder class.
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Iterable<T> |
it
The backing iterable.
|
| Modifier | Constructor and Description |
|---|---|
protected |
IterableBuilder(java.lang.Iterable<T> source)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
<U,V> IterableBuilder<V> |
aggregate(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. |
IterableBuilder<java.lang.Boolean> |
all(Func1<? super T,java.lang.Boolean> predicate)
Returns an iterable which contains true if all
elements of the source iterable satisfy the predicate.
|
IterableBuilder<java.lang.Boolean> |
any()
Determines if the given source has any elements at all.
|
IterableBuilder<java.lang.Boolean> |
any(Func1<? super T,java.lang.Boolean> predicate)
Tests if there is any element of the source that satisfies the given predicate function.
|
<V extends java.lang.Comparable<? super V>> |
argAndMax(Func1<? super T,? extends V> valueSelector)
Returns a pair of the maximum argument and value from the given sequence.
|
<V> Pair<T,V> |
argAndMax(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.
|
<V extends java.lang.Comparable<? super V>> |
argAndMin(Func1<? super T,? extends V> valueSelector)
Returns a pair of the minimum argument and value from the given sequence.
|
<V> Pair<T,V> |
argAndMin(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.
|
IterableBuilder<java.math.BigDecimal> |
averageBigDecimal()
Computes and signals the average value of the BigDecimal source.
|
IterableBuilder<java.math.BigDecimal> |
averageBigInteger()
Computes and signals the average value of the BigInteger source.
|
IterableBuilder<java.lang.Double> |
averageDouble()
Computes and signals the average value of the Double source.
|
IterableBuilder<java.lang.Float> |
averageFloat()
Computes and signals the average value of the Float source.
|
IterableBuilder<java.lang.Double> |
averageInt()
Computes and signals the average value of the integer source.
|
IterableBuilder<java.lang.Double> |
averageLong()
Computes and signals the average value of the Long source.
|
IterableBuilder<java.util.List<T>> |
buffer(int bufferSize)
Returns an iterable which buffers the source elements
into
bufferSize lists. |
<U> IterableBuilder<U> |
cast(java.lang.Class<U> token)
Casts the source iterable into a different typ by using a type token.
|
<U> ObservableBuilder<U> |
concat(Func1<? super T,? extends Observable<? extends U>> resultSelector)
Perform the concatenation of observable
sequences based on this iterable and the
given result selector function.
|
IterableBuilder<T> |
concat(java.lang.Iterable<? extends T> other)
Concatenate this iterable with the other iterable in a way, that calling the second
iterator()
only happens when there is no more element in the first iterator. |
IterableBuilder<T> |
concat(T... values)
Concatenate this iterable with the sequence of array values.
|
IterableBuilder<T> |
concatAll(java.lang.Iterable<? extends java.lang.Iterable<? extends T>> others)
Creates an iterable builder which contains the concatenation
of this iterable and the rest iterable provided.
|
IterableBuilder<java.lang.Boolean> |
contains(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(). |
IterableBuilder<java.lang.Integer> |
count()
Counts the elements of the iterable source by using a 32 bit
int. |
IterableBuilder<java.lang.Long> |
countLong()
Counts the elements of the iterable source by using a 64 bit
long. |
static <T> IterableBuilder<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. |
IterableBuilder<T> |
dematerialize()
Convert the source materialized elements into normal iterator behavior.
|
IterableBuilder<T> |
distinct()
Returns an iterable which filters its elements based if they vere ever seen before in
the current iteration.
|
<U> IterableBuilder<T> |
distinct(Func1<? super T,? extends U> keySelector)
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.
|
IterableBuilder<T> |
distinctNext()
Creates an iterable which ensures that subsequent values of T are not equal (reference and equals).
|
<U> IterableBuilder<T> |
distinctNext(Func1<T,U> keySelector)
Creates an iterable which ensures that subsequent values of
T are not equal in respect to the extracted keys (reference and equals).
|
IterableBuilder<T> |
doWhile(Func0<java.lang.Boolean> gate)
Returns an iterable which reiterates over and over again on
source
as long as the gate is true. |
IterableBuilder<T> |
endWith(T value)
Creates an iterable sequence which returns all elements from source
followed by the supplied value as last.
|
IterableBuilder<T> |
finish(Action0 action)
Returns an iterable which executes the given action after
the stream completes.
|
T |
first()
Returns the first element from the iterable sequence or
throws a NoSuchElementException.
|
static <T> IterableBuilder<T> |
from(java.lang.Iterable<T> source)
Creates a new iterable builder instance by wrapping the given
source sequence, if not already a builder.
|
static <T> IterableBuilder<T> |
from(Observable<T> source)
Creates a new iterable builder by wrapping the given observable.
|
static <T> IterableBuilder<T> |
from(T... ts)
Creates a new iterable builder instance by wrapping the given
array.
|
static <T> IterableBuilder<T> |
fromPart(int from,
int to,
T... ts)
Creates a new iterable builder instance by wrapping the given
array.
|
static <T> IterableBuilder<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.
|
<K> IterableBuilder<Pair<K,IterableBuilder<T>>> |
groupBy(Func1<? super T,? extends K> keySelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values the elements into GroupedIterables,
which can be interated over later on.
|
<K,V> IterableBuilder<Pair<K,IterableBuilder<V>>> |
groupBy(Func1<? super T,? extends K> keySelector,
Func1<? super T,? extends V> valueSelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values extracted by valueSelector into
a pair of Key and IterableBuilder instances,
which can be interated over later on.
|
<K> IterableBuilder<GroupedIterable<K,T>> |
groupBy0(Func1<? super T,? extends K> keySelector)
Creates an iterable which traverses the source iterable,
and based on the key selector, groups values the elements into GroupedIterables,
which can be interated over later on.
|
<K,V> IterableBuilder<GroupedIterable<K,V>> |
groupBy0(Func1<? super T,? extends K> keySelector,
Func1<? super T,? extends V> 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 interated over later on.
|
<U extends java.util.Collection<? super T>> |
into(U out)
Add the elements of the sequence into the supplied collection.
|
IterableBuilder<T> |
invoke(Action1<? super T> action)
Construct a new iterable which will invoke the specified action
before the source value gets relayed through it.
|
IterableBuilder<java.lang.Boolean> |
isEmpty()
Returns a single true if the target iterable is empty.
|
java.util.Iterator<T> |
iterator() |
IterableBuilder<java.lang.String> |
join(java.lang.String separator)
Concatenates the source strings one after another and uses the given separator.
|
T |
last()
Returns the last element of the iterable or throws a
NoSuchElementException if the iterable is empty. |
IterableBuilder<Option<T>> |
materialize()
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.
|
<U extends java.lang.Comparable<? super U>> |
max()
Returns the maximum value of the given iterable source.
|
IterableBuilder<T> |
max(java.util.Comparator<? super T> comparator)
Returns the maximum value of the given iterable source in respect to the supplied comparator.
|
<U extends java.lang.Comparable<? super U>> |
maxBy()
Returns an iterator which will produce a single List of the maximum values encountered
in the source stream based on the supplied key selector.
|
IterableBuilder<java.util.List<T>> |
maxBy(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.
|
<U extends java.lang.Comparable<? super U>> |
mayBy(Func1<? super T,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.
|
<U> IterableBuilder<java.util.List<T>> |
mayBy(Func1<? super T,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.
|
IterableBuilder<T> |
memoize(int bufferSize)
Enumerates the source iterable once and caches its results.
|
IterableBuilder<T> |
memoizeAll()
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.
|
<U extends java.lang.Comparable<? super U>> |
min()
Returns the maximum value of the given iterable source.
|
IterableBuilder<T> |
min(java.util.Comparator<? super T> comparator)
Returns the minimum value of the given iterable source in respect to the supplied comparator.
|
IterableBuilder<java.util.List<T>> |
minBy(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.
|
<U extends java.lang.Comparable<? super U>> |
minBy(Func1<? super T,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.
|
<U> IterableBuilder<java.util.List<T>> |
minBy(Func1<? super T,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.
|
<U extends java.lang.Comparable<? super U>> |
minxBy()
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> IterableBuilder<T> |
newBuilder(java.lang.Iterable<T> source)
Creates a new iterable builder instance by wrapping the given
source sequence.
|
<U extends java.lang.Comparable<? super U>> |
orderBy()
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
IterableBuilder<T> |
orderBy(java.util.Comparator<? super T> comparator)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
<U extends java.lang.Comparable<? super U>> |
orderBy(Func1<? super T,? extends U> keySelector)
Returns an iterable which traverses the entire
source iterable and creates an ordered list
of elements.
|
<U> IterableBuilder<T> |
orderBy(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.
|
void |
print()
Runs this iterable and prints the values.
|
void |
println()
Runs this iterable and prints the values.
|
<U> IterableBuilder<U> |
prune(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)). |
<U> IterableBuilder<U> |
publish(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.
|
<U> IterableBuilder<U> |
publish(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 IterableBuilder<java.lang.Integer> |
range(int start,
int count)
Creates an integer iteratable builder which returns numbers from the start position in the count size.
|
static IterableBuilder<java.lang.Long> |
range(long start,
long count)
Creates an long iterable builder which returns numbers from the start position in the count size.
|
void |
removeAll()
Consumes the sequence and removes all items via the Iterator.remove().
|
static <T> IterableBuilder<T> |
repeat(T t)
Creates an iterable builder which repeats the given
value indefinitely.
|
static <T> IterableBuilder<T> |
repeat(T t,
int count)
Returns an iterable builder which repeats the given single value the specified number of times.
|
<U> IterableBuilder<U> |
replay(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.
|
<U> IterableBuilder<U> |
replay(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.
|
void |
run()
Iterates over the given source without using its returned value.
|
void |
run(Action1<? super T> action)
Iterate over the source and submit each value to the
given action.
|
<U> IterableBuilder<U> |
scan(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.
|
<U> IterableBuilder<U> |
scan(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.
|
<U> IterableBuilder<U> |
select(Func1<? super T,? extends U> selector)
Creates an iterable which is a transforms the source
elements by using the selector function.
|
<U> IterableBuilder<U> |
select(Func2<java.lang.Integer,? super T,? extends U> selector)
Creates an iterable which is a transforms the source
elements by using the selector function.
|
<U> IterableBuilder<U> |
selectMany(Func1<? super T,? extends java.lang.Iterable<? extends U>> selector)
Creates an iterable which returns a stream of Us for each source Ts.
|
IterableBuilder<T> |
share()
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.
|
IterableBuilder<T> |
skipLast(int num)
Returns an iterable which skips the last
num elements from the
source iterable. |
IterableBuilder<T> |
startWith(T value)
Returns an iterable which prefixes the source iterable values
by a constant.
|
IterableBuilder<Pair<T,T>> |
subsequent()
Returns each pair of subsequent elements as pairs.
|
IterableBuilder<IterableBuilder<T>> |
subsequent(int count)
Returns each pair of subsequent elements as pairs.
|
IterableBuilder<java.math.BigDecimal> |
sumBigDecimal()
Computes and signals the sum of the values of the BigDecimal source.
|
IterableBuilder<java.math.BigInteger> |
sumBigInteger()
Computes and signals the sum of the values of the BigInteger source.
|
IterableBuilder<java.lang.Double> |
sumDouble()
Computes and signals the sum of the values of the Double source.
|
IterableBuilder<java.lang.Float> |
sumFloat()
Computes and signals the sum of the values of the Float source.
|
IterableBuilder<java.lang.Integer> |
sumInt()
Computes and signals the sum of the values of the Integer source.
|
IterableBuilder<java.lang.Double> |
sumIntAsDouble()
Computes and signals the sum of the values of the Integer source by using
a double intermediate representation.
|
IterableBuilder<java.lang.Long> |
sumLong()
Computes and signals the sum of the values of the Long source.
|
IterableBuilder<java.lang.Double> |
sumLongAsDouble()
Computes and signals the sum of the values of the Long sourceby using
a double intermediate representation.
|
IterableBuilder<T> |
take(int num)
Returns the iterable which returns the first
num element. |
IterableBuilder<T> |
takeLast(int num)
Returns an iterable which takes only the last
num elements from the
source iterable. |
java.lang.Object[] |
toArray()
Returns an object array of all elements in this
iterable.
|
T[] |
toArray(T[] a)
Returns all elements from this iterable into either
the given array or a new array if the size requires.
|
static <T> Func1<java.lang.Iterable<T>,IterableBuilder<T>> |
toBuilder() |
<K> java.util.Map<K,T> |
toHashMap(Func1<? super T,? extends K> keySelector)
Convinience method to create a hashmap from the elements.
|
<K> java.util.Map<K,java.util.List<T>> |
toHashMultimap(Func1<? super T,? extends K> keySelector)
Convinience method to create a hash-multimap with list from the elements.
|
java.util.List<T> |
toList()
Iterates over and returns all elements in a list.
|
<K> java.util.Map<K,T> |
toMap(Func1<? super T,? extends K> keySelector,
Func0<? extends java.util.Map<K,T>> mapProvider)
Convert the iterable values into a map representation.
|
<K,V> java.util.Map<K,V> |
toMap(Func1<? super T,? extends K> keySelector,
Func1<? super T,? extends V> valueSelector,
Func0<? extends java.util.Map<K,V>> mapProvider)
Convert the iterable values into a map representation.
|
<K,V,C extends java.util.Collection<V>> |
toMultimap(Func1<? super T,? extends K> keySelector,
Func1<? super T,? extends V> valueSelector,
Func0<? extends java.util.Map<K,C>> mapProvider,
Func0<? extends C> collectionProvider)
Convert the values into a multimap representation where each
key can have multiple values.
|
ObservableBuilder<T> |
toObservable()
Converts this iterable into an observable builder
which uses the default scheduler of
Reactive to emit values. |
ObservableBuilder<T> |
toObservable(Scheduler scheduler)
Converts this iterable into an observable builder
which uses the supplied Scheduler to emit values.
|
IterableBuilder<T> |
where(Func1<? super T,java.lang.Boolean> filter)
Creates an iterable which filters this iterable with the
given predicate factory function.
|
IterableBuilder<T> |
where(Func2<java.lang.Integer,? super T,java.lang.Boolean> predicate)
Creates an iterable which filters this iterable with the
given predicate factory function.
|
<U,V> IterableBuilder<V> |
zip(java.lang.Iterable<? extends U> right,
Func2<? super T,? super U,? extends V> combiner)
Pairs each element from this and the oher iterable source and
combines them into a new value by using the
combiner
function. |
protected final java.lang.Iterable<T> it
protected IterableBuilder(@Nonnull
java.lang.Iterable<T> source)
source - the backing iterablepublic static <T> IterableBuilder<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.public static <T> IterableBuilder<T> fromPart(int from, int to, @Nonnull T... ts)
T - the element typefrom - the source index inclusiveto - the destination index exclusivets - the array of tspublic static <T> IterableBuilder<T> from(@Nonnull java.lang.Iterable<T> source)
T - the element typesource - the source sequencepublic static <T> IterableBuilder<T> newBuilder(@Nonnull java.lang.Iterable<T> source)
T - the element typesource - the source sequencepublic static <T> IterableBuilder<T> from(@Nonnull Observable<T> source)
The resulting iterable does not support the remove() method.
T - the element typesource - the source observablepublic static <T> IterableBuilder<T> from(@Nonnull T... ts)
T - the element typets - the array of tspublic static <T> IterableBuilder<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.public static IterableBuilder<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.public static IterableBuilder<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.public static <T> IterableBuilder<T> repeat(T t)
The resulting iterable does not support the remove() method.
T - the element typet - the value to repeatpublic static <T> IterableBuilder<T> repeat(T t, int count)
The returned iterable does not support the remove() method.
T - the value typet - the value to repeatcount - the repeat amountpublic <U,V> IterableBuilder<V> aggregate(@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.U - the itermediate aggregation typeV - the resulting aggregation typesum - the function which takes the current itermediate 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.public IterableBuilder<java.lang.Boolean> all(@Nonnull Func1<? super T,java.lang.Boolean> predicate)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
predicate - the predicatepublic IterableBuilder<java.lang.Boolean> any()
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public IterableBuilder<java.lang.Boolean> any(@Nonnull Func1<? super T,java.lang.Boolean> predicate)
predicate - the predicate tester functionpublic <V extends java.lang.Comparable<? super V>> Pair<T,V> argAndMax(@Nonnull Func1<? super T,? extends V> valueSelector)
V - the value type for the comparison, must be self comparablevalueSelector - the value selector functionpublic <V> Pair<T,V> argAndMax(@Nonnull Func1<? super T,? extends V> valueSelector, @Nonnull java.util.Comparator<? super V> valueComparator)
V - the value typevalueSelector - the selector to extract the value from TvalueComparator - the comparator to compare two valuespublic <V extends java.lang.Comparable<? super V>> Pair<T,V> argAndMin(@Nonnull Func1<? super T,? extends V> valueSelector)
V - the value type for the comparison, must be self comparablevalueSelector - the value selector functionpublic <V> Pair<T,V> argAndMin(@Nonnull Func1<? super T,? extends V> valueSelector, @Nonnull java.util.Comparator<? super V> valueComparator)
V - the value typevalueSelector - the selector to extract the value from TvalueComparator - the comparator to compare two values@Nonnull public IterableBuilder<java.math.BigDecimal> averageBigDecimal()
Note that it uses forced cast of this sequence. If T != BigDecimal this method is guaranteed to throw ClassCastException.
@Nonnull public IterableBuilder<java.math.BigDecimal> averageBigInteger()
Note that it uses forced cast of this sequence. If T != BigInteger this method is guaranteed to throw ClassCastException.
@Nonnull public IterableBuilder<java.lang.Double> averageDouble()
@Nonnull public IterableBuilder<java.lang.Float> averageFloat()
@Nonnull public IterableBuilder<java.lang.Double> averageInt()
@Nonnull public IterableBuilder<java.lang.Double> averageLong()
public IterableBuilder<java.util.List<T>> buffer(int bufferSize)
bufferSize lists.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
bufferSize - the buffer size.public <U> IterableBuilder<U> cast(@Nonnull java.lang.Class<U> token)
next()
will throw a ClassCastException.
The returned iterator forwards all remove() calls
to the source.
U - the result element typetoken - the type tokenpublic IterableBuilder<T> concat(@Nonnull java.lang.Iterable<? extends T> other)
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).
other - the second iterablepublic IterableBuilder<T> concat(@Nonnull T... values)
values - the array valuespublic IterableBuilder<T> concatAll(@Nonnull java.lang.Iterable<? extends java.lang.Iterable<? extends T>> others)
others - the other iterablespublic IterableBuilder<java.lang.Boolean> contains(T value)
equals(). The iterable then returns a single true or false.value - the value to checkpublic IterableBuilder<java.lang.Integer> count()
int.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public IterableBuilder<java.lang.Long> countLong()
long.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public IterableBuilder<T> dematerialize()
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public IterableBuilder<T> distinctNext()
public <U> IterableBuilder<T> distinctNext(@Nonnull Func1<T,U> keySelector)
U - the key typekeySelector - the function to extract the keys which will be comparedpublic IterableBuilder<T> distinct()
equals()public <U> IterableBuilder<T> distinct(@Nonnull Func1<? super T,? extends U> keySelector)
equals()U - the key element typekeySelector - the key selector for only-once filtering@Nonnull public IterableBuilder<T> doWhile(@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.
gate - the gate function to stop the repeatpublic IterableBuilder<T> endWith(T value)
The returned iterable forwards all remove()
methods to the source iterable, except the last element where it
throws UnsupportedOperationException.
value - the value to appendpublic IterableBuilder<T> finish(@Nonnull Action0 action)
The returned iterator forwards all remove() calls
to the source.
action - the action to invokepublic T first()
public <K,V> IterableBuilder<GroupedIterable<K,V>> groupBy0(@Nonnull Func1<? super T,? extends K> keySelector, Func1<? super T,? extends V> valueSelector)
equals() equality.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
K - the result group element typeV - the result group keyskeySelector - the key selectorvalueSelector - the value selectorpublic <K> IterableBuilder<GroupedIterable<K,T>> groupBy0(@Nonnull Func1<? super T,? extends K> keySelector)
equals() equality.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
K - the result group element typekeySelector - the key selectorpublic <K> IterableBuilder<Pair<K,IterableBuilder<T>>> groupBy(@Nonnull Func1<? super T,? extends K> keySelector)
equals() equality.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
K - the result group element typekeySelector - the key selectorpublic <K,V> IterableBuilder<Pair<K,IterableBuilder<V>>> groupBy(@Nonnull Func1<? super T,? extends K> keySelector, Func1<? super T,? extends V> valueSelector)
equals() equality.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
K - the result group element typeV - the result group keyskeySelector - the key selectorvalueSelector - the value selectorpublic IterableBuilder<T> invoke(@Nonnull Action1<? super T> action)
The returned iterator forwards all remove() calls
to the source.
action - the action to invoke before each next() is returned.public IterableBuilder<java.lang.Boolean> isEmpty()
public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public IterableBuilder<java.lang.String> join(java.lang.String separator)
The returned iterator forwards all remove() calls
to the source.
separator - the separator to usepublic T last()
NoSuchElementException if the iterable is empty.public IterableBuilder<Option<T>> materialize()
UnsupportedOperationException for its remove() method.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public <U extends java.lang.Comparable<? super U>> IterableBuilder<U> max()
U - the self comparable typepublic IterableBuilder<T> max(@Nonnull java.util.Comparator<? super T> comparator)
comparator - the comparator to usepublic <U extends java.lang.Comparable<? super U>> IterableBuilder<java.util.List<U>> maxBy()
U - the source element type, which must be self comparablepublic IterableBuilder<java.util.List<T>> maxBy(@Nonnull java.util.Comparator<? super T> comparator)
comparator - the key comparatorpublic <U extends java.lang.Comparable<? super U>> IterableBuilder<java.util.List<T>> mayBy(@Nonnull Func1<? super T,U> keySelector)
U - the key type, which must be self-comparablekeySelector - the selector for keyspublic <U> IterableBuilder<java.util.List<T>> mayBy(@Nonnull Func1<? super T,U> keySelector, @Nonnull java.util.Comparator<? super U> keyComparator)
U - the key typekeySelector - the selector for keyskeyComparator - the key comparatorpublic IterableBuilder<T> memoize(int bufferSize)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
bufferSize - the size of the bufferingpublic IterableBuilder<T> memoizeAll()
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public <U extends java.lang.Comparable<? super U>> IterableBuilder<U> min()
U - the self comparable typepublic IterableBuilder<T> min(@Nonnull java.util.Comparator<? super T> comparator)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
comparator - the comparator to usepublic IterableBuilder<java.util.List<T>> minBy(@Nonnull java.util.Comparator<? super T> comparator)
comparator - the key comparatorpublic <U extends java.lang.Comparable<? super U>> IterableBuilder<java.util.List<T>> minBy(@Nonnull Func1<? super T,U> keySelector)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
U - the key type, which must be self-comparablekeySelector - the selector for keyspublic <U> IterableBuilder<java.util.List<T>> minBy(@Nonnull Func1<? super T,U> keySelector, @Nonnull java.util.Comparator<? super U> keyComparator)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
U - the key typekeySelector - the selector for keyskeyComparator - the key comparatorpublic <U extends java.lang.Comparable<? super U>> IterableBuilder<java.util.List<U>> minxBy()
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
U - the source element type, which must be self comparablepublic <U extends java.lang.Comparable<? super U>> IterableBuilder<U> orderBy()
Note: the element type should be self comparable or a ClassCastException is thrown.
U - the source element type, which must be self comparablepublic IterableBuilder<T> orderBy(@Nonnull java.util.Comparator<? super T> comparator)
comparator - the value comparatorpublic <U extends java.lang.Comparable<? super U>> IterableBuilder<T> orderBy(@Nonnull Func1<? super T,? extends U> keySelector)
U - the key type for the ordering, must be self comparablekeySelector - the key selector for comparisonpublic <U> IterableBuilder<T> orderBy(@Nonnull Func1<? super T,? extends U> keySelector, @Nonnull java.util.Comparator<? super U> keyComparator)
U - the key type for the orderingkeySelector - the key selector for comparisonkeyComparator - the key comparator functionpublic <U> IterableBuilder<U> prune(@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)).U - the return typesfunc - invoke the function on the buffering iterable and return an iterator over it.public <U> IterableBuilder<U> publish(@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.
U - the return typesfunc - invoke the function on the buffering iterable and return an iterator over it.initial - the initial value to append to the output streampublic <U> IterableBuilder<U> publish(@Nonnull Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
U - the return typesfunc - invoke the function on the buffering iterable and return an iterator over it.public <U> IterableBuilder<U> replay(@Nonnull Func1<? super java.lang.Iterable<T>,? extends java.lang.Iterable<U>> func)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
U - the return typesfunc - invoke the function on the buffering iterable and return an iterator over it.public <U> IterableBuilder<U> replay(@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.
U - the return typesfunc - invoke the function on the buffering iterable and return an iterator over it.bufferSize - the buffer sizepublic void run()
public void run(@Nonnull
Action1<? super T> action)
action - the action to invoke on with elementpublic <U> IterableBuilder<U> scan(@Nonnull Func2<? super U,? super T,? extends U> aggregator)
U - the destination element typeaggregator - the function which takes the current running aggregation value, the current element and produces a new aggregation value.public <U> IterableBuilder<U> scan(U seed, @Nonnull Func2<? super U,? super T,? extends U> aggregator)
The returned iterator forwards all remove() calls
to the source.
U - the destination element typeseed - 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.public <U> IterableBuilder<U> select(Func1<? super T,? extends U> selector)
U - the output element typeselector - the selector functionpublic <U> IterableBuilder<U> select(@Nonnull Func2<java.lang.Integer,? super T,? extends U> selector)
The returned iterator forwards all remove() calls
to the source.
U - the output element typeselector - the selector functionpublic <U> IterableBuilder<U> selectMany(@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).
U - the output element typeselector - the selector for multiple Us for each Tpublic IterableBuilder<T> share()
public IterableBuilder<T> skipLast(int num)
num elements from the
source iterable.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
num - the number of elements to skip at the endpublic IterableBuilder<T> startWith(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.
value - the value to prefix@Nonnull public IterableBuilder<java.math.BigDecimal> sumBigDecimal()
@Nonnull public IterableBuilder<java.math.BigInteger> sumBigInteger()
@Nonnull public IterableBuilder<java.lang.Double> sumDouble()
@Nonnull public IterableBuilder<java.lang.Float> sumFloat()
@Nonnull public IterableBuilder<java.lang.Integer> sumInt()
@Nonnull public IterableBuilder<java.lang.Double> sumIntAsDouble()
@Nonnull public IterableBuilder<java.lang.Long> sumLong()
@Nonnull public IterableBuilder<java.lang.Double> sumLongAsDouble()
public IterableBuilder<T> take(int num)
num element.
from the source iterable.
The returned iterator forwards all remove() calls
to the source.
num - the number of items to takepublic IterableBuilder<T> takeLast(int num)
num elements from the
source iterable.
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
num - the number of elements to skip at the end@Nonnull public java.lang.Object[] toArray()
@Nonnull public T[] toArray(T[] a)
a - the output array@Nonnull public java.util.List<T> toList()
public ObservableBuilder<T> toObservable()
Reactive to emit values.public ObservableBuilder<T> toObservable(@Nonnull Scheduler scheduler)
scheduler - the schedulerpublic IterableBuilder<T> where(Func1<? super T,java.lang.Boolean> filter)
The returned iterator forwards all remove() calls
to the source.
filter - the predicate functionpublic IterableBuilder<T> where(@Nonnull Func2<java.lang.Integer,? super T,java.lang.Boolean> predicate)
predicate - the predicatepublic <U,V> IterableBuilder<V> zip(@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.
U - the right source typeV - the result typeright - the right sourcecombiner - the combiner functionpublic void print()
Is the same as using this.run(Interactive.print()).
public void println()
Is the same as using this.run(Interactive.println()).
public <K,V> java.util.Map<K,V> toMap(Func1<? super T,? extends K> keySelector, Func1<? super T,? extends V> valueSelector, Func0<? extends java.util.Map<K,V>> mapProvider)
If an element maps to the same key, the existing value will be overwritten.
K - the key typeV - the value typekeySelector - the function to extract a key from an elementvalueSelector - the function to extract a value from an elementmapProvider - the map providerpublic <K> java.util.Map<K,T> toMap(Func1<? super T,? extends K> keySelector, Func0<? extends java.util.Map<K,T>> mapProvider)
If an element maps to the same key, the existing value will be overwritten.
See Functions.hashMapProvider() and others for some standard map implementations.
K - the key typekeySelector - the function to extract a key from an elementmapProvider - the map providerpublic <K,V,C extends java.util.Collection<V>> java.util.Map<K,C> toMultimap(Func1<? super T,? extends K> keySelector, Func1<? super T,? extends V> valueSelector, Func0<? extends java.util.Map<K,C>> mapProvider, Func0<? extends C> collectionProvider)
See Functions.hashMapProvider(), Functions.arrayListProvider() and others for some standard map implementations.
K - the key typeV - the value typeC - the collection typekeySelector - the key selectorvalueSelector - the value selectormapProvider - the provider for the base mapcollectionProvider - the provider for the value collectionpublic <K> java.util.Map<K,T> toHashMap(Func1<? super T,? extends K> keySelector)
K - the key typekeySelector - the key selectorpublic <K> java.util.Map<K,java.util.List<T>> toHashMultimap(Func1<? super T,? extends K> keySelector)
K - the key typekeySelector - the key selectorpublic IterableBuilder<Pair<T,T>> subsequent()
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
public IterableBuilder<IterableBuilder<T>> subsequent(int count)
The returned iterator will throw an UnsupportedOperationException
for its remove() method.
count - the number of subsequent elementspublic static <T> Func1<java.lang.Iterable<T>,IterableBuilder<T>> toBuilder()
T - the element typepublic <U extends java.util.Collection<? super T>> U into(@Nonnull U out)
U - a collection typeout - the output collectionpublic void removeAll()
@Nonnull public <U> ObservableBuilder<U> concat(@Nonnull Func1<? super T,? extends Observable<? extends U>> resultSelector)
U - the result sequence typeresultSelector - the observable selector function