From 8809341248c62b15b78d7e6d8e06ab2ec3793c8e Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 28 Mar 2007 22:00:24 +0000 Subject: Merged 1.2-dev to trunk. --- .../amazon/carbonado/cursor/FilteredCursor.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/main/java/com/amazon/carbonado/cursor') diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java index c25f8db..faf990d 100644 --- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java @@ -37,6 +37,27 @@ import com.amazon.carbonado.filter.OpenFilter; * @author Brian S O'Neill */ public abstract class FilteredCursor extends AbstractCursor { + /** + * Returns a Cursor that is filtered by the given filter expression and values. + * + * @param cursor cursor to wrap + * @param type type of storable + * @param filter filter to apply + * @param filterValues values for filter + * @return wrapped cursor which filters results + * @throws IllegalStateException if any values are not specified + * @throws IllegalArgumentException if any argument is null + */ + public static Cursor applyFilter(Cursor cursor, + Class type, + String filter, + Object... filterValues) + { + Filter f = Filter.filterFor(type, filter).bind(); + FilterValues fv = f.initialFilterValues().withValues(filterValues); + return applyFilter(f, fv, cursor); + } + /** * Returns a Cursor that is filtered by the given Filter and FilterValues. * The given Filter must be composed only of the same PropertyFilter @@ -61,6 +82,9 @@ public abstract class FilteredCursor extends AbstractCursor { throw new IllegalArgumentException(); } + // Make sure the filter is the same one that filterValues should be using. + filter = filter.bind(); + return FilteredCursorGenerator.getFactory(filter) .newFilteredCursor(cursor, filterValues.getValuesFor(filter)); } -- cgit v1.2.3