polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Re: Predicates as Constraints
Date Mon, 07 Sep 2015 15:34:37 GMT
No, please.... ;-)  No programming language in annotations.


Is that even possible??

You are trying to avoid new annotations, and build logic with smaller ones.
It feels super-icky to me...
Off the top of my head, something like this;

void someMethod( @PaulsDreaming(1,4,8) Integer something );

@ConstraintFactory( PaulsDreamFactory.class )
public interface @PaulsDreaming
{
    int[] value();
}

public class PaulsDreamFactory
{
    public Predicate<Integer> create( PaulsDreaming annot )
    {
        int[] values = annot.values();
        return new RangePredicate( values[0], values[1])
               .or( new MinPredicate( values[2] ) );
    }
}

On Mon, Sep 7, 2015 at 5:22 PM, Paul Merlin <paul@nosphere.org> wrote:

> Niclas Hedhman a écrit :
> > The value in the annotation is solved by field/constructor injection and
> is
> > not an issue (I think).
> It should do it.
> It should also be noted that such a Predicate then cannot be written as
> a lambda.
>
>
> I now disgress but I'd like to add annotation support for logic
> combination of constraints. Something like:
>
> void someMethod( @Or({ @Range(1,4), @Min( 8 ) }) Integer something );
>
> Providing @Or, @And should not be too much work.
> What do you guys think about this?
>
> /Paul
>
>


-- 
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message