net.sf.staccatocommons.collections.stream
Class AbstractBasicStream<A>

java.lang.Object
  extended by net.sf.staccatocommons.lang.AbstractProtoMonad<Stream<A>,Stream,A>
      extended by net.sf.staccatocommons.collections.stream.AbstractBasicStream<A>
Type Parameters:
A -
All Implemented Interfaces:
Iterable<A>, Stream<A>, ContainsAware<A>, EmptyAware, SizeAware, ProtoMonad<Stream<A>,Stream,A>
Direct Known Subclasses:
AbstractStream

public abstract class AbstractBasicStream<A>
extends AbstractProtoMonad<Stream<A>,Stream,A>
implements Stream<A>

Very minimal stream partial implementation that defines final methods that are, by spec, overloading or synonyms of the other stream methods

Since:
2.2
Author:
flbulgarelli

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
AbstractBasicStream()
           
 
Method Summary
 A any()
          Returns the Stream.head() of this Stream The different between Stream.head() and Stream.any() is strictly semantic: use this message instead of Stream.head() whenever the code needs an unspecified element, rather than the first element of the stream.
 Stream<A> append(Iterable<A> other)
          Equivalent to Stream.concat(Iterable)
 Stream<A> append(Thunk<A> element)
          Equivalent to Stream.delayedAppend(Thunk).
 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(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, 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.
<B> boolean
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.
<B> boolean
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.
<B> boolean
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.
 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.
<B> Stream<B>
map(Applicable<? super A,? extends B> function)
          Transforms each element using the given function
<B extends Comparable<B>>
A
maximumOn(Applicable<? super A,B> function)
          Answers the maximum element of the stream, using the given Compare.on(function) to compare elements.
 Stream<A> memorize()
          Equivalent to Stream.memoize()
<B extends Comparable<B>>
A
minimumOn(Applicable<? super A,B> function)
          Answers the minimum element of the stream, using the given Compare.on(function) to compare elements.
 int positionOf(A element)
          Answers the index of the given present element.
 Stream<A> prepend(Thunk<A> element)
          Equivalent to Stream.delayedPrepend(Thunk)
 void println()
          Prints the stream elements to System.out, followed by a newline character.
 A second()
          Answers the second element.
<B extends Comparable<B>>
Stream<A>
sortOn(Applicable<? super A,B> function)
          Sorts this Stream, using Compare.on(function) as comparator
 A third()
          Answers the third element.
<B> Stream<Tuple2<A,B>>
zip(B... elements)
          Returns a Stream formed by by pair of element from this and the given elements.
<B> Stream<Tuple2<A,B>>
zip(Iterable<B> iterable)
          Returns a Stream formed by by pair of element from this and the given iterable.
<B,C> Stream<C>
zip(Iterable<B> iterable, Function2<? super A,? super B,C> function)
          Equivalent to Stream.zipWith(Function2, Iterable), with arguments interchanged
<B> Stream<Tuple2<A,B>>
zip(Iterator<B> other)
          Returns a Stream formed by by pair of element from this and the given Iterator.
 
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, toString, wait, wait, wait
 
Methods inherited from interface net.sf.staccatocommons.collections.stream.Stream
all, allEquiv, allEquivBy, any, anyOrElse, anyOrElse, anyOrNone, anyOrNull, append, appendUndefined, average, branch, clone, concat, concat, concat, containsBefore, containsBeforeIndex, countOf, cross, cross, cross, cross, cross, crossStreams, decons, delayedAppend, delayedDecons, delayedPrepend, drop, dropWhile, each, equiv, equivBy, filter, filterIndex, find, findIndex, findOrElse, findOrElse, findOrNone, findOrNull, flatMap, flatMapArray, fold, force, forEach, get, groupOn, head, incorporate, incorporate, indexOf, indices, insertBefore, insertBeforeIndex, intersperse, isBefore, iterator, joinStrings, last, map, maximum, maximumBy, memoize, minimum, minimumBy, partition, prepend, print, print, println, printString, product, reduce, reduce, reverse, skip, skipIndex, slice, sort, sortBy, streamPartition, sum, tail, take, takeWhile, toArray, toList, toSet, transform, transform, transform, zipWith, zipWith, zipWith
 
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
 

Constructor Detail

AbstractBasicStream

public AbstractBasicStream()
Method Detail

any

public final A any()
Description copied from interface: Stream
Returns the Stream.head() of this Stream The different between Stream.head() and Stream.any() is strictly semantic: use this message instead of Stream.head() whenever the code needs an unspecified element, rather than the first element of the stream.

Specified by:
any in interface Stream<A>
Returns:
Stream.head()

first

public final A first()
Description copied from interface: Stream
Answers the first element. This is equivalent to Stream.head(). It is also equivalent to get(0), but throws a EmptySourceException if stream is empty

Specified by:
first in interface Stream<A>
Returns:
Stream.head()

second

public final A second()
Description copied from interface: Stream
Answers the second element. This is equivalent to get(1), but throws a NoSuchElementException if stream size < 2

Specified by:
second in interface Stream<A>
Returns:
get(1)

third

public final A third()
Description copied from interface: Stream
Answers the third element. This is equivalent to get(2), but throws a NoSuchElementException if stream size < 3

Specified by:
third in interface Stream<A>
Returns:
get(2)

map

public final <B> Stream<B> map(Applicable<? super A,? extends B> function)
Description copied from interface: Stream
Transforms each element using the given function

Specified by:
map in interface Stream<A>
Specified by:
map in interface ProtoMonad<Stream<A>,Stream,A>
Parameters:
function - the mapper used to transform each element, applying it
Returns:
a new Stream projection that will retrieve the result of applying the given function to each element

equiv

public final boolean equiv(A... elements)
Description copied from interface: Stream
Test that the elements of this stream are equal to the elements of the given array, and in the same order.

Specified by:
equiv in interface Stream<A>
Returns:
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 otherwise

equivBy

public final boolean equivBy(Evaluable2<? super A,? super A> equalityTest,
                             A... elements)
Description copied from interface: Stream
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.

Specified by:
equivBy in interface Stream<A>
Returns:
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

equivOn

public final <B> boolean equivOn(Applicable<? super A,? extends B> function,
                                 A... elements)
Description copied from interface: Stream
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.

Specified by:
equivOn in interface Stream<A>
Returns:
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)

