public class Filters extends Object
The methods in this class are for the most part simple factory methods for
various Filter
classes, but in some cases provide additional type
safety. They also tend to make the code more readable, especially if imported
statically, so their use is strongly encouraged in lieu of direct construction
of Filter
classes.
Constructor and Description |
---|
Filters() |
Modifier and Type | Method and Description |
---|---|
static <T> Filter<T> |
all(Filter<? super T>... filters)
Return a composite filter representing logical AND of all specified
filters.
|
static <T> Filter<T> |
always()
Return a filter that always evaluates to true.
|
static <T> Filter<T> |
any(Filter<? super T>... filters)
Return a composite filter representing logical OR of all specified
filters.
|
static <T,E> Filter<T> |
arrayContains(ValueExtractor<T,E[]> extractor,
E value)
Return a filter that tests if the extracted array contains the
specified value.
|
static <T,E> Filter<T> |
arrayContainsAll(ValueExtractor<T,E[]> extractor,
E... values)
Return a filter that tests if the extracted array contains all of
the specified values.
|
static <T,E> Filter<T> |
arrayContainsAll(ValueExtractor<T,E[]> extractor,
Set<? extends E> setValues)
Return a filter that tests if the extracted array contains all of
the specified values.
|
static <T,E> Filter<T> |
arrayContainsAny(ValueExtractor<T,E[]> extractor,
E... values)
Return a filter that tests if the extracted array contains any of
the specified values.
|
static <T,E> Filter<T> |
arrayContainsAny(ValueExtractor<T,E[]> extractor,
Set<? extends E> setValues)
Return a filter that tests if the extracted array contains any of
the specified values.
|
static <T,E extends Comparable<? super E>> |
between(ValueExtractor<T,? extends E> extractor,
E from,
E to)
Return a filter that tests if the extracted value is between
the specified values (inclusive).
|
static <T,E,C extends Collection<? extends E>> |
contains(ValueExtractor<T,C> extractor,
E value)
Return a filter that tests if the extracted collection contains the
specified value.
|
static <T,E,C extends Collection<? extends E>> |
containsAll(ValueExtractor<T,C> extractor,
E... values)
Return a filter that tests if the extracted collection contains all of
the specified values.
|
static <T,E,C extends Collection<? extends E>> |
containsAll(ValueExtractor<T,C> extractor,
Set<? extends E> setValues)
Return a filter that tests if the extracted collection contains all of
the specified values.
|
static <T,E,C extends Collection<? extends E>> |
containsAny(ValueExtractor<T,C> extractor,
E... values)
Return a filter that tests if the extracted collection contains any of
the specified values.
|
static <T,E,C extends Collection<? extends E>> |
containsAny(ValueExtractor<T,C> extractor,
Set<? extends E> setValues)
Return a filter that tests if the extracted collection contains any of
the specified values.
|
static <T,E> Filter<T> |
equal(String fieldName,
E value)
Return a filter that tests for equality using a
UniversalExtractor
instance to extract the specified field. |
static <T,E> Filter<T> |
equal(ValueExtractor<T,? extends E> extractor,
E value)
Return a filter that tests for equality.
|
static <T,E extends Comparable<? super E>> |
greater(ValueExtractor<T,? extends E> extractor,
E value)
Return a filter that tests if the extracted value is greater than the
specified value.
|
static <T,E extends Comparable<? super E>> |
greaterEqual(ValueExtractor<T,? extends E> extractor,
E value)
Return a filter that tests if the extracted value is greater than or equal
to the specified value.
|
static <T,E> Filter<T> |
in(ValueExtractor<T,? extends E> extractor,
E... values)
Return a filter that tests if the extracted value is contained in the
specified array.
|
static <T,E> Filter<T> |
in(ValueExtractor<T,? extends E> extractor,
Set<? extends E> setValues)
Return a filter that tests if the extracted value is contained in the
specified set.
|
static <T,E> Filter<T> |
isNotNull(ValueExtractor<T,E> extractor)
Return a filter that evaluates to true for non-null values.
|
static <T,E> Filter<T> |
isNull(ValueExtractor<T,E> extractor)
Return a filter that evaluates to true for null values.
|
static <T,E extends Comparable<? super E>> |
less(ValueExtractor<T,? extends E> extractor,
E value)
Return a filter that tests if the extracted value is less than the
specified value.
|
static <T,E extends Comparable<? super E>> |
lessEqual(ValueExtractor<T,? extends E> extractor,
E value)
Return a filter that tests if the extracted value is less than or equal
to the specified value.
|
static <T,E> Filter<T> |
like(ValueExtractor<T,E> extractor,
String sPattern)
Return a LikeFilter for pattern match.
|
static <T,E> Filter<T> |
like(ValueExtractor<T,E> extractor,
String sPattern,
boolean fIgnoreCase)
Return a LikeFilter for pattern match.
|
static <T,E> Filter<T> |
like(ValueExtractor<T,E> extractor,
String sPattern,
char chEscape)
Return a LikeFilter for pattern match.
|
static <T,E> Filter<T> |
like(ValueExtractor<T,E> extractor,
String sPattern,
char chEscape,
boolean fIgnoreCase)
Return a LikeFilter for pattern match.
|
static <T> Filter<T> |
never()
Return a filter that always evaluates to false.
|
static <T> Filter<T> |
not(Filter<T> filter)
Return a filter that represents the logical negation of the specified
filter.
|
static <T,E> Filter<T> |
notEqual(ValueExtractor<T,? extends E> extractor,
E value)
Return a filter that tests for non-equality.
|
static <T> Filter<T> |
predicate(Remote.Predicate<T> predicate)
Return a PredicateFilter for a given
Predicate . |
static <T,E> Filter<T> |
predicate(ValueExtractor<T,? extends E> extractor,
Remote.Predicate<? super E> predicate)
Return a PredicateFilter for a given
Predicate . |
static <T> Filter<T> |
present()
Return a filter that evaluates to true if an entry is present in the cache.
|
static <T,E> Filter<T> |
regex(ValueExtractor<T,E> extractor,
String sRegex)
Return a RegexFilter for pattern match.
|
static <V> Filter<V> |
script(String sLanguage,
String sScriptPath,
Object... aoArgs)
Instantiate a Filter that is implemented in a script using the specified
language.
|
public static <T> Filter<T> all(Filter<? super T>... filters)
filters
- an array of filtersAllFilter
public static <T> Filter<T> any(Filter<? super T>... filters)
filters
- an array of filtersAnyFilter
public static <T> Filter<T> always()
AlwaysFilter
public static <T> Filter<T> never()
NeverFilter
public static <T> Filter<T> present()
PresentFilter
public static <T> Filter<T> not(Filter<T> filter)
T
- the type of the input argument to the filterfilter
- the filterNotFilter
public static <T,E> Filter<T> isNull(ValueExtractor<T,E> extractor)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the Extractor to useIsNullFilter
public static <T,E> Filter<T> isNotNull(ValueExtractor<T,E> extractor)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the Extractor to useIsNotNullFilter
public static <T,E> Filter<T> equal(String fieldName, E value)
UniversalExtractor
instance to extract the specified field.T
- the type of the object to extract value fromE
- the type of extracted valuefieldName
- the name of the field to usevalue
- the value to compare the extracted value withEqualsFilter
,
UniversalExtractor
public static <T,E> Filter<T> equal(ValueExtractor<T,? extends E> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the Extractor to usevalue
- the value to compare the extracted value withEqualsFilter
public static <T,E> Filter<T> notEqual(ValueExtractor<T,? extends E> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withNotEqualsFilter
public static <T,E extends Comparable<? super E>> Filter<T> less(ValueExtractor<T,? extends E> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withLessFilter
public static <T,E extends Comparable<? super E>> Filter<T> lessEqual(ValueExtractor<T,? extends E> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withLessEqualsFilter
public static <T,E extends Comparable<? super E>> Filter<T> greater(ValueExtractor<T,? extends E> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withGreaterFilter
public static <T,E extends Comparable<? super E>> Filter<T> greaterEqual(ValueExtractor<T,? extends E> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withGreaterEqualsFilter
public static <T,E extends Comparable<? super E>> Filter<T> between(ValueExtractor<T,? extends E> extractor, E from, E to)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usefrom
- the lower bound to compare the extracted value withto
- the upper bound to compare the extracted value withBetweenFilter
public static <T,E,C extends Collection<? extends E>> Filter<T> contains(ValueExtractor<T,C> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueC
- the type of value that will be extracted by the extractorextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withContainsFilter
public static <T,E> Filter<T> arrayContains(ValueExtractor<T,E[]> extractor, E value)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalue
- the value to compare the extracted value withContainsFilter
public static <T,E,C extends Collection<? extends E>> Filter<T> containsAll(ValueExtractor<T,C> extractor, Set<? extends E> setValues)
T
- the type of the object to extract value fromE
- the type of extracted valueC
- the type of value that will be extracted by the extractorextractor
- the ValueExtractor to usesetValues
- the values to compare the extracted value withContainsAllFilter
@SafeVarargs public static <T,E,C extends Collection<? extends E>> Filter<T> containsAll(ValueExtractor<T,C> extractor, E... values)
T
- the type of the object to extract value fromE
- the type of extracted valueC
- the type of value that will be extracted by the extractorextractor
- the ValueExtractor to usevalues
- the values to compare the extracted value withContainsAllFilter
public static <T,E> Filter<T> arrayContainsAll(ValueExtractor<T,E[]> extractor, Set<? extends E> setValues)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usesetValues
- the values to compare the extracted value withContainsAllFilter
@SafeVarargs public static <T,E> Filter<T> arrayContainsAll(ValueExtractor<T,E[]> extractor, E... values)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalues
- the values to compare the extracted value withContainsAllFilter
public static <T,E,C extends Collection<? extends E>> Filter<T> containsAny(ValueExtractor<T,C> extractor, Set<? extends E> setValues)
T
- the type of the object to extract value fromE
- the type of extracted valueC
- the type of value that will be extracted by the extractorextractor
- the ValueExtractor to usesetValues
- the values to compare the extracted value withContainsAnyFilter
@SafeVarargs public static <T,E,C extends Collection<? extends E>> Filter<T> containsAny(ValueExtractor<T,C> extractor, E... values)
T
- the type of the object to extract value fromE
- the type of extracted valueC
- the type of value that will be extracted by the extractorextractor
- the ValueExtractor to usevalues
- the values to compare the extracted value withContainsAnyFilter
public static <T,E> Filter<T> arrayContainsAny(ValueExtractor<T,E[]> extractor, Set<? extends E> setValues)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usesetValues
- the values to compare the extracted value withContainsAnyFilter
@SafeVarargs public static <T,E> Filter<T> arrayContainsAny(ValueExtractor<T,E[]> extractor, E... values)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalues
- the values to compare the extracted value withContainsAnyFilter
public static <T,E> Filter<T> in(ValueExtractor<T,? extends E> extractor, Set<? extends E> setValues)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usesetValues
- the values to compare the extracted value withContainsAnyFilter
@SafeVarargs public static <T,E> Filter<T> in(ValueExtractor<T,? extends E> extractor, E... values)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to usevalues
- the values to compare the extracted value withContainsAnyFilter
public static <T,E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the Extractor to use by this filtersPattern
- the string pattern to compare the result withpublic static <T,E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern, char chEscape)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to use by this filtersPattern
- the string pattern to compare the result withchEscape
- the escape character for escaping '%' and '_'public static <T,E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern, boolean fIgnoreCase)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to use by this filtersPattern
- the string pattern to compare the result withfIgnoreCase
- true to be case-insensitivepublic static <T,E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern, char chEscape, boolean fIgnoreCase)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to use by this filtersPattern
- the string pattern to compare the result withchEscape
- the escape character for escaping '%' and '_'fIgnoreCase
- true to be case-insensitivepublic static <T,E> Filter<T> regex(ValueExtractor<T,E> extractor, String sRegex)
T
- the type of the object to extract value fromE
- the type of extracted valueextractor
- the ValueExtractor to use by this filtersRegex
- the regular expression to match the result withpublic static <T> Filter<T> predicate(Remote.Predicate<T> predicate)
Predicate
.T
- the type of the object to evaluatepredicate
- the predicate to evaluatepublic static <T,E> Filter<T> predicate(ValueExtractor<T,? extends E> extractor, Remote.Predicate<? super E> predicate)
Predicate
.T
- the type of the object to extract value fromE
- the type of extracted value to evaluateextractor
- the ValueExtractor to use by this filterpredicate
- the predicate to evaluatepublic static <V> Filter<V> script(String sLanguage, String sScriptPath, Object... aoArgs)
V
- the type of value that the Filter
will receivesLanguage
- the string specifying one of the supported languagessScriptPath
- the path where the script reside, relative to rootaoArgs
- the arguments to be passed to the scriptFilter
ScriptException
- if the script
cannot be loaded
or any error occurs during its executionIllegalArgumentException
- if the specified language is not supported