|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.staccatocommons.lang.AbstractProtoMonad<Stream<A>,Stream,A>
net.sf.staccatocommons.collections.stream.AbstractBasicStream<A>
net.sf.staccatocommons.collections.stream.AbstractStream<A>
A - public abstract class AbstractStream<A>
An abstract implementation of a Stream. Only it Iterator
method is abstract.
Implementors must grant that the following methods remain consistent:
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface net.sf.staccatocommons.collections.stream.Stream |
|---|
Stream.DeconsApplicable<A,B>, Stream.DelayedDeconsApplicable<A,B>, Stream.EmptyApplicable<A> |
| Constructor Summary | |
|---|---|
AbstractStream()
|
|
| 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 |
|
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 Stream.head() of the given Stream, just like Stream.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> |
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 |
contains(A element)
|
|
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>> other)
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 |
|
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 |
equivBy(Evaluable2<? super A,? super A> equalty,
Iterable<? 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. |
|
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. |
|
|
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(O initial,
Applicable2<? super O,? super A,? extends O> 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 position)
Inserts element at index - 1. |
|
Stream<A> |
intersperse(A sep)
intersperse _ [] = [] intersperse _ [x] = [x] intersperse sep (x:xs) = x : sep : intersperse sep xs |
|
boolean |
isBefore(A previous,
A next)
Answers if both arguments are contained by this stream, and the first one is before the second one. |
|
boolean |
isEmpty()
|
|
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(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. |
|
Stream<A> |
memoize()
Memoizes stream elements and their order, by answering a lazy stream with Repeatable iteration order that caches elements evaluated during
iteration. |
|
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. |
|
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 |
|
Stream<A> |
prepend(A element)
Adds an element as the first one of the stream. |
|
void |
print()
Prints the stream elements to System.out |
|
void |
print(Appendable o)
Prints the stream elements to an appendable, like StringBuilder or
a Writer |
|
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. |
|
int |
size()
|
|
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 lowerBound,
int upperBound)
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 |
|
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[] |
toArray(Class<? super A> clazz)
Creates a new array that has the same elements that the retrived by this Stream |
|
protected A[] |
toArray(Class<? super A> clazz,
Collection<A> readOnlyColView)
|
|
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. |
|
String |
toString()
|
|
|
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. |
|
|
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 class net.sf.staccatocommons.collections.stream.AbstractBasicStream |
|---|
any, append, append, equiv, equiv, equivBy, equivBy, equivOn, equivOn, equivOn, findPosition, first, map, maximumOn, memorize, minimumOn, positionOf, prepend, println, second, sortOn, third, zip, zip, zip, zip |
| Methods inherited from class net.sf.staccatocommons.lang.AbstractProtoMonad |
|---|
each, replace, replaceNull, skip, skipNull |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface net.sf.staccatocommons.collections.stream.Stream |
|---|
each, iterator, skip |
| Methods inherited from interface net.sf.staccatocommons.defs.ProtoMonad |
|---|
replace, replaceNull, skipNull |
| Constructor Detail |
|---|
public AbstractStream()
| Method Detail |
|---|
public int size()
public int countOf(Evaluable<? super A> predicate)
Stream
filter(predicate).size()public boolean isEmpty()
public void forEach(Executable<? super A> block)
StreamExecutable block for each element.
This message is equivalent to a for-each loop over this Stream
public boolean contains(A element)
public Stream<A> filter(Evaluable<? super A> predicate)
Streampredicate
Example:
//Answers stream [hello, world], which has only strings whose length is 5
Streams.cons("a", "hello", "world", "of", "streams", "!").filter(length().equal(5));
Stream projection that will retrieve only elements
that evaluate to truepublic Stream<A> takeWhile(Evaluable<? super A> predicate)
Streampredicate
Stream projection that will retrieve all elements
from this stream, as long as none of them evaluates to false.
public Stream<A> take(@NotNegative
int amountOfElements)
StreamamountOfElements, the resulting stream will retrieve the same
elements than this stream.
Stream projection that will retrieve up to N elementspublic Stream<A> dropWhile(Evaluable<? super A> predicate)
Streampredicate
Stream projection that will skip all elements as long
as they satisfy the given Evaluable
public Stream<A> drop(@NotNegative
int amountOfElements)
StreamStream. 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
public Stream<A> slice(@NotNegative
int lowerBound,
@NotNegative
int upperBound)
StreambeginIndex, 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 []
lowerBound - the lower bound, inclusiveupperBound - the upper bound, exclusive
drop(beginIndex).take(endIndex - beginIndex)public A reduce(Applicable2<? super A,? super A,? extends A> function)
StreamStream using the first element of the
stream as initial value, producing a single aggregated result from all the
Stream elements.
Stream.fold(Object, Applicable2),
Folds
public <B> B reduce(Reduction<? super A,B> reduction)
throws NoSuchElementException
Streamreduction
NoSuchElementException
public <O> O fold(O initial,
Applicable2<? super O,? super A,? extends O> function)
StreamStream 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.
public Option<A> anyOrNone()
StreamStream.head() of the given Stream, just like Stream.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.public A anyOrNull()
StreamanyOrNone().valueOrNull()
anyOrNone().valueOrNull()public A anyOrElse(Thunk<A> thunk)
StreamanyOrNone().valueOrElse(thunk)
anyOrNone().valueOrElse(thunk)public A anyOrElse(A value)
StreamanyOrNone().valueOrElse(value)
anyOrNone().valueOrElse(value)public A find(Evaluable<? super A> predicate)
StreamEvaluable. If such
element does not exist, throws NoSuchElementException
public Option<A> findOrNone(Evaluable<? super A> predicate)
StreamEvaluable. If such
element exists, returns some(element). Otherwise, returns
None.
None if Stream is empty, regardless of the given
predicatepublic A findOrNull(Evaluable<? super A> predicate)
StreamEvaluable. If such
element exists, returns it. Otherwise, returns null.
Stream is empty, regardless of
the given predicate
public A findOrElse(Evaluable<? super A> predicate,
Thunk<? extends A> thunk)
StreamEvaluable. If such
element exists, returns it. Otherwise, returns the given thunk's value.
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
public A findOrElse(Evaluable<? super A> predicate,
A element)
StreamEvaluable. If such
element exists, returns it. Otherwise, returns the given
element .
findOrElse(predicate, Thunks.constant(element))public boolean all(Evaluable<? super A> predicate)
StreamEvaluable
predicate - an Evaluable to evaluate each element
public boolean allEquiv()
Stream
public boolean allEquivBy(Evaluable2<? super A,? super A> equivTest)
StreamequivTest
equivTest - an Evaluable2 used to testing if an element is equivalent
to another
public boolean any(Evaluable<? super A> predicate)
StreamEvaluable
predicate - an Evaluable to evaluate each element
public <B> Stream<Tuple2<A,B>> clone(Applicable<? super A,? extends B> function)
Stream
This message is equivalent to map(Tuples.clone(function))
function - the function to apply to each element
StreamTuples.clone(Applicable)
public <B,C> Stream<Tuple2<B,C>> branch(Applicable<? super A,? extends B> function0,
Applicable<? super A,? extends C> function1)
Streamthis.map(Tuples.branch(function0, function1))
StreamTuples.branch(Applicable, Applicable)public <B> Stream<B> map(Function<? super A,? extends B> function)
Stream
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();
function - the mapper used to transform each element, applying it
Stream projection that will retrieve the result of
applying the given function to each elementpublic <B> Stream<B> flatMap(Function<? super A,? extends Iterable<? extends B>> function)
Stream
Stream that will retrieve the result of transforming
each element and concatenating those transformations
public <B> Stream<B> flatMapArray(@NonNull
Function<? super A,? extends B[]> function)
Stream
Stream that will retrieve the result of transforming
each element and concatenating those trsansformationspublic Stream<A> appendUndefined()
Streamconcat(Streams.undefined())
Stream, Repeatable as long as this is
repeatableStreams.undefined()public A head()
StreamStream, 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
Stream.decons().
Stream.first()public A last()
Stream
public A get(int n)
Stream
public Stream<A> filterIndex(Evaluable<Integer> predicate)
Streampredicate
Stream projection that will retrieve only elements
whose index evaluate to truepublic Stream<A> skipIndex(int index)
Stream
Stream that skips the element at the given indexpublic int indexOf(A element)
Stream
element, or
-1, if it is not contained by this streampublic int findIndex(Evaluable<? super A> predicate)
Stream
predicate
to true, or -1, if no element satisfies itpublic Stream<Integer> indices(Evaluable<? super A> predicate)
Stream
Stream with the indices of the elements that satisfy the
given predicate
public boolean isBefore(A previous,
A next)
Stream
Stream, and the
first is before the second one.Stream.containsBefore(Object, Object)public Set<A> toSet()
StreamStream 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
Streampublic List<A> toList()
StreamStream 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
Streampublic Stream<A> force()
Stream
Stream that retrieves elements from the next
iteration of this Stream.public A[] toArray(Class<? super A> clazz)
StreamStream
clazz - the array component class
protected A[] toArray(Class<? super A> clazz,
Collection<A> readOnlyColView)
public String joinStrings(@NonNull
String separator)
StreamStream concatenating each elements toString with a
separator
public Tuple2<List<A>,List<A>> partition(Evaluable<? super A> predicate)
Stream
Tuple2 that contains this stream partitioned into two
lists.public final Tuple2<Stream<A>,Stream<A>> streamPartition(Evaluable<? super A> predicate)
StreamStream.partition(Evaluable) into Streams.
Tuple2 that contains this stream partitioned into two
other streams.public boolean equiv(Iterable<? extends A> other)
StreamIterable, and in the same order.
other, and each pair formed by elements of this
stream and given iterable at same position are equal.
false otherwise
public boolean equivBy(Evaluable2<? super A,? super A> equalty,
Iterable<? extends A> other)
StreamIterable, and in the same order, using the given
equalityTest for determining equivalence between elements.
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 Evaluable2public <B> Stream<B> transform(Applicable<Stream<A>,? extends Stream<B>> function)
StreamStream.
function - the function to apply to this stream
public Stream<A> intersperse(A sep)
intersperse _ [] = [] intersperse _ [x] = [x] intersperse sep (x:xs) = x : sep : intersperse sep xs
Streampublic Stream<A> incorporate(Function<? super A,? extends A> function)
StreamStreams.cons(10, 9, 90).incorporate(integer().negate()).equiv(10, -10, 9, -9, 90, -90);
Streampublic Stream<A> incorporate(A element)
StreamStream.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');
Streampublic Stream<A> append(A element)
Stream
Stream that retrieves this Stream elements,
and then, the given elementpublic Stream<A> prepend(A element)
Stream
Stream that retrieves the given element,
and then, this Stream elements.public <B> Stream<B> transform(Stream.DeconsApplicable<A,B> function)
Streamfunction to this stream,
deconstructing this stream into head and tail, or into an empty stream.
Unlike Stream.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.
Stream.decons()public <B> Stream<B> transform(Stream.DelayedDeconsApplicable<A,B> function)
Streamfunction to this stream,
deconstructing this stream into a head thunk and tail, or into an empty
stream.
Unlike Stream.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.
Stream.delayedDecons()public Tuple2<A,Stream<A>> decons()
StreamStream.head() and Stream.tail(), as it
will work as expected even on non repeatable iteration streams.
NonNull and a Projection, but it is always
non-repeatable.public Tuple2<Thunk<A>,Stream<A>> delayedDecons()
StreamStream.decons() when the head value of the
Stream is potentially irrelevant, as this methods grants to suceeds
even in those cases where Stream.head() fails.
NonNull and a
Projection, but it is always non-repeatable.public Stream<A> tail()
StreamStream
Stream that retrieves all its elements, except of the
first onepublic A sum(NumberType<A> numberType)
StreamStream using the given
NumberType
Iterables.sum(Iterable, NumberType)public A product(NumberType<A> numberType)
StreamStream using the given
NumberType
Iterables.product(Iterable, NumberType)public A average(NumberType<A> numberType)
StreamNumberType for performing addition and division.
public A maximum()
Stream
public A minimum()
Stream
public A maximumBy(Comparator<? super A> comparator)
Streamcomparator to compare elements.
public A minimumBy(Comparator<? super A> comparator)
Streamcomparator to compare elements.
public Stream<A> sort()
Stream
Streampublic Stream<A> sortBy(Comparator<A> comparator)
Stream
Streampublic Stream<A> reverse()
StreamProjection, depending on if the stream's source
permits it.
Stream that retrieves elements in the inverse order
of this stream.
public <K,V> Map<K,V> groupOn(Applicable<? super A,K> groupFunction,
Reduction<A,V> reduction)
StreamgroupingFunction, 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))
public Stream<Tuple2<A,A>> cross()
Stream
Stream projectionIterables.cross(Iterable, Iterable)public final <B> Stream<Tuple2<A,B>> cross(B... elements)
StreamStream 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"));
cross(Streams.cons(elements))Stream.cross(Stream)public final <B> Stream<Tuple2<A,B>> cross(Iterator<B> other)
StreamStream and the given
Iterator
cross(Streams.from(other))Stream.cross(Stream)
public <B> Stream<Tuple2<A,B>> cross(@NonNull
Iterable<B> other)
StreamStream and the given
Iterable
cross(Streams.from(other))Stream.cross(Stream)
public <B> Stream<Tuple2<A,B>> cross(@NonNull
Stream<B> other)
Stream
Stream projectionIterables.cross(Iterable, Iterable)
public Stream<Stream<A>> crossStreams(@NonNull
Stream<Stream<A>> other)
StreamStream and each one of the
given streamOfStreams
Stream projection
public final void print(Appendable o)
throws IOException
StreamStringBuilder or
a Writer
o - the appendable were print stream elements
IOException - if any io error occurspublic final void print()
StreamSystem.out
public final void println(Appendable o)
throws IOException
StreamStringBuilder or
a Writer, followed by a newline character
IOException - if any io error occurspublic final String printString()
Stream
public final String toString()
toString in class Objectpublic final Stream<A> concat(Iterable<? extends A> other)
Streamthis 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.
Streampublic final Stream<A> concat(A... elements)
Streamthis 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
Streampublic Stream<A> concat(Iterator<? extends A> other)
Streamthis 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
Streampublic Stream<A> delayedAppend(Thunk<A> thunk)
Stream
Stream that retrieves this Stream elements,
and then, the value of the given thunkpublic Stream<A> delayedPrepend(Thunk<A> thunk)
Stream
Stream that retrieves the value of the given
thunk, and then, this Stream elements.
public final <B,C> Stream<C> zipWith(Function2<? super A,? super B,C> function,
B... elements)
StreamStream 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);
function - the function to apply to each pairelements - the elements to zip with this Stream
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)
public final <B,C> Stream<C> zipWith(Function2<? super A,? super B,C> function,
Iterable<B> other)
StreamStream 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 typefunction - 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)
public <B,C> Stream<C> zipWith(Function2<? super A,? super B,C> function,
Iterator<B> other)
StreamStream 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 typefunction - the function to apply to each pairother - the Iterator to zip with this Stream
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)public Stream<A> memoize()
StreamRepeatable iteration order that caches elements evaluated during
iteration.
Stream that memoizes elements evaluated during
iteration
public Stream<A> insertBeforeIndex(A element,
@NotNegative
int position)
Streamelement 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 insertposition - the index before inserting it
Stream that lazily inserts the given element before the
given index
public Stream<A> insertBefore(A element,
A reference)
Streamelement 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]
Stream that lazily inserts the given element before the
reference
public boolean containsBeforeIndex(A element,
@NotNegative
int index)
Streamelement 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
Stream.insertBeforeIndex(Object, int)
public boolean containsBefore(A element,
A reference)
Streamelement 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 Stream.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 reference
Stream, and the
first is before the second one.Stream.insertBefore(Object, Object),
Stream.isBefore(Object, Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||