Class QueryFilter<F>

java.lang.Object
org.forgerock.util.query.QueryFilter<F>
Type Parameters:
F - The type of the field specification.

public class QueryFilter<F> extends Object
A filter which can be used to select resources, which is compatible with the CREST query filters.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.forgerock.util.query.QueryFilter.Impl<F>
    the filter implementation.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    QueryFilter(org.forgerock.util.query.QueryFilter.Impl<F> pimpl)
    Construct a QueryFilter from a base filter implementation.
    protected
    QueryFilter(org.forgerock.util.query.QueryFilter.Impl<F> pimpl, QueryFilterVisitor<StringBuilder,StringBuilder,F> toStringVisitor)
    Construct a QueryFilter from a base filter implementation and a custom toString implementation.
  • Method Summary

    Modifier and Type
    Method
    Description
    <R, P> R
    accept(QueryFilterVisitor<R,P,F> v, P p)
    Applies a QueryFilterVisitor to this QueryFilter.
    static <FF> QueryFilter<FF>
    Returns a filter which does not match any resources.
    static <FF> QueryFilter<FF>
    Returns a filter which matches all resources.
    static <FF> QueryFilter<FF>
    and(Collection<QueryFilter<FF>> subFilters)
    Creates a new and filter using the provided list of sub-filters.
    static <FF> QueryFilter<FF>
    and(QueryFilter<FF>... subFilters)
    Creates a new and filter using the provided list of sub-filters.
    static <FF> QueryFilter<FF>
    comparisonFilter(FF field, String operator, Object valueAssertion)
    Creates a new generic comparison filter using the provided field name, operator, and value assertion.
    static <FF> QueryFilter<FF>
    complex(FF field, QueryFilter<FF> subFilter)
    Creates a new complex filter using the provided field name and sub-filter expression.
    static <FF> QueryFilter<FF>
    contains(FF field, Object valueAssertion)
    Creates a new contains filter using the provided field name and value assertion.
    boolean
     
    static <FF> QueryFilter<FF>
    equalTo(FF field, Object valueAssertion)
    Creates a new equality filter using the provided field name and value assertion.
    static <FF> QueryFilter<FF>
    extendedMatch(FF field, String operator, Object valueAssertion)
    Creates a new extended match filter using the provided field name, operator and value assertion.
    static <FF> QueryFilter<FF>
    greaterThan(FF field, Object valueAssertion)
    Creates a new greater than filter using the provided field name and value assertion.
    static <FF> QueryFilter<FF>
    greaterThanOrEqualTo(FF field, Object valueAssertion)
    Creates a new greater than or equal to filter using the provided field name and value assertion.
    int
     
    static <FF> QueryFilter<FF>
    lessThan(FF field, Object valueAssertion)
    Creates a new less than filter using the provided field name and value assertion.
    static <FF> QueryFilter<FF>
    lessThanOrEqualTo(FF field, Object valueAssertion)
    Creates a new less than or equal to filter using the provided field name and value assertion.
    static <FF> QueryFilter<FF>
    not(QueryFilter<FF> subFilter)
    Creates a new not filter using the provided sub-filter.
    static <FF> QueryFilter<FF>
    or(Collection<QueryFilter<FF>> subFilters)
    Creates a new or filter using the provided list of sub-filters.
    static <FF> QueryFilter<FF>
    or(QueryFilter<FF>... subFilters)
    Creates a new or filter using the provided list of sub-filters.
    static <FF> QueryFilter<FF>
    present(FF field)
    Creates a new presence filter using the provided field name.
    static <FF> QueryFilter<FF>
    startsWith(FF field, Object valueAssertion)
    Creates a new starts with filter using the provided field name and value assertion.
    Returns the string representation of this query filter.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • pimpl

      protected final org.forgerock.util.query.QueryFilter.Impl<F> pimpl
      the filter implementation.
  • Constructor Details

    • QueryFilter

      protected QueryFilter(org.forgerock.util.query.QueryFilter.Impl<F> pimpl)
      Construct a QueryFilter from a base filter implementation.
      Parameters:
      pimpl - the filter implementation.
    • QueryFilter

      protected QueryFilter(org.forgerock.util.query.QueryFilter.Impl<F> pimpl, QueryFilterVisitor<StringBuilder,StringBuilder,F> toStringVisitor)
      Construct a QueryFilter from a base filter implementation and a custom toString implementation.
      Parameters:
      pimpl - the filter implemntation.
      toStringVisitor - the visitor to provide a toString implementation.
  • Method Details

    • alwaysFalse

      public static <FF> QueryFilter<FF> alwaysFalse()
      Returns a filter which does not match any resources.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Returns:
      A filter which does not match any resources.
    • alwaysTrue

      public static <FF> QueryFilter<FF> alwaysTrue()
      Returns a filter which matches all resources.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Returns:
      A filter which matches all resources.
    • and

      public static <FF> QueryFilter<FF> and(Collection<QueryFilter<FF>> subFilters)
      Creates a new and filter using the provided list of sub-filters.

      Creating a new and filter with a null or empty list of sub-filters is equivalent to calling alwaysTrue().

      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      subFilters - The list of sub-filters, may be empty or null.
      Returns:
      The newly created and filter.
    • and

      @SafeVarargs public static <FF> QueryFilter<FF> and(QueryFilter<FF>... subFilters)
      Creates a new and filter using the provided list of sub-filters.

      Creating a new and filter with a null or empty list of sub-filters is equivalent to calling alwaysTrue().

      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      subFilters - The list of sub-filters, may be empty or null.
      Returns:
      The newly created and filter.
    • comparisonFilter

      public static <FF> QueryFilter<FF> comparisonFilter(FF field, String operator, Object valueAssertion)
      Creates a new generic comparison filter using the provided field name, operator, and value assertion. When the provided operator name represents a core operator, e.g. "eq", then this method is equivalent to calling the equivalent constructor, e.g. equalTo(Object, Object). Otherwise, when the operator name does not correspond to a core operator, an extended comparison filter will be returned.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field within the JSON resource to be compared.
      operator - The operator to use for the comparison, which must be one of the core operator names, or a string matching the regular expression [a-zA-Z_0-9.]+.
      valueAssertion - The assertion value.
      Returns:
      The newly created generic comparison filter.
      Throws:
      IllegalArgumentException - If operator is not a valid operator name.
    • contains

      public static <FF> QueryFilter<FF> contains(FF field, Object valueAssertion)
      Creates a new contains filter using the provided field name and value assertion. This method is used to check that the string representation of the field contains the provided substring. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if any of the element's string representations contain the provided substring.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created contains filter.
    • equalTo

      public static <FF> QueryFilter<FF> equalTo(FF field, Object valueAssertion)
      Creates a new equality filter using the provided field name and value assertion. This would represent either equality for single values, or contains and equal value for a collection of values.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created equality filter.
    • greaterThan

      public static <FF> QueryFilter<FF> greaterThan(FF field, Object valueAssertion)
      Creates a new greater than filter using the provided field name and value assertion. This method is used to check that the value of the field is greater than the provided value. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if any of the element's values are greater than the provided value.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created greater than filter.
    • greaterThanOrEqualTo

      public static <FF> QueryFilter<FF> greaterThanOrEqualTo(FF field, Object valueAssertion)
      Creates a new greater than or equal to filter using the provided field name and value assertion. This method is used to check that the value of the field is greater than or equal to the provided value. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if any of the element's values are greater than or equal to the provided value.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created greater than or equal to filter.
    • lessThan

      public static <FF> QueryFilter<FF> lessThan(FF field, Object valueAssertion)
      Creates a new less than filter using the provided field name and value assertion. This method is used to check that the value of the field is less than the provided value. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if any of the element's values are less than the provided value.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created less than filter.
    • extendedMatch

      public static <FF> QueryFilter<FF> extendedMatch(FF field, String operator, Object valueAssertion)
      Creates a new extended match filter using the provided field name, operator and value assertion.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      operator - The operator.
      valueAssertion - The assertion value.
      Returns:
      The newly created less than or equal to filter.
    • lessThanOrEqualTo

      public static <FF> QueryFilter<FF> lessThanOrEqualTo(FF field, Object valueAssertion)
      Creates a new less than or equal to filter using the provided field name and value assertion. This method is used to check that the value of the field is less than or equal to the provided value. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if any of the element's values are less than or equal to the provided value.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created less than or equal to filter.
    • not

      public static <FF> QueryFilter<FF> not(QueryFilter<FF> subFilter)
      Creates a new not filter using the provided sub-filter.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      subFilter - The sub-filter.
      Returns:
      The newly created not filter.
    • or

      public static <FF> QueryFilter<FF> or(Collection<QueryFilter<FF>> subFilters)
      Creates a new or filter using the provided list of sub-filters.

      Creating a new or filter with a null or empty list of sub-filters is equivalent to calling alwaysFalse().

      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      subFilters - The list of sub-filters, may be empty or null.
      Returns:
      The newly created or filter.
    • or

      @SafeVarargs public static <FF> QueryFilter<FF> or(QueryFilter<FF>... subFilters)
      Creates a new or filter using the provided list of sub-filters.

      Creating a new or filter with a null or empty list of sub-filters is equivalent to calling alwaysFalse().

      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      subFilters - The list of sub-filters, may be empty or null.
      Returns:
      The newly created or filter.
    • present

      public static <FF> QueryFilter<FF> present(FF field)
      Creates a new presence filter using the provided field name.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field which must be present.
      Returns:
      The newly created presence filter.
    • startsWith

      public static <FF> QueryFilter<FF> startsWith(FF field, Object valueAssertion)
      Creates a new starts with filter using the provided field name and value assertion. This method is used to check that the string representation of the field starts with the provided substring. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if any of the element's string representations starts with the provided substring.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      valueAssertion - The assertion value.
      Returns:
      The newly created starts with filter.
    • complex

      public static <FF> QueryFilter<FF> complex(FF field, QueryFilter<FF> subFilter)
      Creates a new complex filter using the provided field name and sub-filter expression. This method is used to check that child attributes beneath the parent attribute field meet the criteria set forth by the sub-expression. When operating on a collection of values the operation should be evaluated on each element in the collection, passing if an element's sub-attributes match the given sub-filter.
      Type Parameters:
      FF - The type of the field specification. Named to be distinct from the type of the parent class.
      Parameters:
      field - The name of field to be compared.
      subFilter - The sub-expression applied to child attributes of field.
      Returns:
      The newly created complex filter.
    • accept

      public <R, P> R accept(QueryFilterVisitor<R,P,F> v, P p)
      Applies a QueryFilterVisitor to this QueryFilter.
      Type Parameters:
      R - The return type of the visitor's methods.
      P - The type of the additional parameters to the visitor's methods.
      Parameters:
      v - The filter visitor.
      p - Optional additional visitor parameter.
      Returns:
      A result as specified by the visitor.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns the string representation of this query filter. The string representation is defined to be similar to that of SCIM's, with the following differences:
      • field references are JSON pointers
      • support for boolean literal expressions, e.g. (true)
      • support for the logical not operator, e.g. (! /role eq "user")
      Overrides:
      toString in class Object
      Returns:
      The string representation of this query filter.