2
2
3
3
import java .lang .annotation .Retention ;
4
4
import java .lang .annotation .RetentionPolicy ;
5
+ import java .util .Arrays ;
5
6
import java .util .Collections ;
6
7
import java .util .HashSet ;
7
8
import java .util .Set ;
@@ -120,7 +121,7 @@ public static CategoryFilter include(boolean matchAny, Class<?>... categories) {
120
121
if (hasNull (categories )) {
121
122
throw new NullPointerException ("has null category" );
122
123
}
123
- return categoryFilter (matchAny , createSet ( categories ) , true , null );
124
+ return new CategoryFilter (matchAny , categories , true , null );
124
125
}
125
126
126
127
public static CategoryFilter include (Class <?> category ) {
@@ -135,7 +136,7 @@ public static CategoryFilter exclude(boolean matchAny, Class<?>... categories) {
135
136
if (hasNull (categories )) {
136
137
throw new NullPointerException ("has null category" );
137
138
}
138
- return categoryFilter (true , null , matchAny , createSet ( categories ) );
139
+ return new CategoryFilter (true , null , matchAny , categories );
139
140
}
140
141
141
142
public static CategoryFilter exclude (Class <?> category ) {
@@ -151,14 +152,27 @@ public static CategoryFilter categoryFilter(boolean matchAnyInclusions, Set<Clas
151
152
return new CategoryFilter (matchAnyInclusions , inclusions , matchAnyExclusions , exclusions );
152
153
}
153
154
155
+ @ Deprecated
156
+ public CategoryFilter (Class <?> includedCategory , Class <?> excludedCategory ) {
157
+ this (true , createSet (includedCategory ), true , createSet (excludedCategory ));
158
+ }
159
+
154
160
protected CategoryFilter (boolean matchAnyIncludes , Set <Class <?>> includes ,
155
- boolean matchAnyExcludes , Set <Class <?>> excludes ) {
161
+ boolean matchAnyExcludes , Set <Class <?>> excludes ) {
156
162
includedAny = matchAnyIncludes ;
157
163
excludedAny = matchAnyExcludes ;
158
164
included = copyAndRefine (includes );
159
165
excluded = copyAndRefine (excludes );
160
166
}
161
167
168
+ private CategoryFilter (boolean matchAnyIncludes , Class <?>[] inclusions ,
169
+ boolean matchAnyExcludes , Class <?>[] exclusions ) {
170
+ includedAny = matchAnyIncludes ;
171
+ excludedAny = matchAnyExcludes ;
172
+ included = createSet (inclusions );
173
+ excluded = createSet (exclusions );
174
+ }
175
+
162
176
/**
163
177
* @see #toString()
164
178
*/
@@ -347,10 +361,11 @@ private static boolean hasAssignableTo(Set<Class<?>> assigns, Class<?> to) {
347
361
}
348
362
349
363
private static Set <Class <?>> createSet (Class <?>... t ) {
350
- final Set <Class <?>> set = new HashSet <Class <?>>();
351
- if (t != null ) {
352
- Collections .addAll (set , t );
364
+ if (t == null || t .length == 0 ) {
365
+ return Collections .emptySet ();
366
+ } else if (t .length == 1 ) {
367
+ return Collections .<Class <?>>singleton (t [0 ]);
353
368
}
354
- return set ;
369
+ return new HashSet < Class <?>>( Arrays . asList ( t )) ;
355
370
}
356
371
}
0 commit comments