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