equiv

public final boolean equiv(Iterator<? extends A> other)
Description copied from interface: Stream
Test that the elements of this stream are equal to the elements of the given iterator, and in the same order.

Specified by:
equiv in interface Stream<A>
Returns:
true if this stream has the same number of elements that other, and each pair formed by elements of this stream and given iterable at same position are equal. false otherwise

equivBy

public final boolean equivBy(Evaluable2<? super A,? super A> equalityTest,
                             Iterator<? extends A> other)
Description copied from interface: Stream
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.

Specified by:
equivBy in interface Stream<A>
Returns:
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

equivOn

public final <B> boolean equivOn(Applicable<? super A,? extends B> function,
                                 Iterator<? extends A> other)
Description copied from interface: Stream
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.

Specified by:
equivOn in interface Stream<A>
Returns:
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)

zip

public final <B> Stream<Tuple2<A,B>> zip(B... elements)
Description copied from interface: Stream
Returns a 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
 

Specified by:
zip in interface Stream<A>
Returns:
a new Stream formed applying the given Applicable2 to each pair this Stream and the given elements. The resulting Stream size is the minimum of both iterables sizes.
See Also:
Stream.zip(Iterable, Function2)

zip

public final <B> Stream<Tuple2<A,B>> zip(Iterator<B> other)
Description copied from interface: Stream
Returns a 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.

