org.javimmutable.collections.cursors
Class StandardCursor

java.lang.Object
  extended by org.javimmutable.collections.cursors.StandardCursor

@Immutable
public abstract class StandardCursor
extends Object

Utility class that implements standard Cursor behavior for classes that do not naturally start at a position before the first element. Such classes can pass a Source implementation to the of() method and this class will ensure that traversal does not start until the next() method is called and does not progress beyond the point where atEnd() is true.


Nested Class Summary
static interface StandardCursor.Source<T>
          Simple interface for classes that can iterate immediately (i.e.
 
Constructor Summary
StandardCursor()
           
 
Method Summary
static Cursor<Integer> forRange(int low, int high)
          Creates a Cursor over a range of integers.
static
<T> Iterator<T>
iterator(StandardCursor.Source<T> source)
          Creates a java.util.Iterator that iterates over values in the specified Source.
static
<T> List<T>
makeList(Cursor<T> cursor)
          Utility method, useful in unit tests, that collects all of the values in the Cursor into a List and returns the List.
static
<T> Cursor<T>
of()
          Creates an empty cursor that has no values.
static
<T> Cursor<T>
of(Indexed<T> source)
          Creates a Cursor for the given Indexed.
static
<T> Cursor<T>
of(StandardCursor.Source<T> source)
          Creates a Cursor for the given Source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardCursor

public StandardCursor()
Method Detail

of

public static <T> Cursor<T> of()
Creates an empty cursor that has no values.

Type Parameters:
T -
Returns:

of

public static <T> Cursor<T> of(StandardCursor.Source<T> source)
Creates a Cursor for the given Source. The Source must point to the first value (i.e. cannot be be used for empty collections) to be iterated over.

Type Parameters:
T -
Parameters:
source -
Returns:

of

public static <T> Cursor<T> of(Indexed<T> source)
Creates a Cursor for the given Indexed.

Type Parameters:
T -
Parameters:
source -
Returns:

iterator

public static <T> Iterator<T> iterator(StandardCursor.Source<T> source)
Creates a java.util.Iterator that iterates over values in the specified Source. The Source must point to the first value (i.e. cannot be be used for empty collections) to be iterated over.

Type Parameters:
T -
Parameters:
source -
Returns:

forRange

public static Cursor<Integer> forRange(int low,
                                       int high)
Creates a Cursor over a range of integers. Useful for test purposes.

Parameters:
low -
high -
Returns:

makeList

public static <T> List<T> makeList(Cursor<T> cursor)
Utility method, useful in unit tests, that collects all of the values in the Cursor into a List and returns the List.

Type Parameters:
T -
Parameters:
cursor -
Returns:


Copyright © 2014 Burton Computer Corporation. All rights reserved.