19
19
import java .lang .annotation .Annotation ;
20
20
import java .lang .reflect .AnnotatedElement ;
21
21
import java .util .ArrayList ;
22
+ import java .util .HashMap ;
22
23
import java .util .List ;
24
+ import java .util .Map ;
23
25
24
26
/**
25
27
* Factory for creating {@link SecurityAnnotationScanner} instances.
29
31
*/
30
32
public final class SecurityAnnotationScanners {
31
33
34
+ private static final Map <Class <? extends Annotation >, SecurityAnnotationScanner <? extends Annotation >> uniqueScanners = new HashMap <>();
35
+
36
+ private static final Map <Class <? extends Annotation >, SecurityAnnotationScanner <? extends Annotation >> uniqueTemplateScanners = new HashMap <>();
37
+
38
+ private static final Map <List <Class <? extends Annotation >>, SecurityAnnotationScanner <? extends Annotation >> uniqueTypesScanners = new HashMap <>();
39
+
32
40
private SecurityAnnotationScanners () {
33
41
}
34
42
@@ -40,7 +48,8 @@ private SecurityAnnotationScanners() {
40
48
* @return the default {@link SecurityAnnotationScanner}
41
49
*/
42
50
public static <A extends Annotation > SecurityAnnotationScanner <A > requireUnique (Class <A > type ) {
43
- return new UniqueSecurityAnnotationScanner <>(type );
51
+ return (SecurityAnnotationScanner <A >) uniqueScanners .computeIfAbsent (type ,
52
+ (t ) -> new UniqueSecurityAnnotationScanner <>(type ));
44
53
}
45
54
46
55
/**
@@ -60,9 +69,10 @@ public static <A extends Annotation> SecurityAnnotationScanner<A> requireUnique(
60
69
public static <A extends Annotation > SecurityAnnotationScanner <A > requireUnique (Class <A > type ,
61
70
AnnotationTemplateExpressionDefaults templateDefaults ) {
62
71
if (templateDefaults == null ) {
63
- return new UniqueSecurityAnnotationScanner <> (type );
72
+ return requireUnique (type );
64
73
}
65
- return new ExpressionTemplateSecurityAnnotationScanner <>(type , templateDefaults );
74
+ return (SecurityAnnotationScanner <A >) uniqueTemplateScanners .computeIfAbsent (type ,
75
+ (t ) -> new ExpressionTemplateSecurityAnnotationScanner <>(t , templateDefaults ));
66
76
}
67
77
68
78
/**
@@ -75,7 +85,8 @@ public static <A extends Annotation> SecurityAnnotationScanner<A> requireUnique(
75
85
public static SecurityAnnotationScanner <Annotation > requireUnique (List <Class <? extends Annotation >> types ) {
76
86
List <Class <Annotation >> casted = new ArrayList <>();
77
87
types .forEach ((type ) -> casted .add ((Class <Annotation >) type ));
78
- return new UniqueSecurityAnnotationScanner <>(casted );
88
+ return (SecurityAnnotationScanner <Annotation >) uniqueTypesScanners .computeIfAbsent (types ,
89
+ (t ) -> new UniqueSecurityAnnotationScanner <>(casted ));
79
90
}
80
91
81
92
}
0 commit comments