1 package lv.id.jc.piglatin.core;
2
3 import static java.lang.annotation.ElementType.FIELD;
4 import static java.lang.annotation.ElementType.METHOD;
5 import static java.lang.annotation.ElementType.PARAMETER;
6 import static java.lang.annotation.RetentionPolicy.RUNTIME;
7
8 import java.lang.annotation.Documented;
9 import java.lang.annotation.Retention;
10 import java.lang.annotation.Target;
11
12 import jakarta.validation.Constraint;
13 import jakarta.validation.Payload;
14 import jakarta.validation.constraints.NotBlank;
15 import jakarta.validation.constraints.NotNull;
16 import jakarta.validation.constraints.Pattern;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 @Documented
34 @Retention(RUNTIME)
35 @Constraint(validatedBy = {})
36 @Target({PARAMETER, METHOD, FIELD})
37 @NotNull
38 @NotBlank
39 @Pattern(regexp = """
40 #
41 # A single word
42 # contains only Unicode letters and apostrophe (') in the middle
43 # only one apostrophe is allowed
44 #
45 ^ # Start of the line
46 ( # Start of the group
47 \\p{L} # Any Unicode letter
48 | # OR
49 (?<=\\p{L}) # Positive lookbehind for a Unicode letter
50 ' # An apostrophe
51 (?=\\p{L}) # Positive lookahead for a Unicode letter
52 (?!.*') # Negative lookahead for another apostrophe
53 ) # End of the group
54 + # One or more of the previous group
55 $ # End of the line
56 """,
57 flags = {Pattern.Flag.COMMENTS, Pattern.Flag.CASE_INSENSITIVE}
58 )
59 public @interface Word {
60
61
62
63
64
65 String message() default "must be a single word";
66
67
68
69
70
71
72 Class<?>[] groups() default {};
73
74
75
76
77
78
79 Class<? extends Payload>[] payload() default {};
80 }