commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim O'Brien <tobr...@discursive.com>
Subject [beanutils] A BeanPredicate which wraps another Predicate
Date Mon, 08 Mar 2004 17:14:11 GMT
BeanUtils has a BeanPropertyValueEqualsPredicate, this Predicate uses 
PropertyUtils to get a bean property and then checks to see if the bean 
property equals a certain value.

This is great if your application needs to test a bean property for 
equality, but it limits what can be done with the various Predicates now 
available in collections 3.0.

I've added a BeanPredicate which allows you to decorate a Predicate to 
act upon a bean property.  This class is in the spirit of BeanComparator.

BeanPropertyValueEqualsPredicate predicate =
     new BeanPropertyValueEqualsPredicate( "activeEmployee",
			                  Boolean.FALSE );

Now becomes,

BeanPredicate predicate =
     new BeanPredicate( "activeEmployee",
                        new EqualPredicate( Boolean.FALSE ) );

And it also allow for other predicates.  To check for a null bean property:

BeanPredicate predicate =
     new BeanPredicate( "name", NullPredicate.INSTANCE );

Or to test the type of a bean property:

BeanPredicate predicate =
     new BeanPredicate( "name", new InstanceofPredicate(String.class) );

... and so on and so forth ...

Tim



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message