com.amazon.carbonado.cursor
Class SingletonCursor<S>

java.lang.Object
  extended by com.amazon.carbonado.cursor.SingletonCursor<S>
All Implemented Interfaces:
Cursor<S>

public class SingletonCursor<S>
extends Object
implements Cursor<S>

Special cursor implementation that returns only one element.

Author:
Brian S O'Neill
See Also:
EmptyCursor

Constructor Summary
SingletonCursor(S object)
           
 
Method Summary
 void close()
          Call close to release any resources being held by this cursor.
 int copyInto(Collection<? super S> c)
          Copies all remaining next elements into the given collection.
 int copyInto(Collection<? super S> c, int limit)
          Copies a limited amount of remaining next elements into the given collection.
 boolean hasNext()
          Returns true if this cursor has more elements.
 S next()
          Returns the next element from this cursor.
 int skipNext(int amount)
          Skips forward by the specified amount of elements, returning the actual amount skipped.
 List<S> toList()
          Copies all remaining next elements into a new modifiable list.
 List<S> toList(int limit)
          Copies a limited amount of remaining next elements into a new modifiable list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingletonCursor

public SingletonCursor(S object)
Parameters:
object - single object to return from cursor, must not be null
Throws:
IllegalArgumentException - if object is null
Method Detail

close

public void close()
Description copied from interface: Cursor
Call close to release any resources being held by this cursor. Further operations on this cursor will behave as if there are no results.

Specified by:
close in interface Cursor<S>

hasNext

public boolean hasNext()
Description copied from interface: Cursor
Returns true if this cursor has more elements. In other words, returns true if next would return an element rather than throwing an exception.

Specified by:
hasNext in interface Cursor<S>

next

public S next()
Description copied from interface: Cursor
Returns the next element from this cursor. This method may be called repeatedly to iterate through the results.

Specified by:
next in interface Cursor<S>

skipNext

public int skipNext(int amount)
Description copied from interface: Cursor
Skips forward by the specified amount of elements, returning the actual amount skipped. The actual amount is less than the requested amount only if the end of the results was reached.

Specified by:
skipNext in interface Cursor<S>
Parameters:
amount - maximum amount of elements to skip
Returns:
actual amount skipped

copyInto

public int copyInto(Collection<? super S> c)
Description copied from interface: Cursor
Copies all remaining next elements into the given collection. This method is roughly equivalent to the following:
 Cursor cursor;
 ...
 while (cursor.hasNext()) {
     c.add(cursor.next());
 }
 

As a side-effect of calling this method, the cursor is closed.

Specified by:
copyInto in interface Cursor<S>
Returns:
actual amount of results added

copyInto

public int copyInto(Collection<? super S> c,
                    int limit)
Description copied from interface: Cursor
Copies a limited amount of remaining next elements into the given collection. This method is roughly equivalent to the following:
 Cursor cursor;
 ...
 while (--limit >= 0 && cursor.hasNext()) {
     c.add(cursor.next());
 }
 

Specified by:
copyInto in interface Cursor<S>
limit - maximum amount of elements to copy
Returns:
actual amount of results added

toList

public List<S> toList()
Description copied from interface: Cursor
Copies all remaining next elements into a new modifiable list. This method is roughly equivalent to the following:
 Cursor<S> cursor;
 ...
 List<S> list = new ...
 cursor.copyInto(list);
 

As a side-effect of calling this method, the cursor is closed.

Specified by:
toList in interface Cursor<S>
Returns:
a new modifiable list

toList

public List<S> toList(int limit)
Description copied from interface: Cursor
Copies a limited amount of remaining next elements into a new modifiable list. This method is roughly equivalent to the following:
 Cursor<S> cursor;
 ...
 List<S> list = new ...
 cursor.copyInto(list, limit);
 

Specified by:
toList in interface Cursor<S>
Parameters:
limit - maximum amount of elements to copy
Returns:
a new modifiable list


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.