Class Filters

java.lang.Object
com.tangosol.util.Filters

public class Filters extends Object
Simple Filter DSL.

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.

Author:
as 2014.06.15
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    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>
    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>>
    Filter<T>
    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>>
    Filter<T>
    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>>
    Filter<T>
    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>>
    Filter<T>
    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>>
    Filter<T>
    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>>
    Filter<T>
    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(ValueExtractor<T,? extends E> extractor, E value)
    Return a filter that tests for equality.
    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 extends Comparable<? super E>>
    Filter<T>
    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>>
    Filter<T>
    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> Filter<T>
    Return a filter that evaluates to true if the extracted value is false.
    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> Filter<T>
    Return a filter that evaluates to true if the extracted value is true.
    static <T, E extends Comparable<? super E>>
    Filter<T>
    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>>
    Filter<T>
    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>
    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>
    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>
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Filters

      public Filters()
  • Method Details

    • all

      public static <T> Filter<T> all(Filter<? super T>... filters)
      Return a composite filter representing logical AND of all specified filters.
      Parameters:
      filters - an array of filters
      Returns:
      a composite filter representing logical AND of all specified filters
      See Also:
    • any

      public static <T> Filter<T> any(Filter<? super T>... filters)
      Return a composite filter representing logical OR of all specified filters.
      Parameters:
      filters - an array of filters
      Returns:
      a composite filter representing logical OR of all specified filters
      See Also:
    • always

      public static <T> Filter<T> always()
      Return a filter that always evaluates to true.
      Returns:
      a filter that always evaluates to true
      See Also:
    • never

      public static <T> Filter<T> never()
      Return a filter that always evaluates to false.
      Returns:
      a filter that always evaluates to false
      See Also:
    • present

      public static <T> Filter<T> present()
      Return a filter that evaluates to true if an entry is present in the cache.
      Returns:
      a filter that evaluates to true if an entry is present
      See Also:
    • not

      public static <T> Filter<T> not(Filter<T> filter)
      Return a filter that represents the logical negation of the specified filter.
      Type Parameters:
      T - the type of the input argument to the filter
      Parameters:
      filter - the filter
      Returns:
      a filter that represents the logical negation of the specified filter
      See Also:
    • isNull

      public static <T, E> Filter<T> isNull(ValueExtractor<T,E> extractor)
      Return a filter that evaluates to true for null values.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the Extractor to use
      Returns:
      a filter that evaluates to true for null values
      See Also:
    • isNotNull

      public static <T, E> Filter<T> isNotNull(ValueExtractor<T,E> extractor)
      Return a filter that evaluates to true for non-null values.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the Extractor to use
      Returns:
      a filter that evaluates to true for non-null values
      See Also:
    • isTrue

      public static <T> Filter<T> isTrue(ValueExtractor<T,Boolean> extractor)
      Return a filter that evaluates to true if the extracted value is true.
      Type Parameters:
      T - the type of the object to extract value from
      Parameters:
      extractor - the Extractor to use
      Returns:
      a filter that evaluates to true for non-null values
    • isFalse

      public static <T> Filter<T> isFalse(ValueExtractor<T,Boolean> extractor)
      Return a filter that evaluates to true if the extracted value is false.
      Type Parameters:
      T - the type of the object to extract value from
      Parameters:
      extractor - the Extractor to use
      Returns:
      a filter that evaluates to true for non-null values
    • equal

      public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      fieldName - the name of the field to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests for equality
      See Also:
    • equal

      public static <T, E> Filter<T> equal(ValueExtractor<T,? extends E> extractor, E value)
      Return a filter that tests for equality.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the Extractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests for equality
      See Also:
    • notEqual

      public static <T, E> Filter<T> notEqual(ValueExtractor<T,? extends E> extractor, E value)
      Return a filter that tests for non-equality.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests for non-equality
      See Also:
    • less

      public static <T, E extends Comparable<? super E>> Filter<T> less(ValueExtractor<T,? extends E> extractor, E value)
      Return a filter that tests if the extracted value is less than the specified value.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is less than the specified value
      See Also:
    • lessEqual

      public static <T, E extends Comparable<? super E>> Filter<T> 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is less than or equal to the specified value
      See Also:
    • greater

      public static <T, E extends Comparable<? super E>> Filter<T> greater(ValueExtractor<T,? extends E> extractor, E value)
      Return a filter that tests if the extracted value is greater than the specified value.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is greater than the specified value
      See Also:
    • greaterEqual

      public static <T, E extends Comparable<? super E>> Filter<T> 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is greater than or equal to the specified value
      See Also:
    • between

      public static <T, E extends Comparable<? super E>> Filter<T> 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).
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      from - the lower bound to compare the extracted value with
      to - the upper bound to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is between the specified values
      See Also:
    • contains

      public static <T, E, C extends Collection<? extends E>> Filter<T> contains(ValueExtractor<T,C> extractor, E value)
      Return a filter that tests if the extracted collection contains the specified value.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      C - the type of value that will be extracted by the extractor
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests if the extracted collection contains the specified value
      See Also:
    • arrayContains

      public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      value - the value to compare the extracted value with
      Returns:
      a filter that tests if the extracted array contains the specified value
      See Also:
    • containsAll

      public static <T, E, C extends Collection<? extends E>> Filter<T> containsAll(ValueExtractor<T,C> extractor, Set<? extends E> setValues)
      Return a filter that tests if the extracted collection contains all of the specified values.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      C - the type of value that will be extracted by the extractor
      Parameters:
      extractor - the ValueExtractor to use
      setValues - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted collection contains all of the specified values
      See Also:
    • containsAll

      @SafeVarargs public static <T, E, C extends Collection<? extends E>> Filter<T> containsAll(ValueExtractor<T,C> extractor, E... values)
      Return a filter that tests if the extracted collection contains all of the specified values.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      C - the type of value that will be extracted by the extractor
      Parameters:
      extractor - the ValueExtractor to use
      values - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted collection contains all of the specified values
      See Also:
    • arrayContainsAll

      public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      setValues - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted array contains all of the specified values
      See Also:
    • arrayContainsAll

      @SafeVarargs public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      values - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted array contains all of the specified value
      See Also:
    • containsAny

      public static <T, E, C extends Collection<? extends E>> Filter<T> containsAny(ValueExtractor<T,C> extractor, Set<? extends E> setValues)
      Return a filter that tests if the extracted collection contains any of the specified values.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      C - the type of value that will be extracted by the extractor
      Parameters:
      extractor - the ValueExtractor to use
      setValues - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted collection contains any of the specified values
      See Also:
    • containsAny

      @SafeVarargs public static <T, E, C extends Collection<? extends E>> Filter<T> containsAny(ValueExtractor<T,C> extractor, E... values)
      Return a filter that tests if the extracted collection contains any of the specified values.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      C - the type of value that will be extracted by the extractor
      Parameters:
      extractor - the ValueExtractor to use
      values - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted collection contains any of the specified values
      See Also:
    • arrayContainsAny

      public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      setValues - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted array contains any of the specified values
      See Also:
    • arrayContainsAny

      @SafeVarargs public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      values - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted array contains any of the specified values
      See Also:
    • in

      public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      setValues - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is contained in the specified set
      See Also:
    • in

      @SafeVarargs public 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.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use
      values - the values to compare the extracted value with
      Returns:
      a filter that tests if the extracted value is contained in the specified array
      See Also:
    • like

      public static <T, E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern)
      Return a LikeFilter for pattern match.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the Extractor to use by this filter
      sPattern - the string pattern to compare the result with
      Returns:
      a LikeFilter
    • like

      public static <T, E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern, char chEscape)
      Return a LikeFilter for pattern match.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use by this filter
      sPattern - the string pattern to compare the result with
      chEscape - the escape character for escaping '%' and '_'
      Returns:
      a LikeFilter
    • like

      public static <T, E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern, boolean fIgnoreCase)
      Return a LikeFilter for pattern match.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use by this filter
      sPattern - the string pattern to compare the result with
      fIgnoreCase - true to be case-insensitive
      Returns:
      a LikeFilter
    • like

      public static <T, E> Filter<T> like(ValueExtractor<T,E> extractor, String sPattern, char chEscape, boolean fIgnoreCase)
      Return a LikeFilter for pattern match.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use by this filter
      sPattern - the string pattern to compare the result with
      chEscape - the escape character for escaping '%' and '_'
      fIgnoreCase - true to be case-insensitive
      Returns:
      a LikeFilter
    • regex

      public static <T, E> Filter<T> regex(ValueExtractor<T,E> extractor, String sRegex)
      Return a RegexFilter for pattern match.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value
      Parameters:
      extractor - the ValueExtractor to use by this filter
      sRegex - the regular expression to match the result with
      Returns:
      a RegexFilter
    • predicate

      public static <T> Filter<T> predicate(Remote.Predicate<T> predicate)
      Return a PredicateFilter for a given Predicate.
      Type Parameters:
      T - the type of the object to evaluate
      Parameters:
      predicate - the predicate to evaluate
      Returns:
      a RegexFilter
    • predicate

      public static <T, E> Filter<T> predicate(ValueExtractor<T,? extends E> extractor, Remote.Predicate<? super E> predicate)
      Return a PredicateFilter for a given Predicate.
      Type Parameters:
      T - the type of the object to extract value from
      E - the type of extracted value to evaluate
      Parameters:
      extractor - the ValueExtractor to use by this filter
      predicate - the predicate to evaluate
      Returns:
      a RegexFilter
    • script

      public static <V> Filter<V> script(String sLanguage, String sScriptPath, Object... aoArgs)
      Instantiate a Filter that is implemented in a script using the specified language.
      Type Parameters:
      V - the type of value that the Filter will receive
      Parameters:
      sLanguage - the string specifying one of the supported languages
      sScriptPath - the path where the script reside, relative to root
      aoArgs - the arguments to be passed to the script
      Returns:
      An instance of Filter
      Throws:
      ScriptException - if the script cannot be loaded or any error occurs during its execution
      IllegalArgumentException - if the specified language is not supported
      Since:
      14.1.1.0