polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Predicates as Constraints
Date Sat, 05 Sep 2015 07:49:46 GMT

I think it makes sense to get rid of the Constraint interface and use the
Predicate instead.
And at the same time support a ConstraintFactory concept, where the
Predicate can be created by a factory, to support the CompositeConstraint
concept that exists (I didn't know that).

So, something like this;

public interface Customer
    Property<String> name();

    Property<Integer> age();

@Retention( RUNTIME )
@Constraints( AgePredicate.class )
public @interface Age
    int min() default 18;
    int max() default 95;

public static class AgePredicate
    implements Predicate<Integer>
    private Age range;

    public boolean test( Integer argument )
        return argument > range.min() && argument < range.max();

I will think a little bit more about the ConstrainFactory, but it should
probably get access to a bit more than just the Annotation.

To make the codebase lean, I would like to remove the Constraint variant
completely, although @Constraints remain as previously.


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

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