Gang,
ZEST-36...
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();
@Age
Property<Integer> age();
}
@ConstraintDeclaration
@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;
@Override
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.
WDYT?
Cheers
--
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java