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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]