Look at the HibernateValidator constraint implementations:
I. SimpleConstraint (14)
A) with empty initialize method (8)
Code:
// 1
public class AssertFalseValidator implements Validator<AssertFalse>, Serializable {
public void initialize(AssertFalse parameters) {
}
}
// 2
public class AssertTrueValidator implements Validator<AssertTrue>, Serializable {
public void initialize(AssertTrue parameters) {
}
}
// 3
public class CreditCardNumberValidator extends AbstractLuhnValidator implements Validator<CreditCardNumber>, Serializable {
public void initialize(CreditCardNumber parameters) {
}
}
// 4
public class EANValidator implements Validator<EAN> {
public void initialize(EAN parameters) {
}
}
// 5
public class FutureValidator implements Validator<Future>, Serializable {
public void initialize(Future parameters) {
}
}
// 6
public class NotEmptyValidator implements Validator<NotEmpty>, PropertyConstraint, Serializable {
public void initialize(NotEmpty parameters) {
}
}
// 7
public class NotNullValidator implements Validator<NotNull>, PropertyConstraint, Serializable {
public void initialize(NotNull parameters) {
}
}
// 8
public class PastValidator implements Validator<Past>, PropertyConstraint, Serializable {
public void initialize(Past parameters) {
}
}
B) initialize method copying data from the Annotation (6)
Code:
// 1
public class DigitsValidator implements Validator<Digits>, PropertyConstraint {
public void initialize(Digits configuration) {
integerDigits = configuration.integerDigits();
fractionalDigits = configuration.fractionalDigits();
}
}
// 2
public class LengthValidator implements Validator<Length>, PropertyConstraint, Serializable {
public void initialize(Length parameters) {
max = parameters.max();
min = parameters.min();
}
}
// 3
public class MaxValidator implements Validator<Max>, PropertyConstraint, Serializable {
public void initialize(Max parameters) {
max = parameters.value();
}
}
// 4
public class MinValidator implements Validator<Min>, PropertyConstraint, Serializable {
public void initialize(Min parameters) {
min = parameters.value();
}
}
// 5
public class RangeValidator implements Validator<Range>, PropertyConstraint, Serializable {
public void initialize(Range parameters) {
max = parameters.max();
min = parameters.min();
}
}
// 6
public class SizeValidator implements Validator<Size>, Serializable {
public void initialize(Size parameters) {
max = parameters.max();
min = parameters.min();
}
}
II. Constraint (2)
Code:
// 1
public class EmailValidator implements Validator<Email>, Serializable {
public void initialize(Email parameters) {
pattern = java.util.regex.Pattern.compile(
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$",
java.util.regex.Pattern.CASE_INSENSITIVE
);
pattern = java.util.regex.Pattern.compile(
"^" + ATOM + "+(\\." + ATOM + "+)*@"
+ DOMAIN
+ "|"
+ IP_DOMAIN
+ ")$",
java.util.regex.Pattern.CASE_INSENSITIVE
);
}
}
// 2
public class PatternValidator implements Validator<Pattern>, Serializable {
public void initialize(Pattern parameters) {
pattern = java.util.regex.Pattern.compile(
parameters.regex(),
parameters.flags()
);
}
}
So we have Constraint : SimpleConstraint = 2 : 14 = 1 : 7.
I thing we shoud reverse the naming, because the SimpleConstraint is used more often than the Constraint:
SimpleConstraint -> Constraint
Constraint -> HeavyweightConstraint
Maybe you do not like the interface name HeavyweightConstraint.., but I hope you get the idea.