org.kuali.rice.core.api.criteria
Class PredicateFactory

java.lang.Object
  extended by org.kuali.rice.core.api.criteria.PredicateFactory

public final class PredicateFactory
extends Object

This is a factory class to construct Predicates.

For more readable predicate construction it is recommended that this class is statically imported. import static org.kuali.rice.core.api.criteria.PredicateFactory.*;

to create a simple predicate where the property foo.bar equals "baz" do the following: Predicate simple = equals("foo.bar", "baz"); to create a compound predicate where the property foo.bar equals "baz" and foo.id equals 1 do the following: Predicate compound = and(equals("foo.bar", "baz"), equals("foo.id", 1)) to create a deeply nested predicate where lots of properties are evaluated do the following: Predicate apiAuthors = and( like("display", "*Eric*"), greaterThan("birthDate", gtBirthDate), lessThan("birthDate", ltBirthDate), or( equal("name.first", "Travis"), equal("name.last", "Schneeberger")))

WARNING: this class does automatic reductions such that you cannot assume the concrete Predicate type returned from this factory.

See Also:
QueryByCriteria

Method Summary
static Predicate and(Predicate... predicates)
          Creates an and predicate that is used to "and" predicates together.
static Predicate dynConstruct(String name, Object... args)
          This method will construct a predicate based on the predicate name.
static Predicate equal(String propertyPath, Object value)
          Creates an predicate representing equals comparison.
static Predicate equalIgnoreCase(String propertyPath, CharSequence value)
          Creates an equals ignore case predicate.
static Predicate greaterThan(String propertyPath, Object value)
          Creates a greater than predicate.
static Predicate greaterThanOrEqual(String propertyPath, Object value)
          Creates a greater than or equal predicate.
static
<T> Predicate
in(String propertyPath, T... values)
          Create an in predicate.
static
<T extends CharSequence>
Predicate
inIgnoreCase(String propertyPath, T... values)
          Create an in ignore case predicate.
static Predicate isNotNull(String propertyPath)
          Creates an is not null predicate.
static Predicate isNull(String propertyPath)
          Creates an is null predicate.
static Predicate lessThan(String propertyPath, Object value)
          Creates a less than predicate.
static Predicate lessThanOrEqual(String propertyPath, Object value)
          Creates a less than or equal predicate.
static Predicate like(String propertyPath, CharSequence value)
          Creates a like predicate.
static Predicate notEqual(String propertyPath, Object value)
          Creates a predicate representing not equals comparison.
static Predicate notEqualIgnoreCase(String propertyPath, CharSequence value)
          Creates a not equals ignore case predicate.
static
<T> Predicate
notIn(String propertyPath, T... values)
          Create a not in predicate.
static
<T extends CharSequence>
Predicate
notInIgnoreCase(String propertyPath, T... values)
          Create a not in ignore case.
static Predicate notLike(String propertyPath, CharSequence value)
          Creates a not like predicate.
static Predicate or(Predicate... predicates)
          Creates an or predicate that is used to "or" predicate together.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equal

public static Predicate equal(String propertyPath,
                              Object value)
Creates an predicate representing equals comparison. Defines that the property represented by the given path should be equal to the specified value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

notEqual

public static Predicate notEqual(String propertyPath,
                                 Object value)
Creates a predicate representing not equals comparison. Defines that the property represented by the given path should not be equal to the specified value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

equalIgnoreCase

public static Predicate equalIgnoreCase(String propertyPath,
                                        CharSequence value)
Creates an equals ignore case predicate. Defines that the property represented by the given path should be equal to the specified value ignoring the case of the value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

notEqualIgnoreCase

public static Predicate notEqualIgnoreCase(String propertyPath,
                                           CharSequence value)
Creates a not equals ignore case predicate. Defines that the property represented by the given path should not be equal to the specified value ignoring the case of the value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

like

public static Predicate like(String propertyPath,
                             CharSequence value)
Creates a like predicate. Defines that the property represented by the given path should match the specified value, but supports the use of wildcards in the given value.

The supported wildcards include:

Because of this, the like predicate only supports character data for the passed-in value.

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null

notLike

public static Predicate notLike(String propertyPath,
                                CharSequence value)
Creates a not like predicate. Defines that the property represented by the given path should not match the specified value, but supports the use of wildcards in the given value.

The supported wildcards include:

Because of this, the like predicate only supports character data for the passed-in value.

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null

