commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <pj...@sfaf.org>
Subject RE: [reflect][collection] Predicate - a question
Date Mon, 17 Jun 2002 17:02:20 GMT
Well, I think the proposed AssertingPredicate is secretly a Closure, no?


public class Assert implements Closure {

    private Predicate predicate;

    public Assert(Predicate p) {
        this.predicate = p;
    }

    public void execute(Object o) {
        if (!predicate.evaluate(o)) throw new AssertFailedException();
    }
}


-Paul

> -----Original Message-----
> From: scolebourne@btopenworld.com [mailto:scolebourne@btopenworld.com]
> Sent: Monday, June 17, 2002 5:21 AM
> To: commons-dev@jakarta.apache.org; ola.berg@arkitema.se
> Subject: Re: [reflect][collection] Predicate - a question
> 
> 
> >  from:    Ola Berg <ola.berg@arkitema.se>
> 
> This seems like a reasonable decorator to me. In collections 
> at present, the decorators for Predicate are on 
> PredicateUtils. Included are And, Or, Not, InstanceOf, Null, 
> NotNull. This would be another one to add.
> 
> Stephen
> 
> > I agree with you. And I would like to elaborate, by letting 
> Assert become a decorator for Predicate:
> > 
> > /**
> > This class throws AssertionException if the underlying
> > Predicate evaluates to false.
> > */
> > class AssertingPredicate implements Predicate {
> > 
> >     private Predicate _predicate;
> > 
> >     public AssertingPredicate( Predicate predicate){
> >         _predicate = predicate;
> >     }
> > 
> >     public boolean evaluate( Object input){
> >         if (!_predicate.evaluate( input)){
> >             throw new AssertionException( input, predicate);
> >         }
> >         else{
> >             return true;
> >         }
> >     }
> > }
> > 
> > Could be a candidate for lang (where Predicate already 
> should be IMO). Are common assertion mechanisms discussed here before?
> > 
> > /O
> > 
> > --
> > To unsubscribe, e-mail:   
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
> 


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

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


Mime
View raw message