1 import java.lang.annotation.Documented; 2 import java.lang.annotation.ElementType; 3 import java.lang.annotation.Retention; 4 import java.lang.annotation.RetentionPolicy; 5 6 import javax.annotation.MatchesPattern; 7 import javax.annotation.meta.TypeQualifier; 8 import javax.annotation.meta.TypeQualifierValidator; 9 import javax.annotation.meta.When; 10 11 @Documented 12 @TypeQualifier 13 @MatchesPattern("[0-9]{16}") 14 @Retention(RetentionPolicy.RUNTIME) 15 public @interface CreditCardNumber { 16 class Checker implements TypeQualifierValidator<CreditCardNumber> { 17 forConstantValue(CreditCardNumber annotation, Object v)18 public When forConstantValue(CreditCardNumber annotation, Object v) { 19 if (!(v instanceof String)) 20 return When.NEVER; 21 String s = (String) v; 22 if (LuhnVerification.checkNumber(s)) 23 return When.ALWAYS; 24 return When.NEVER; 25 } 26 } 27 } 28