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

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

public abstract class FilteredCursor<S>
extends AbstractCursor<S>

Wraps another cursor and applies custom filtering to reduce the set of results.

Author:
Brian S O'Neill

Constructor Summary
protected FilteredCursor(Cursor<S> cursor)
           
 
Method Summary
static
<S extends Storable>
Cursor<S>
applyFilter(Cursor<S> cursor, Class<S> type, String filter, Object... filterValues)
          Returns a Cursor that is filtered by the given filter expression and values.
static
<S extends Storable>
Cursor<S>
applyFilter(Filter<S> filter, FilterValues<S> filterValues, Cursor<S> cursor)
          Returns a Cursor that is filtered by the given Filter and FilterValues.
 void close()
          Call close to release any resources being held by this cursor.
 boolean hasNext()
          Returns true if this cursor has more elements.
protected abstract  boolean isAllowed(S storable)
           
 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.
 
Methods inherited from class com.amazon.carbonado.cursor.AbstractCursor
copyInto, copyInto, toList, toList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteredCursor

protected FilteredCursor(Cursor<S> cursor)
Method Detail

applyFilter

public static <S extends Storable> Cursor<S> applyFilter(Cursor<S> cursor,
                                                         Class<S> type,
                                                         String filter,
                                                         Object... filterValues)
Returns a Cursor that is filtered by the given filter expression and values.

Parameters:
cursor - cursor to wrap
type - type of storable
filter - filter to apply
filterValues - values for filter
Returns:
wrapped cursor which filters results
Throws:
IllegalStateException - if any values are not specified
IllegalArgumentException - if any argument is null
Since:
1.2

applyFilter

public static <S extends Storable> Cursor<S> applyFilter(Filter<S> filter,
                                                         FilterValues<S> filterValues,
                                                         Cursor<S> cursor)
Returns a Cursor that is filtered by the given Filter and FilterValues. The given Filter must be composed only of the same PropertyFilter instances as used to construct the FilterValues. An IllegalStateException will result otherwise.

Parameters:
filter - filter to apply
filterValues - values for filter, which may be null if filter has no parameters
cursor - cursor to wrap
Returns:
wrapped cursor which filters results
Throws:
IllegalStateException - if any values are not specified
IllegalArgumentException - if filter is closed

isAllowed

protected abstract boolean isAllowed(S storable)
                              throws FetchException
Returns:
false if object should not be in results
Throws:
FetchException

close

public void close()
           throws FetchException
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.

Throws:
FetchException

hasNext

public boolean hasNext()
                throws FetchException
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.

Throws:
FetchException - if storage layer throws an exception

next

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

Throws:
FetchException - if storage layer throws an exception

skipNext

public int skipNext(int amount)
             throws FetchException
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>
Overrides:
skipNext in class AbstractCursor<S>
Parameters:
amount - maximum amount of elements to skip
Returns:
actual amount skipped
Throws:
FetchException - if storage layer throws an exception


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