org.javimmutable.collections.cursors
Class LazyCursor<V>

java.lang.Object
  extended by org.javimmutable.collections.cursors.AbstractStartCursor<V>
      extended by org.javimmutable.collections.cursors.LazyCursor<V>
Type Parameters:
V -
All Implemented Interfaces:
Iterable<V>, Cursor<V>

@Immutable
public class LazyCursor<V>
extends AbstractStartCursor<V>

Cursor that creates and returns a real Cursor for a specific iterable only when start() or next() is called for the first time.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javimmutable.collections.Cursor
Cursor.NotStartedException, Cursor.NoValueException
 
Constructor Summary
LazyCursor(Cursorable<V> cursorable)
          Creates a new LazyCursor for the specified cursorable.
LazyCursor(Func0<Cursor<V>> factory)
          Creates a new LazyCursor for the specified factory.
 
Method Summary
 Cursor<V> next()
          Creates the real cursor using the factory and returns its next() method's result.
static
<V> LazyCursor<V>
of(Cursorable<V> cursorable)
          Creates a new LazyPersistentIterator for the specified cursorable.
static
<V> LazyCursor<V>
of(Func0<Cursor<V>> factory)
          Creates a new LazyPersistentIterator using the specified factory.
 
Methods inherited from class org.javimmutable.collections.cursors.AbstractStartCursor
getValue, hasValue, iterator, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LazyCursor

public LazyCursor(Func0<Cursor<V>> factory)
Creates a new LazyCursor for the specified factory.

Parameters:
factory - a function to return an actual Cursor to use for iteration

LazyCursor

public LazyCursor(Cursorable<V> cursorable)
Creates a new LazyCursor for the specified cursorable.

Parameters:
cursorable - to return an actual Cursor to use for iteration
Method Detail

of

public static <V> LazyCursor<V> of(Func0<Cursor<V>> factory)
Creates a new LazyPersistentIterator using the specified factory.

Parameters:
factory - a Func0 capable of creating a real Cursor

of

public static <V> LazyCursor<V> of(Cursorable<V> cursorable)
Creates a new LazyPersistentIterator for the specified cursorable.

Parameters:
cursorable - a PersistentIterable capable of producing a non-empty PersistentIterator

next

@Nonnull
public Cursor<V> next()
Creates the real cursor using the factory and returns its next() method's result. Thus when the lazy cursor creates the real cursor it always immediately calls its start() method to start its iteration and get it into the state expected by the caller of this method.

Specified by:
next in interface Cursor<V>
Overrides:
next in class AbstractStartCursor<V>
Returns:
real cursor's next() value


Copyright © 2014 Burton Computer Corporation. All rights reserved.