Specified by:
zip in interface Stream<A>
Returns:
a new Stream formed applying the given 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 are
See Also:
Iterables.zip(Iterable, Iterable), Stream.zip(Iterable, Function2)

zip

public final <B> Stream<Tuple2<A,B>> zip(Iterable<B> iterable)
Description copied from interface: Stream
Returns a 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.

Specified by:
zip in interface Stream<A>
Returns:
a new Stream formed applying the given 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 are
See Also:
Iterables.zip(Iterable, Iterable), Stream.zip(Iterable, Function2)

findPosition

public final int findPosition(Evaluable<? super A> predicate)
Description copied from interface: Stream
Answers the zero-based index of first, present element that matches the given predicate. This method behaves exactly like Stream.findIndex(Evaluable), with the only difference that it will throw a NoSuchElementException if the given element is not present on the stream

Specified by:
findPosition in interface Stream<A>
Returns:
the index of the first element that evaluates the predicate

positionOf

public final int positionOf(A element)
Description copied from interface: Stream
Answers the index of the given present element. This method behaves exactly like Stream.indexOf(Object), with the only difference that it will throw a NoSuchElementException if the given element is not present on the stream

Specified by:
positionOf in interface Stream<A>
Returns:
the index of the given element

maximumOn

public final <B extends Comparable<B>> A maximumOn(Applicable<? super A,B> function)
                  throws NoSuchElementException
Description copied from interface: Stream
Answers the maximum element of the stream, using the given Compare.on(function) to compare elements.

Specified by:
maximumOn in interface Stream<A>
Returns:
the maximum element.
Throws:
EmptySourceException - if the stream is empty.
NoSuchElementException

minimumOn

public final <B extends Comparable<B>> A minimumOn(Applicable<? super A,B> function)
                  throws NoSuchElementException
Description copied from interface: Stream
Answers the minimum element of the stream, using the given Compare.on(function) to compare elements.

Specified by:
minimumOn in interface Stream<A>
Returns:
the minimum element.
Throws:
EmptySourceException - if the stream is empty.
NoSuchElementException

equivOn

public final <B> boolean equivOn(Applicable<? super A,? extends B> function,
                                 Iterable<? extends A> iterable)
Description copied from interface: Stream
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.

Specified by:
equivOn in interface Stream<A>
Returns:
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)

sortOn

public final <B extends Comparable<B>> Stream<A> sortOn(Applicable<? super A,B> function)
Description copied from interface: Stream
Sorts this Stream, using Compare.on(function) as comparator

Specified by:
sortOn in interface Stream<A>
Returns:
a new Stream

println

public final void println()
Description copied from interface: Stream
Prints the stream elements to System.out, followed by a newline character. Equivalent to println(System.out)

Specified by:
println in interface Stream<A>

memorize

public final Stream<A> memorize()
Description copied from interface: Stream
Equivalent to Stream.memoize()

Specified by:
memorize in interface Stream<A>

append

public Stream<A> append(Iterable<A> other)
Description copied from interface: Stream
Equivalent to Stream.concat(Iterable)

Specified by:
append in interface Stream<A>

append

public final Stream<A> append(Thunk<A> element)
Description copied from interface: Stream
Equivalent to Stream.delayedAppend(Thunk).

Specified by:
append in interface Stream<A>

prepend

public final Stream<A> prepend(Thunk<A> element)
Description copied from interface: Stream
Equivalent to Stream.delayedPrepend(Thunk)

Specified by:
prepend in interface Stream<A>

zip

public final <B,C> Stream<C> zip(@NonNull
                                 Iterable<B> iterable,
                                 @NonNull
                                 Function2<? super A,? super B,C> function)
Description copied from interface: Stream
Equivalent to Stream.zipWith(Function2, Iterable), with arguments interchanged

Specified by:
zip in interface Stream<A>


Get Staccatocommons at SourceForge.net. Fast, secure and Free Open Source software downloads