|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
A - the type of object the stream is source ofpublic interface Stream<A>
A Stream is a lazy, rich-interfaced, Iterable, chained
functional-style object that can retrieve and process an arbitrary - and
potentially unbound - amount of other objects of a parameterized type. Such
objects are called elements, and are generated by another object, called
source. Some examples of elements and its source are:
#equals(Object), #hashCode() nor
#toString()Serializable Thus, they should
not be used as attributes of long-living objects.Object like #toString() and
#hashCode(). None of those methods affect the transformation nor the
underlying sourceSizeAware.isEmpty(): it may be sent multiple times and grants consistent
results as long as no other message except of those at previous item is sent.
This message does not affect the transformation, but may modify the
underlying sourceRepeatable, like force() or Streams.cons(Object).
Such streams may be reused and receive any message any number of times, and
grant consistent results, including repeatable iteration order.Projection are lazy. Such methods do also work
with very large o potentially infinte streams. Methods not annotated that way
will not work on infinite streams, as they will never end
normallyStreams class. Other concrete streams are be provided by
other staccato-commons libraries.
Aside from these concrete streams, client code may also implement new ones.
In order to do that, it must not implement this interface
directly, but inherit from AbstractStream, which implements all
methods except of iterator()
| Nested Class Summary | |
|---|---|
static interface |
Stream.DeconsApplicable<A,B>
An Applicable2 that can transform a Stream by
deconstructing it into head and tail, or into an empty stream. |
static interface |
Stream.DelayedDeconsApplicable<A,B>
An Applicable2 that can transform a Stream by
deconstructing it into head thunk and tail, or into an empty stream. |
static interface |
Stream.EmptyApplicable<A>
|
| Method Summary | ||
|---|---|---|
boolean |
all(Evaluable<? super A> predicate)
Tests if all elements satisfy the given Evaluable |
|
boolean |
allEquiv()
Tests if all elements are equal |
|
boolean |
allEquivBy(Evaluable2<? super A,? super A> equivTest)
Tests if all elements are equivalent, using the given equivTest |
|
A |
any()
Returns the head() of this Stream
The different between head() and any() is strictly semantic:
use this message instead of head() whenever the code needs an
unspecified element, rather than the first element of the stream. |
|
boolean |
any(Evaluable<? super A> predicate)
Tests if at least one element satisfies the given Evaluable |
|
A |
anyOrElse(A value)
Shorthand for anyOrNone().valueOrElse(value) |
|
A |
anyOrElse(Thunk<A> thunk)
Shorthand for anyOrNone().valueOrElse(thunk) |
|
Option<A> |
anyOrNone()
Returns the head() of the given Stream, just like any(),
but as an option. |
|
A |
anyOrNull()
Shorthand for anyOrNone().valueOrNull() |
|
Stream<A> |
append(A element)
Adds an element as the last one of the stream. |
|
Stream<A> |
append(Iterable<A> other)
Deprecated. use concat(Iterable) instead |
|
Stream<A> |
append(Thunk<A> thunk)
Deprecated. use delayedAppend(Thunk) instead |
|
Stream<A> |
appendUndefined()
Concatenates this Stream with the undefined Stream. |
|
A |
average(NumberType<A> numberType)
Answers the average of the stream elements, using the given NumberType for performing addition and division. |
|
|
branch(Applicable<? super A,? extends B> function0,
Applicable<? super A,? extends C> function1)
Answers a Stream of pairs, where each one contains both results of applying the given functions. |
|
|
clone(Applicable<? super A,? extends B> function)
Answers a stream that retrieves a tuple per each element, formed by the original element as the first component, and the result of applying the given function to it as the second component. |
|
Stream<A> |
concat(A... elements)
Concatenates this with the given elements
It answers an Stream that retrieves elements from this Stream, and
then, after its last element, the given elements. |
|
Stream<A> |
concat(Iterable<? extends A> other)
Concatenates this with other
It answers an Stream that retrieves elements from this Stream, and
then, after its last element, from the given iterable. |
|
Stream<A> |
concat(Iterator<? extends A> other)
Concatenates this with the given Iterator
It answers an Stream that retrieves elements from this Stream, and
then, after its last element, the given iterator's elements. |
|
boolean |
containsBefore(A element,
A reference)
Answers if element is contained by this stream, and its first
occurence is before the first occurence of the second one, if any. |
|
boolean |
containsBeforeIndex(A element,
int index)
Answers if element is contained by this stream, and its first
occurence is before the given index. |
|
int |
countOf(Evaluable<? super A> predicate)
Answers the number of element that satisfy the given predicate |
|
Stream<Tuple2<A,A>> |
cross()
Answers the Cartesian product of this stream and itself |
|
|
cross(B... elements)
Answers the cartesian product of this Stream and the given
elements. |
|
|
cross(Iterable<B> other)
Answers the cartesian product of this Stream and the given
Iterable |
|
|
cross(Iterator<B> other)
Answers the cartesian product of this Stream and the given
Iterator |
|
|
cross(Stream<B> other)
Answers the Cartesian product of this stream and the given one |
|
Stream<Stream<A>> |
crossStreams(Stream<Stream<A>> streamOfStreams)
Answers the cartesian product of this Stream and each one of the
given streamOfStreams |
|
Tuple2<A,Stream<A>> |
decons()
Answers this stream split into head and tail. |
|
Stream<A> |
delayedAppend(Thunk<A> thunk)
Adds an element's thunk as the last one of the stream. |
|
Tuple2<Thunk<A>,Stream<A>> |
delayedDecons()
Answers this non-empty stream split into a head thunk and tail. |
|
Stream<A> |
delayedPrepend(Thunk<A> thunk)
Adds an element's thunk as the first one of the stream. |
|
Stream<A> |
drop(int amountOfElements)
Discards up to N elements from this Stream. |
|
Stream<A> |
dropWhile(Evaluable<? super A> predicate)
Discards all elements while they satisfy the given predicate |
|
Stream<A> |
each(Executable<? super A> block)
Maps the given side effect over this stream, by answering a Stream
that lazily applies the given side effect over each stream elements, and
retrieves them. |
|
boolean |
equiv(A... elements)
Test that the elements of this stream are equal to the elements of the given array, and in the same order. |
|
boolean |
equiv(Iterable<? extends A> other)
Test that the elements of this stream are equal to the elements of the given Iterable, and in the same order. |
|
boolean |
equiv(Iterator<? extends A> other)
Test that the elements of this stream are equal to the elements of the given iterator, and in the same order. |
|
boolean |
equivBy(Evaluable2<? super A,? super A> equalityTest,
A... elements)
Test that the elements of this stream are equivalent to the given elements, and in the same order, using the given
equalityTest for determining equivalence between elements. |
|
boolean |
equivBy(Evaluable2<? super A,? super A> equalityTest,
Iterable<? extends A> iterable)
Test that the elements of this stream are equivalent to the elements of the given Iterable, and in the same order, using the given
equalityTest for determining equivalence between elements. |
|
boolean |
equivBy(Evaluable2<? super A,? super A> equalityTest,
Iterator<? extends A> other)
Test that the elements of this stream are equivalent to the elements of the given Iterable, and in the same order, using the given
equalityTest for determining equivalence between elements. |
|
|
equivOn(Applicable<? super A,? extends B> function,
A... elements)
Test that the elements of this stream are equivalent to the given elements, and in the same order, using the Equiv.on(function) for
determining equivalence between elements. |
|
|
equivOn(Applicable<? super A,? extends B> function,
Iterable<? extends A> iterable)
Test that the elements of this stream are equivalent to the elements of the given Iterable, and in the same order, using the
Equiv.on(function) for determining equivalence between
elements. |
|
|
equivOn(Applicable<? super A,? extends B> function,
Iterator<? extends A> other)
Test that the elements of this stream are equivalent to the elements of the given Iterator, and in the same order, using the
Equiv.on(function) for determining equivalence between
elements. |
|
Stream<A> |
filter(Evaluable<? super A> predicate)
Preserves elements that satisfy the given predicate
Example:
//Answers stream [hello, world], which has only strings whose length is 5
Streams.cons("a", "hello", "world", "of", "streams", "!"). |
|
Stream<A> |
filterIndex(Evaluable<Integer> predicate)
Preserves elements that whose index satisfy the given predicate |
|
A |
find(Evaluable<? super A> predicate)
Looks for a element that satisfies the given Evaluable. |
|
int |
findIndex(Evaluable<? super A> predicate)
Answers the zero-based index of first element that matches the given predicate |
|
A |
findOrElse(Evaluable<? super A> predicate,
A element)
Looks for an element that satisfies the given Evaluable. |
|
A |
findOrElse(Evaluable<? super A> predicate,
Thunk<? extends A> thunk)
Looks for an element that satisfies the given Evaluable. |
|
Option<A> |
findOrNone(Evaluable<? super A> predicate)
Looks for an element that satisfies the given Evaluable. |
|
A |
findOrNull(Evaluable<? super A> predicate)
Looks for an element that satisfies the given Evaluable. |
|
int |
findPosition(Evaluable<? super A> predicate)
Answers the zero-based index of first, present element that matches the given predicate. |
|
A |
first()
Answers the first element. |
|
|
flatMap(Function<? super A,? extends Iterable<? extends B>> function)
Transformes each element into an iterable using the given function, and concatenates (flattens) the result |
|
|
flatMapArray(Function<? super A,? extends B[]> function)
Transformes each element into an array using the given function, and concatenates (flattens) the result |
|
|
fold(B initial,
Applicable2<? super B,? super A,? extends B> function)
(Left)folds this Stream using an initial value and the given
two-arg function, producing a single aggregated result from all the Stream
elements. |
|
Stream<A> |
force()
Forces stream elements evaluation by converting it into a new ordered stream one that is not lazy and that has repeatable iteration order. |
|
void |
forEach(Executable<? super A> block)
Executes the given Executable block for each element. |
|
A |
get(int n)
Answers the n-th element. |
|
|
groupOn(Applicable<? super A,K> groupFunction,
Reduction<A,V> reduction)
Groups elements by the given groupingFunction, and reduces each
group using the given reduction. |
|
A |
head()
Answers the head of the Stream, which is the first element of the
stream. |
|
Stream<A> |
incorporate(A element)
Inserts the given value after each element of the stream. |
|
Stream<A> |
incorporate(Function<? super A,? extends A> function)
Inserts after each element the result of applying the given function to it. |
|
int |
indexOf(A element)
Answers the zero-based index of the given element |
|
Stream<Integer> |
indices(Evaluable<? super A> predicate)
Answers a stream containing all the zero-based indices of the elements that matches the given predicate |
|
Stream<A> |
insertBefore(A element,
A reference)
Inserts element before the first occurrence of reference. |
|
Stream<A> |
insertBeforeIndex(A element,
int index)
Inserts element at index - 1. |
|
Stream<A> |
intersperse(A element)
Inserts the given element between each retrieved element of
this Stream |
|
boolean |
isBefore(A previous,
A next)
Answers if both arguments are contained by this stream, and the first one is before the second one. |
|
Thriterator<A> |
iterator()
|
|
String |
joinStrings(String separator)
(Left)folds this Stream concatenating each elements toString with a
separator |
|
A |
last()
Answers the last element of this stream. |
|
|
map(Applicable<? super A,? extends B> function)
Transforms each element using the given function |
|
|
map(Function<? super A,? extends B> function)
Transforms each element using the given function. |
|
A |
maximum()
Answers the maximum element of the stream, using elements natural order. |
|
A |
maximumBy(Comparator<? super A> comparator)
Answers the maximum element of the stream, using the given comparator to compare elements. |
|
|
maximumOn(Applicable<? super A,B> function)
Answers the maximum element of the stream, using the given Compare.on(function) to compare elements. |
|
Stream<A> |
memoize()
Memoizes stream elements and their order, by answering a lazy stream with Repeatable iteration order that caches elements evaluated during
iteration. |
|
Stream<A> |
memorize()
Deprecated. the exact name of this concept is memoization, not memorization. Use memoize() instead |
|
A |
minimum()
Answers the minimum element of the stream, using elements natural order. |
|
A |
minimumBy(Comparator<? super A> comparator)
Answers the min element of the stream, using the given comparator to compare elements. |
|
|
minimumOn(Applicable<? super A,B> function)
Answers the minimum element of the stream, using the given Compare.on(function) to compare elements. |
|
Tuple2<List<A>,List<A>> |
partition(Evaluable<? super A> predicate)
Splits stream elements into two lists using a predicate - elements that evaluate to true will be returned in the first component, the rest will be returned in the second component |
|
int |
positionOf(A element)
Answers the index of the given present element. |
|
Stream<A> |
prepend(A element)
Adds an element as the first one of the stream. |
|
Stream<A> |
prepend(Thunk<A> thunk)
Deprecated. use delayedPrepend(Thunk) |
|
void |
print()
Prints the stream elements to System.out |
|
void |
print(Appendable destination)
Prints the stream elements to an appendable, like StringBuilder or
a Writer |
|
void |
println()
Prints the stream elements to System.out, followed by a newline
character. |
|
void |
println(Appendable o)
Prints the stream elements to an appendable, like StringBuilder or
a Writer, followed by a newline character |
|
String |
printString()
Prints the stream elements to a string |
|
A |
product(NumberType<A> numberType)
Answers the product of the elements of this Stream using the given
NumberType |
|
A |
reduce(Applicable2<? super A,? super A,? extends A> function)
(Left)folds the tail of this Stream using the first element of the
stream as initial value, producing a single aggregated result from all the
Stream elements. |
|
|
reduce(Reduction<? super A,B> reduction)
Answers the result of aggregating this stream using the given reduction |
|
Stream<A> |
reverse()
Reverses this Stream, by returning a new Stream that retrieves elements in the inverse order of this Stream. |
|
A |
second()
Answers the second element. |
|
Stream<A> |
skip(A element)
Preserves all elements but those that are equal to the given one. |
|
Stream<A> |
skipIndex(int index)
Answers a streams that retrieves all the elements of this one, except of that at the given index |
|
Stream<A> |
slice(int beginIndex,
int endIndex)
Answers a stream that is a substream of this one. |
|
Stream<A> |
sort()
Sorts this Stream, using their element's natural ordering |
|
Stream<A> |
sortBy(Comparator<A> comparator)
Sorts this Stream, using the given comparator |
|
|
sortOn(Applicable<? super A,B> function)
Sorts this Stream, using Compare.on(function) as comparator |
|
Tuple2<Stream<A>,Stream<A>> |
streamPartition(Evaluable<? super A> predicate)
Splits stream elements into two ordered streams, that support random access. |
|
A |
sum(NumberType<A> numberType)
Answers the sum of the elements of this Stream using the given
NumberType |
|
Stream<A> |
tail()
Answers the tail of the Stream |
|
Stream<A> |
take(int amountOfElements)
Preserves up to N elements. |
|
Stream<A> |
takeWhile(Evaluable<? super A> predicate)
Preserves all elements while they satisfy the given predicate |
|
A |
third()
Answers the third element. |
|
A[] |
toArray(Class<? super A> clazz)
Creates a new array that has the same elements that the retrived by this Stream |
|
List<A> |
toList()
* Converts this Stream into a List, by adding all its elements to a
new List. |
|
Set<A> |
toSet()
Converts this Stream into a Set, by adding all its elements to a
new Set. |
|
|
transform(Applicable<Stream<A>,? extends Stream<B>> function)
Lazily applies the given function to this Stream. |
|
|
transform(Stream.DeconsApplicable<A,B> function)
Lazily applies the given function to this stream,
deconstructing this stream into head and tail, or into an empty stream. |
|
|
transform(Stream.DelayedDeconsApplicable<A,B> function)
Lazily applies the given function to this stream,
deconstructing this stream into a head thunk and tail, or into an empty
stream. |
|
|
zip(B... elements)
Returns a Stream formed by by pair of element from
this and the given elements. |
|
|
zip(Iterable<B> iterable)
Returns a Stream formed by by pair of element from
this and the given iterable. |
|
|
zip(Iterable<B> iterable,
Function2<? super A,? super B,C> function)
Deprecated. use zipWith(Function2, Iterable) |
|
|
zip(Iterator<B> other)
Returns a Stream formed by by pair of element from
this and the given Iterator. |
|
|
zipWith(Function2<? super A,? super B,C> function,
B... elements)
Returns a Stream formed by the result of applying the given
function to each pair of elements from this and
the given iterable. |
|
|
zipWith(Function2<? super A,? super B,C> function,
Iterable<B> other)
Returns a Stream formed by the result of applying the given
function to each pair of elements from this and
the given iterable. |
|
|
zipWith(Function2<? super A,? super B,C> function,
Iterator<B> other)
Returns a Stream formed by the result of applying the given
function to each pair of elements from this and
the other. |
|
| Methods inherited from interface net.sf.staccatocommons.defs.partial.ContainsAware |
|---|
contains |
| Methods inherited from interface net.sf.staccatocommons.defs.ProtoMonad |
|---|
replace, replaceNull, skipNull |
| Methods inherited from interface net.sf.staccatocommons.defs.partial.SizeAware |
|---|
isEmpty, size |
| Method Detail |
|---|
Thriterator<A> iterator()
iterator in interface Iterable<A>
void forEach(@NonNull
Executable<? super A> block)
Executable block for each element.
This message is equivalent to a for-each loop over this Stream
forEach in interface ProtoMonad<Stream<A>,Stream,A>block -
@Projection
Stream<A> each(@NonNull
Executable<? super A> block)
Stream
that lazily applies the given side effect over each stream elements, and
retrieves them.
each in interface ProtoMonad<Stream<A>,Stream,A>block -
map(Functions.impure(block)forEach(Executable), 1.2 current version, incompatible with previous 1.1
@Projection
<B> Stream<B> map(@NonNull
Applicable<? super A,? extends B> function)
map in interface ProtoMonad<Stream<A>,Stream,A>B - function - the mapper used to transform each element, applying it
Stream projection that will retrieve the result of
applying the given function to each element
@Projection
Stream<A> filter(@NonNull
Evaluable<? super A> predicate)
predicate
Example:
//Answers stream [hello, world], which has only strings whose length is 5
Streams.cons("a", "hello", "world", "of", "streams", "!").filter(length().equal(5));
filter in interface ProtoMonad<Stream<A>,Stream,A>predicate -
Stream projection that will retrieve only elements
that evaluate to true
@Projection
Stream<A> skip(@NonNull
A element)
filter(Predicates.equal(element).not())
skip in interface ProtoMonad<Stream<A>,Stream,A>element -
Stream that retrieves all elements that are not equal to
the given one
@Projection
Stream<A> takeWhile(@NonNull
Evaluable<? super A> predicate)
predicate
predicate -
Stream projection that will retrieve all elements
from this stream, as long as none of them evaluates to false.
@Projection
Stream<A> take(@NotNegative
int amountOfElements)
amountOfElements, the resulting stream will retrieve the same
elements than this stream.
amountOfElements -
Stream projection that will retrieve up to N elements
@Projection
Stream<A> dropWhile(@NonNull
Evaluable<? super A> predicate)
predicate
predicate -
Stream projection that will skip all elements as long
as they satisfy the given Evaluable
@Projection
Stream<A> drop(@NotNegative
int amountOfElements)
Stream. Is the Stream size is
shorter than the given amountOfElements, the resulting stream
will be empty.
amountOfElements - the amount of elements to discard
Stream that discards up to the given
amountOfElements
@Projection
Stream<A> slice(@NotNegative
int beginIndex,
@NotNegative
int endIndex)
beginIndex, and extends to the element at index
endIndex - 1, if it has enough elements, or up to its last element,
otherwise.
The resulting stream is always finite, and satisfies that
size() <= endIndex - beginIndex
As a particular case, if beginIndex == endIndex, an empty stream is
returned.
Examples:
Streams.from("hamburger").slice(4, 8).joinStrings(""); //answers "urge"
Streams.from("smiles").slice(1, 5).joinStrings(""); //answers "mile"
Streams.from("hello world!").slice(6, 309).joinStrings(""); //answers "world!"
Streams.enumerate(1,20).slice(5,5).toList(); //answers []
beginIndex - the lower bound, inclusiveendIndex - the upper bound, exclusive
drop(beginIndex).take(endIndex - beginIndex)
@NonNull
Tuple2<List<A>,List<A>> partition(@NonNull
Evaluable<? super A> predicate)
predicate -
Tuple2 that contains this stream partitioned into two
lists.
@NonNull
Tuple2<Stream<A>,Stream<A>> streamPartition(@NonNull
Evaluable<? super A> predicate)
partition(Evaluable) into Streams.
predicate -
Tuple2 that contains this stream partitioned into two
other streams.
@Projection
<B> Stream<B> map(@NonNull
Function<? super A,? extends B> function)
import static import net.sf.staccatocommons.util.Strings.*;
//Answers [HELLO, WORLD, STREAMS]
Streams.cons("hello", "world", "streams").map(toUpperCase());
import static net.sf.staccatocommons.numbers.NumberTypes.*; ... //answers Stream [6, 9, 11, 26] Streams.cons(5, 8, 10, 25).map(add(1)).println();
B - function - the mapper used to transform each element, applying it
Stream projection that will retrieve the result of
applying the given function to each element
@Projection
<B> Stream<B> flatMap(@NonNull
Function<? super A,? extends Iterable<? extends B>> function)
B - function -
Stream that will retrieve the result of transforming
each element and concatenating those transformations
@Projection
<B> Stream<B> flatMapArray(@NonNull
Function<? super A,? extends B[]> function)
B - function -
Stream that will retrieve the result of transforming
each element and concatenating those trsansformations@NonNull Stream<A> reverse()
Projection, depending on if the stream's source
permits it.
Stream that retrieves elements in the inverse order
of this stream.
A any()
throws EmptySourceException
head() of this Stream
The different between head() and any() is strictly semantic:
use this message instead of head() whenever the code needs an
unspecified element, rather than the first element of the stream.
head()
EmptySourceException - if this Stream has no elements.@NonNull Option<A> anyOrNone()
head() of the given Stream, just like any(),
but as an option. If Stream has no elements, instead of throwing a
EmptySourceException, it returns None
Option.some(element) if there is at least one element,
or Option.none(), otherwise.A anyOrNull()
anyOrNone().valueOrNull()
anyOrNone().valueOrNull()
A anyOrElse(@NonNull
Thunk<A> thunk)
anyOrNone().valueOrElse(thunk)
thunk -
anyOrNone().valueOrElse(thunk)A anyOrElse(A value)
anyOrNone().valueOrElse(value)
value -
anyOrNone().valueOrElse(value)
A find(@NonNull
Evaluable<? super A> predicate)
throws EmptySourceException,
NoSuchElementException
Evaluable. If such
element does not exist, throws NoSuchElementException
predicate -
EmptySourceException - if this stream is empty
NoSuchElementException - if no element matches the predicate.
@NonNull
Option<A> findOrNone(@NonNull
Evaluable<? super A> predicate)
Evaluable. If such
element exists, returns some(element). Otherwise, returns
None.
predicate -
None if Stream is empty, regardless of the given
predicate
A findOrNull(@NonNull
Evaluable<? super A> predicate)
Evaluable. If such
element exists, returns it. Otherwise, returns null.
predicate -
Stream is empty, regardless of
the given predicate
A findOrElse(@NonNull
Evaluable<? super A> predicate,
@NonNull
Thunk<? extends A> thunk)
Evaluable. If such
element exists, returns it. Otherwise, returns the given thunk's value.
predicate -
thunk.value() if no element matches the predicate, or
an element that satisfies it, if at least one exists. As a
particular case, this method will return the thunk's value if
Stream is empty, regardless of the given predicate
A findOrElse(@NonNull
Evaluable<? super A> predicate,
@NonNull
A element)
Evaluable. If such
element exists, returns it. Otherwise, returns the given
element .
predicate -
findOrElse(predicate, Thunks.constant(element))
boolean all(@NonNull
Evaluable<? super A> predicate)
Evaluable
predicate - an Evaluable to evaluate each element
boolean allEquiv()
boolean allEquivBy(Evaluable2<? super A,? super A> equivTest)
equivTest
equivTest - an Evaluable2 used to testing if an element is equivalent
to another
boolean any(@NonNull
Evaluable<? super A> predicate)
Evaluable
predicate - an Evaluable to evaluate each element
boolean equiv(A... elements)
elements -
true if this stream has the same number of elements
that the given array, and each pair formed by elements of this
stream and the given array at same position are equal.
false otherwiseboolean equiv(Iterable<? extends A> other)
Iterable, and in the same order.
other -
other, and each pair formed by elements of this
stream and given iterable at same position are equal.
false otherwiseboolean equiv(Iterator<? extends A> other)
iterator, and in the same order.
iterable -
other, and each pair formed by elements of this
stream and given iterable at same position are equal.
false otherwise
boolean equivBy(@NonNull
Evaluable2<? super A,? super A> equalityTest,
@NonNull
Iterable<? extends A> iterable)
Iterable, and in the same order, using the given
equalityTest for determining equivalence between elements.
equalityTest - iterable -
true if this stream has the same number of elements
that the given iterable, and each pair formed by
elements of this stream and given iterable at same
position satisfies the given Evaluable2
boolean equivBy(@NonNull
Evaluable2<? super A,? super A> equalityTest,
@NonNull
Iterator<? extends A> other)
Iterable, and in the same order, using the given
equalityTest for determining equivalence between elements.
equalityTest - iterable -
true if this stream has the same number of elements
that other, and each pair formed by
elements of this stream and other at same
position satisfies the given Evaluable2
boolean equivBy(@NonNull
Evaluable2<? super A,? super A> equalityTest,
A... elements)
elements, and in the same order, using the given
equalityTest for determining equivalence between elements.
equalityTest - iterable -
true if this stream has the same number of elements
that the given elements, and each pair formed by
elements of this stream and given elements at same
position satisfies the given Evaluable2
<B> boolean equivOn(@NonNull
Applicable<? super A,? extends B> function,
@NonNull
Iterable<? extends A> iterable)
Iterable, and in the same order, using the
Equiv.on(function) for determining equivalence between
elements.
function - iterable -
true if this stream has the same number of elements
that the given iterable, and each pair formed by
elements of this stream and given iterable at same
position satisfies the Evaluable2
Equiv.on(function)
<B> boolean equivOn(@NonNull
Applicable<? super A,? extends B> function,
@NonNull
Iterator<? extends A> other)
Iterator, and in the same order, using the
Equiv.on(function) for determining equivalence between
elements.
function - iterable -
true if this stream has the same number of elements
that the given Iterator, and each pair formed by
elements of this stream and given Iterator at same
position satisfies the Evaluable2
Equiv.on(function)
<B> boolean equivOn(@NonNull
Applicable<? super A,? extends B> function,
A... elements)
Equiv.on(function) for
determining equivalence between elements.
function - iterable -
true if this stream has the same number of elements
that the given elements, and each pair formed by
elements of this stream and the given elements at same
position satisfies the Evaluable2
Equiv.on(function)
<B> B fold(B initial,
@NonNull
Applicable2<? super B,? super A,? extends B> function)
Stream using an initial value and the given
two-arg function, producing a single aggregated result from all the Stream
elements.
This consist of taking the initial value and a Stream element,
applying the function to them, and then repeating the process with this
result as the next initial value and the next element from the stream. The
last returned value is the folding result.
B - initial - function -
A reduce(@NonNull
Applicable2<? super A,? super A,? extends A> function)
throws EmptySourceException
Stream using the first element of the
stream as initial value, producing a single aggregated result from all the
Stream elements.
function -
EmptySourceException - if this Stream is emptyfold(Object, Applicable2),
Folds
<B> B reduce(Reduction<? super A,B> reduction)
throws NoSuchElementException
reduction
reduction -
NoSuchElementException
@NonNull
String joinStrings(@NonNull
String separator)
Stream concatenating each elements toString with a
separator
separator -
@NonNull
A sum(@NonNull
NumberType<A> numberType)
Stream using the given
NumberType
numberType -
Iterables.sum(Iterable, NumberType)
@NonNull
A product(@NonNull
NumberType<A> numberType)
Stream using the given
NumberType
numberType -
Iterables.product(Iterable, NumberType)
A average(@NonNull
NumberType<A> numberType)
throws ArithmeticException
NumberType for performing addition and division.
numberType -
ArithmeticException - if the stream is empty and number type does not support zero
divisionint countOf(Evaluable<? super A> predicate)
predicate -
filter(predicate).size()@Projection Stream<A> sort()
Stream
@Projection
Stream<A> sortBy(@NonNull
Comparator<A> comparator)
comparator -
Stream@Projection <B extends Comparable<B>> Stream<A> sortOn(Applicable<? super A,B> function)
Compare.on(function) as comparator
B - function -
Stream
@NonNull
A minimumBy(@NonNull
Comparator<? super A> comparator)
throws EmptySourceException
comparator to compare elements.
comparator -
EmptySourceException - if the stream is empty.
<B extends Comparable<B>> A minimumOn(@NonNull
Applicable<? super A,B> function)
throws EmptySourceException
Compare.on(function) to compare elements.
function -
EmptySourceException - if the stream is empty.
@NonNull
A minimum()
throws ClassCastException,
EmptySourceException
EmptySourceException - if the stream is empty.
ClassCastException - if elements are not comparable
@NonNull
A maximumBy(@NonNull
Comparator<? super A> comparator)
throws EmptySourceException
comparator to compare elements.
comparator -
EmptySourceException - if the stream is empty.
<B extends Comparable<B>> A maximumOn(@NonNull
Applicable<? super A,B> function)
throws EmptySourceException
Compare.on(function) to compare elements.
function -
EmptySourceException - if the stream is empty.
@NonNull
A maximum()
throws ClassCastException,
EmptySourceException
EmptySourceException - if the stream is empty.
ClassCastException - if elements are not comparable
@Projection
Stream<A> append(@NonNull
Iterable<A> other)
concat(Iterable) instead
concat(Iterable)
@Projection
Stream<A> concat(@NonNull
Iterable<? extends A> other)
this with other
It answers an Stream that retrieves elements from this Stream, and
then, after its last element, from the given iterable.
As a particular case, if this Stream is infinite, the resulting Stream will
retrieve the same elements than this one.
other -
Stream
@Projection
Stream<A> concat(@NonNull
A... elements)
this with the given elements
It answers an Stream that retrieves elements from this Stream, and
then, after its last element, the given elements.
As a particular case, if this Stream is infinite, the resulting Stream will
retrieve the same elements than this one.
Example:
//answers the Stream [0, 1, 2, 3] Streams.cons(0, 1).concat(2, 3);
elements - the element to add at the end of the stream
Stream
Stream<A> concat(@NonNull
Iterator<? extends A> other)
this with the given Iterator
It answers an Stream that retrieves elements from this Stream, and
then, after its last element, the given iterator's elements.
As a particular case, if this Stream is infinite, the resulting Stream will
retrieve the same elements than this one.
other - the iterator whose elements will be added at the end of the stream
Stream@Projection Stream<A> appendUndefined()
concat(Streams.undefined())
Stream, Repeatable as long as this is
repeatableStreams.undefined()@Projection Stream<A> append(A element)
element -
Stream that retrieves this Stream elements,
and then, the given element
@Deprecated
@Projection
Stream<A> append(@NonNull
Thunk<A> thunk)
delayedAppend(Thunk) instead
delayedAppend(Thunk).
@Projection
Stream<A> delayedAppend(@NonNull
Thunk<A> thunk)
thunk -
Stream that retrieves this Stream elements,
and then, the value of the given thunk@Projection Stream<A> prepend(A element)
element -
Stream that retrieves the given element,
and then, this Stream elements.
@Deprecated
@Projection
Stream<A> prepend(@NonNull
Thunk<A> thunk)
delayedPrepend(Thunk)
delayedPrepend(Thunk)
@Projection
Stream<A> delayedPrepend(@NonNull
Thunk<A> thunk)
thunk -
Stream that retrieves the value of the given
thunk, and then, this Stream elements.
Stream<A> insertBeforeIndex(A element,
@NotNegative
int index)
element at index - 1. If stream has not enough
elements, that is, stream size is less than or equal to index
elements, the element is inserted at its end.
This message ensures that for any finite stream, and any element and index
stream.insertBeforeIndex(element, index).containsBeforeIndex(element, index + 1)is
true.
Examples:
Streams.cons(4, 5, 6).insertBeforeIndex(0, 2); //answers [4, 5, 0, 6] Streams.repeat(1).take(4).insertBeforeIndex(0, 2); //answers [1, 1, 0, 1, 1] Streams.repeat(1).take(4).insertBeforeIndex(0, 20); //answers [1, 1, 1, 1, 0]
element - the element to insertindex - the index before inserting it
Stream that lazily inserts the given element before the
given index
@Projection
Stream<A> insertBefore(A element,
A reference)
element before the first occurrence of reference.
If reference is not contained by this stream, the element is inserted at
its end.
This message ensures that for any finite stream, and any element and reference
stream.insertBefore(element, ref).containsBefore(element, ref)is
true.
Examples:
Streams.cons('a', 'b', 'c').insertBefore('x', 'a'); //answers [x,a,b,c]
Streams.cons('a', 'b', 'c').insertBefore('x', 'c'); //answers [a,b,x,c]
Streams.cons('a', 'b', 'c').insertBefore('x', 'd'); //answers [a,b,c,x]
element - reference -
Stream that lazily inserts the given element before the
reference@Projection <B> Stream<Tuple2<A,B>> clone(Applicable<? super A,? extends B> function)
This message is equivalent to map(Tuples.clone(function))
function - the function to apply to each element
StreamTuples.clone(Applicable)
@Projection
<B,C> Stream<Tuple2<B,C>> branch(Applicable<? super A,? extends B> function0,
Applicable<? super A,? extends C> function1)
this.map(Tuples.branch(function0, function1))
B - C - function0 - function1 -
StreamTuples.branch(Applicable, Applicable)
@Projection
<B,C> Stream<C> zipWith(Function2<? super A,? super B,C> function,
@NonNull
B... elements)
Stream formed by the result of applying the given
function to each pair of elements from this and
the given iterable.
If either this or the given iterable is shorter than the other
given number of elements, the remaining elements of this are discarded
Example:
//Answers the stream [1 + 4, 2 + 5] == [5, 7]; Streams.cons(1, 2).zipWith(integer().add(), 4, 5);
elements - the elements to zip with this Streamfunction - the function to apply to each pair
Applicable2 to each pair this Stream and the elements. The
resulting Stream size is the minimum of this size and the number of
elementsIterables.zip(Iterable, Iterable)
@Projection
<B,C> Stream<C> zipWith(Function2<? super A,? super B,C> function,
@NonNull
Iterable<B> other)
Stream formed by the result of applying the given
function to each pair of elements from this and
the given iterable.
If either this or the given iterable is shorter than
the other one, the remaining elements are discarded.
B - the type to the iterable to zip with this
StreamC - the resulting Stream element typeiterable - the Iterable to zip with this Streamfunction - the function to apply to each pair
Applicable2 to each
pair this Stream and the given iterable. The resulting Stream size
is the minimum of both iterables sizes, or infinite, if both this
and iterable areIterables.zip(Iterable, Iterable)
<B,C> Stream<C> zipWith(Function2<? super A,? super B,C> function,
@NonNull
Iterator<B> other)
Stream formed by the result of applying the given
function to each pair of elements from this and
the other.
If either this or the given Iterator is shorter than
the other one, the remaining elements are discarded.
B - the type to the iterable to zip with this
StreamC - the resulting Stream element typeother - the Iterator to zip with this Streamfunction - the function to apply to each pair
Applicable2 to each
pair this Stream and the given iterator. The resulting Stream size
is the minimum of both iterables sizes, or infinite, if both this
and other areIterables.zip(Iterable, Iterable)
@Deprecated
@Projection
<B,C> Stream<C> zip(@NonNull
Iterable<B> iterable,
Function2<? super A,? super B,C> function)
zipWith(Function2, Iterable)
zipWith(Function2, Iterable), with arguments
interchanged
@Projection
<B> Stream<Tuple2<A,B>> zip(@NonNull
B... elements)
Stream formed by by pair of element from
this and the given elements.
If either this or the given array is shorter than the other
one, the remaining elements are discarded.
Examples:
//Answers the stream [(0, a), (1,b), (2,c)]
Streams.cons(0, 1, 2).zip('a', 'b', 'c');
//Answers true
Streams
.from("hello")
.zip(Streams.from("world!"))
.equiv(
_('h', 'w'),
_('e', 'o'),
_('l', 'r'),
_('l', 'l'),
_('o', 'd')); //notice the last '!' was discarded
B - iterable -
Applicable2 to each
pair this Stream and the given elements. The resulting Stream size
is the minimum of both iterables sizes.zip(Iterable, Function2)
@Projection
<B> Stream<Tuple2<A,B>> zip(@NonNull
Iterable<B> iterable)
Stream formed by by pair of element from
this and the given iterable.
If either this or the given iterable is shorter than
the other one, the remaining elements are discarded.
B - iterable -
Applicable2 to each
pair this Stream and the given iterable. The resulting Stream size
is the minimum of both iterables sizes, or infinite, if both this
and iterable areIterables.zip(Iterable, Iterable),
zip(Iterable, Function2)
<B> Stream<Tuple2<A,B>> zip(@NonNull
Iterator<B> other)
Stream formed by by pair of element from
this and the given Iterator.
If either this or other is shorter than
the other one, the remaining elements are discarded.
B - other -
Applicable2 to each
pair this Stream and the given iterator. The resulting Stream size
is the minimum of both iterables sizes, or infinite, if both this
and other areIterables.zip(Iterable, Iterable),
zip(Iterable, Function2)
void print(Appendable destination)
throws IOException
StringBuilder or
a Writer
destination - the appendable were print stream elements
IOException - if any io error occursvoid print()
System.out
IOException - if any io error occurs
void println(Appendable o)
throws IOException
StringBuilder or
a Writer, followed by a newline character
destination - the appendable were print stream elements
IOException - if any io error occursvoid println()
System.out, followed by a newline
character. Equivalent to println(System.out)
IOException - if any io error occursString printString()
@NonNull Set<A> toSet()
Stream into a Set, by adding all its elements to a
new Set. The resulting Set is Serializable and non-lazy.
Set that contains all elements retrieved from this
Stream@NonNull List<A> toList()
Stream into a List, by adding all its elements to a
new List. The resulting List is Serializable and non-lazy.
List that contains all elements retrieved from this
Stream
@NonNull
A[] toArray(@NonNull
Class<? super A> clazz)
Stream
clazz - the array component class
@Deprecated @Repeatable @Projection Stream<A> memorize()
memoize() instead
memoize()
@Repeatable @Projection Stream<A> memoize()
Repeatable iteration order that caches elements evaluated during
iteration.
Stream that memoizes elements evaluated during
iteration@NonNull @Repeatable Stream<A> force()
Stream that retrieves elements from the next
iteration of this Stream.@Projection Stream<A> intersperse(A element)
element between each retrieved element of
this Stream
element -
Stream
@Projection
Stream<A> incorporate(@NonNull
Function<? super A,? extends A> function)
Streams.cons(10, 9, 90).incorporate(integer().negate()).equiv(10, -10, 9, -9, 90, -90);
function -
Stream
@Projection
Stream<A> incorporate(@NonNull
A element)
intersperse(Object), but inserts the
value also at the end of the stream.
element - Example:
Streams.cons('a', 'b', 'c').incorporate('d').equiv('a', 'd', 'b', 'd', 'c', 'd');
Stream
@NonNull
<K,V> Map<K,V> groupOn(Applicable<? super A,K> groupFunction,
Reduction<A,V> reduction)
groupingFunction, and reduces each
group using the given reduction.
The grouping is performed so that two elements a and b will
be put in the same group if and only if
groupFunction.apply(a).equals(groupFunction.apply(b))
K - groupFunction - reduction -
@Projection Stream<Tuple2<A,A>> cross()
other -
Stream projectionIterables.cross(Iterable, Iterable)
@Projection
<B> Stream<Tuple2<A,B>> cross(@NonNull
Stream<B> other)
B - other -
Stream projectionIterables.cross(Iterable, Iterable)
@Projection
<B> Stream<Tuple2<A,B>> cross(@NonNull
Iterable<B> other)
Stream and the given
Iterable
B - other -
cross(Streams.from(other))cross(Stream)
<B> Stream<Tuple2<A,B>> cross(@NonNull
B... elements)
Stream and the given
elements.
Example:
//Answers true
Streams
.cons("male", "female")
.cross("young", "middle-aged", "old")
.equiv(
_("male", "young"),
_("male", "middle-aged"),
_("male", "old"),
_("female", "young"),
_("female", "middle-aged"),
_("female", "old"));
B - other -
cross(Streams.cons(elements))cross(Stream)
@Projection
<B> Stream<Tuple2<A,B>> cross(@NonNull
Iterator<B> other)
Stream and the given
Iterator
B - other -
cross(Streams.from(other))cross(Stream)
@Projection
Stream<Stream<A>> crossStreams(@NonNull
Stream<Stream<A>> streamOfStreams)
Stream and each one of the
given streamOfStreams
streamOfStreams -
Stream projection
@Projection
<B> Stream<B> transform(@NonNull
Applicable<Stream<A>,? extends Stream<B>> function)
Stream.
B - function - the function to apply to this stream
@Projection
<B> Stream<B> transform(@NonNull
Stream.DeconsApplicable<A,B> function)
function to this stream,
deconstructing this stream into head and tail, or into an empty stream.
Unlike transform(Applicable), whose function will receive
the whole stream, the given Stream.DeconsApplicable, when applied, will
take the head and tail of this Stream, if non empty, or no
arguments, if the stream is empty.
B - function -
decons()
@Projection
<B> Stream<B> transform(@NonNull
Stream.DelayedDeconsApplicable<A,B> function)
function to this stream,
deconstructing this stream into a head thunk and tail, or into an empty
stream.
Unlike transform(Applicable), whose function will receive
the whole stream, the given Stream.DeconsApplicable, when applied, will
take a head's thunk and tail of this Stream, if non empty, or no
arguments, if the stream is empty.
B - function -
delayedDecons()
A first()
throws EmptySourceException
head().
It is also equivalent to get(0), but throws a
EmptySourceException if stream is empty
head()
EmptySourceException - if there is no first element
A second()
throws NoSuchElementException
get(1), but
throws a NoSuchElementException if stream size < 2
get(1)
NoSuchElementException - if there is no second element
A third()
throws NoSuchElementException
get(2), but throws
a NoSuchElementException if stream size < 3
get(2)
IndexOutOfBoundsException - if there is no third element
NoSuchElementException
A last()
throws EmptySourceException
EmptySourceException
boolean isBefore(A previous,
A next)
previous - next -
Stream, and the
first is before the second one.containsBefore(Object, Object)
boolean containsBefore(A element,
A reference)
element is contained by this stream, and its first
occurence is before the first occurence of the second one, if any.
This message is similar to isBefore(Object, Object), but may be
true even if the reference is not present at the stream. It will be
always true if both element and reference are equal, too.
Examples:
Streams.from("abcd").containsBefore('c', 'a'); //false. c is after a
Streams.from("abcd").containsBefore('x', 'd'); //false. x is not present
Streams.from("abcd").containsBefore('a', 'b'); //true
Streams.from("abcd").containsBefore('b', 'd'); //true
Streams.from("abcd").containsBefore('a', 'a'); //true
Streams.from("abcd").containsBefore('x', 'x'); //false. x is not present
element - the element to test whether it is contained by this stream, and
appears before referencereference -
Stream, and the
first is before the second one.insertBefore(Object, Object),
isBefore(Object, Object)
boolean containsBeforeIndex(A element,
@NotNegative
int index)
element is contained by this stream, and its first
occurence is before the given index.
As a particular case, if index is 0, return always
false
Examples:
Streams.from("abcd").containsBeforeIndex('x', 2); //false. x is not present
Streams.from("abcd").containsBeforeIndex('c', 1); //false. c is present but at index 2
Streams.from("abcd").containsBeforeIndex('a', 0); //false. a is present but at index 0
Streams.from("abcd").containsBeforeIndex('a', 1); //true
Streams.from("abcd").containsBeforeIndex('b', 3); //true
Streams.from("abcd").containsBeforeIndex('b', 40); //true
element - index -
insertBeforeIndex(Object, int)A get(int n)
n -
IndexOutOfBoundsException - if there is no n-th element, because stream has less than n elementsint indexOf(A element)
element -
element, or
-1, if it is not contained by this streamint findIndex(Evaluable<? super A> predicate)
predicate -
predicate
to true, or -1, if no element satisfies it@Projection Stream<Integer> indices(Evaluable<? super A> predicate)
predicate -
Stream with the indices of the elements that satisfy the
given predicate
int positionOf(A element)
throws NoSuchElementException
indexOf(Object), with the only
difference that it will throw a NoSuchElementException if the given
element is not present on the stream
element -
NoSuchElementException - if the element is no contained by this Stream
int findPosition(Evaluable<? super A> predicate)
throws NoSuchElementException
findIndex(Evaluable), with the only difference that it will throw
a NoSuchElementException if the given element is not present on the
stream
predicate -
predicate
NoSuchElementException - if no elements satisfies the given predicate
@Projection
Stream<A> filterIndex(@NonNull
Evaluable<Integer> predicate)
predicate
predicate -
Stream projection that will retrieve only elements
whose index evaluate to true@Projection Stream<A> skipIndex(int index)
predicate -
Stream that skips the element at the given index
@NonNull
Tuple2<A,Stream<A>> decons()
throws EmptySourceException
head() and tail(), as it
will work as expected even on non repeatable iteration streams.
NonNull and a Projection, but it is always
non-repeatable.
EmptySourceException - if stream is empty
@NonNull
Tuple2<Thunk<A>,Stream<A>> delayedDecons()
throws EmptySourceException
decons() when the head value of the
Stream is potentially irrelevant, as this methods grants to suceeds
even in those cases where head() fails.
NonNull and a
Projection, but it is always non-repeatable.
EmptySourceException - if stream is empty
A head()
throws EmptySourceException
Stream, which is the first element of the
stream. However, if you need both head and tail in order to perfom
functional-style transformations over the stream, consider using
decons().
first()
EmptySourceException - if stream is empty
@Projection
Stream<A> tail()
throws EmptySourceException
Stream
Stream that retrieves all its elements, except of the
first one
EmptySourceException - if stream is empty
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||