in

public static <T> Predicate in(String propertyPath,
                               T... values)
Create an in predicate. Defines that the property represented by the given path should be contained within the specified list of values.

Supports any of the valid types of value in the value list, with the restriction that all items in the list of values must be of the same type.

Parameters:
propertyPath - the path to the property which should be evaluated
values - the values to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the values list is null, empty, contains object of different types, or includes objects of an invalid type

notIn

public static <T> Predicate notIn(String propertyPath,
                                  T... values)
Create a not in predicate. Defines that the property represented by the given path should not be contained within the specified list of values.

Supports any of the valid types of value in the value list, with the restriction that all items in the list of values must be of the same type.

Parameters:
propertyPath - the path to the property which should be evaluated
values - the values to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the values list is null, empty, contains object of different types, or includes objects of an invalid type

inIgnoreCase

public static <T extends CharSequence> Predicate inIgnoreCase(String propertyPath,
                                                              T... values)
Create an in ignore case predicate. Defines that the property represented by the given path should be contained within the specified list of values ignoring the case of the values.

Supports any of CharSequence value in the value list, with the restriction that all items in the list of values must be of the same type.

Parameters:
propertyPath - the path to the property which should be evaluated
values - the values to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the values list is null, empty, contains object of different types, or includes objects of an invalid type

notInIgnoreCase

public static <T extends CharSequence> Predicate notInIgnoreCase(String propertyPath,
                                                                 T... values)
Create a not in ignore case. Defines that the property represented by the given path should not be contained within the specified list of values ignoring the case of the values.

Supports any CharSequence value in the value list, with the restriction that all items in the list of values must be of the same type.

Parameters:
propertyPath - the path to the property which should be evaluated
values - the values to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the values list is null, empty, contains object of different types, or includes objects of an invalid type

greaterThan

public static Predicate greaterThan(String propertyPath,
                                    Object value)
Creates a greater than predicate. Defines that the property represented by the given path should be greater than the specified value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

greaterThanOrEqual

public static Predicate greaterThanOrEqual(String propertyPath,
                                           Object value)
Creates a greater than or equal predicate. Defines that the property represented by the given path should be greater than or equal to the specified value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

lessThan

public static Predicate lessThan(String propertyPath,
                                 Object value)
Creates a less than predicate. Defines that the property represented by the given path should be less than the specified value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

lessThanOrEqual

public static Predicate lessThanOrEqual(String propertyPath,
                                        Object value)
Creates a less than or equal predicate. Defines that the property represented by the given path should be less than or equal to the specified value.

Supports the following types of values:

Parameters:
propertyPath - the path to the property which should be evaluated
value - the value to compare with the property value located at the propertyPath
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null
IllegalArgumentException - if the value is null or of an invalid type

isNull

public static Predicate isNull(String propertyPath)
Creates an is null predicate. Defines that the property represented by the given path should be null.

Parameters:
propertyPath - the path to the property which should be evaluated
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null

isNotNull

public static Predicate isNotNull(String propertyPath)
Creates an is not null predicate. Defines that the property represented by the given path should not be null.

Parameters:
propertyPath - the path to the property which should be evaluated
Returns:
a predicate
Throws:
IllegalArgumentException - if the propertyPath is null

and

public static Predicate and(Predicate... predicates)
Creates an and predicate that is used to "and" predicates together.

An "and" predicate will evaluate the truth value of of it's internal predicates and, if all of them evaluate to true, then the and predicate itself should evaluate to true. The implementation of an and predicate may short-circuit.

This factory method does automatic reductions.

Parameters:
predicates - to "and" together
Returns:
a predicate

or

public static Predicate or(Predicate... predicates)
Creates an or predicate that is used to "or" predicate together.

An "or" predicate will evaluate the truth value of of it's internal predicates and, if any one of them evaluate to true, then the or predicate itself should evaluate to true. If all predicates contained within the "or" evaluate to false, then the or iself will evaluate to false. The implementation of an or predicate may short-circuit.

This factory method does automatic reductions.

Parameters:
predicates - to "or" together
Returns:
a predicate

dynConstruct

public static Predicate dynConstruct(String name,
                                     Object... args)
This method will construct a predicate based on the predicate name. ex: "or", Or, "OrPredicate" passing the arguments to the construction method.

Parameters:
name - the name of the predicate to create.
args - the args required to construct the predicate
Returns:
the Predicate


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.