polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kent SĂžlvsten <kent.soelvs...@gmail.com>
Subject Re: Predicates as Constraints
Date Sat, 05 Sep 2015 18:49:36 GMT
CompositeConstraint is a terrible name!

My initial thought while hearing the term was some way of letting a
composite implement the predicate.
Reading the assembly code revealed it was more a matter of
grouping/reusing constraints.

Something like allowing

@ConstraintDeclaration @NotEmpty
@Constraints( NoEmptyStringsInCollectionConstraint.class )
public @interface HasValue {
}

Not sure i get the ConstraintFactory idea - i guess a prototype will
tell more than a 1000 words :-)

/Kent


Den 05-09-2015 kl. 11:41 skrev Niclas Hedhman:
> Ok, after digging in this for an hour or so, I have discovered more
> features...
>
> The above is the default implementation, and it is then possible to throw
> other implementations at the composite, and in that way override the
> Constraint check declared in the annotation. There is also the Composite
> Constraint feature (which I want to replace with factory instead)
>
> The mechanism uses the fact that the Constraint implementation contains the
> Annotation type as a generics argument, and that is how they are matched.
> IF I go with Predicate, there is no such possibility, unless the Predicate
> itself is annotated (I think not so nice).
>
> So, the immediate question is; How desirable is this "override" feature? Is
> there any other way to achieve the same functionality?
>
> Cheers
> Niclas
>
>
> On Sat, Sep 5, 2015 at 3:49 PM, Niclas Hedhman <niclas@hedhman.org> wrote:
>
>> 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
>>
>
>


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