org.javimmutable.collections.cursors
Class MultiTransformCursor<S,T>

java.lang.Object
  extended by org.javimmutable.collections.cursors.MultiTransformCursor<S,T>
Type Parameters:
T -
All Implemented Interfaces:
Iterable<T>, Cursor<T>

@Immutable
public class MultiTransformCursor<S,T>
extends Object
implements Cursor<T>

Cursor that produces values by visiting all values in a Cursor of objects and using a Func1 on each object to produce a Cursor that is then visited to reach all of its elements. No values are precomputed so LazyCursors can be used to minimize memory consumption.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javimmutable.collections.Cursor
Cursor.NotStartedException, Cursor.NoValueException
 
Method Summary
 T getValue()
          Return the value at the Cursor's position.
 boolean hasValue()
          Read-only method with no side effects that determines if the Cursor currently has a value.
 Iterator<T> iterator()
           
 Cursor<T> next()
          Advances to the next (possibly first) value.
static
<S,T> Cursor<T>
of(Cursor<S> source, Func1<S,Cursor<T>> transforminator)
           
 Cursor<T> start()
          All Cursors are created in a pre-start position pointing "before" the first element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

of

public static <S,T> Cursor<T> of(Cursor<S> source,
                                 Func1<S,Cursor<T>> transforminator)

start

@Nonnull
public Cursor<T> start()
Description copied from interface: Cursor
All Cursors are created in a pre-start position pointing "before" the first element. Once traversal has begun a Cursor points to some element in the collection or to end ("after" the last element). The start() method advances to the first element if traversal has not yet started or does nothing if traversal has already started. Either next() or start() can be used to initiate a traversal however start() is safer since it can be used safely on already started cursors as well as not-started ones. This distinction is useful when passing a Cursor as parameter to a method that will traverse from the Cursor's current position forward and using start() prevents it from skipping the current value.

Must always return a non-null Cursor.

Specified by:
start in interface Cursor<T>
Returns:
Cursor for first position or this if already started

next

@Nonnull
public Cursor<T> next()
Description copied from interface: Cursor
Advances to the next (possibly first) value. Must always return a non-null Cursor. A newly created Cursor must always point to "before" the first value because next() (or start()) must always be called once before retrieving the first value. If the Cursor is already at the end of its sequence then it should return a Cursor that will always return false for hasValue().

Specified by:
next in interface Cursor<T>
Returns:
Cursor for next position

hasValue

public boolean hasValue()
Description copied from interface: Cursor
Read-only method with no side effects that determines if the Cursor currently has a value. Users of the Cursor will always call this after calling next() to see if they have reached the end of the sequence. If hasValue() returns true then next() will be called. If hasValue() returns false then next() must not be called.

Specified by:
hasValue in interface Cursor<T>
Returns:
true iff getValue() can be called

getValue

public T getValue()
Description copied from interface: Cursor
Return the value at the Cursor's position. Only valid if a call to hasValue() would return true.

Specified by:
getValue in interface Cursor<T>
Returns:
current value

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>


Copyright © 2014 Burton Computer Corporation. All rights reserved.