commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [collections] NegatingPredicate
Date Mon, 01 Dec 2003 23:18:15 GMT
On the CVS you will find a whole package full of predicate implementations,
including this one - NotPredicate. Also accessible through PredicateUtils.

Still working towards a release....

Stephen

----- Original Message -----
From: "Keith Bennett" <krbennettmd@yahoo.com>
> When using the Predicate interface, I thought it would be useful to be
> able to negate a predicate rather than writing a new one with the
> opposite behavior.  Soon afterwards, I encountered a real need for
> such a thing, so I wrote it.  If you think this would be useful to add
> to the library (as I do IMHO), feel free to do so, or let me know how
> I can be of help in doing so.  Here it is:
>
> -----
>
> import org.apache.commons.collections.Predicate;
>
> /**
>  * Wraps a Predicate and reverses its return value.
>  */
> public class NegatingPredicate implements Predicate
> {
>
>     private Predicate predicate;
>
>     /**
>      * Creates an instance with the specified Predicate.
>      *
>      * @param p the predicate to wrap and reverse
>      */
>     NegatingPredicate(Predicate p) {
>         predicate = p;
>     }
>
>     /**
>      * Gets the result of the wrapped Predicate and negates it.
>      *
>      * @param o the object to evaluate
>      */
>     public boolean evaluate(Object o) {
>         return ! predicate.evaluate(o);
>     }
> }
>
> -----
>
> - Keith Bennett
>
>
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
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