Predicate that evaluates a property value against a specified value.
An implementation of org.apache.commons.collections.Predicate that evaluates a
property value on the object provided against a specified value and returns true
if equal; false otherwise.
The BeanPropertyValueEqualsPredicate constructor takes two parameters which
determine what property will be evaluated on the target object and what its expected value should
be.
-
public BeanPropertyValueEqualsPredicate( String propertyName, Object propertyValue )
-
Will create a
Predicate that will evaluate the target object and return
true if the property specified by propertyName has a value which
is equal to the the value specified by propertyValue . Or return
false otherwise.
Note: Property names can be a simple, nested, indexed, or mapped property as defined by
org.apache.commons.beanutils.PropertyUtils . If any object in the property path
specified by propertyName is null then the outcome is based on the
value of the ignoreNull attribute.
A typical usage might look like:
// create the closure
BeanPropertyValueEqualsPredicate predicate =
new BeanPropertyValueEqualsPredicate( "activeEmployee", Boolean.FALSE );
// filter the Collection
CollectionUtils.filter( peopleCollection, predicate );
This would take a Collection of person objects and filter out any people whose
activeEmployee property is false . Assuming...
-
The top level object in the
peeopleCollection is an object which represents a
person.
-
The person object has a
getActiveEmployee() method which returns
the boolean value for the object's activeEmployee property.
Another typical usage might look like:
// create the closure
BeanPropertyValueEqualsPredicate predicate =
new BeanPropertyValueEqualsPredicate( "personId", "456-12-1234" );
// search the Collection
CollectionUtils.find( peopleCollection, predicate );
This would search a Collection of person objects and return the first object whose
personId property value equals 456-12-1234 . Assuming...
-
The top level object in the
peeopleCollection is an object which represents a
person.
-
The person object has a
getPersonId() method which returns
the value for the object's personId property.
author: Norm Deane See Also: org.apache.commons.beanutils.PropertyUtils See Also: org.apache.commons.collections.Predicate |