16
16
17
17
package com .google .common .collect .testing .features ;
18
18
19
+ import static com .google .common .collect .testing .Helpers .copyToSet ;
20
+ import static java .util .Collections .disjoint ;
21
+ import static java .util .Collections .unmodifiableList ;
22
+
19
23
import com .google .common .annotations .GwtIncompatible ;
20
- import com .google .common .collect .testing .Helpers ;
21
24
import com .google .errorprone .annotations .CanIgnoreReturnValue ;
22
25
import java .lang .annotation .Annotation ;
23
26
import java .lang .reflect .AnnotatedElement ;
24
27
import java .lang .reflect .Method ;
25
28
import java .util .ArrayDeque ;
26
29
import java .util .ArrayList ;
27
- import java .util .Collections ;
28
30
import java .util .HashMap ;
29
31
import java .util .LinkedHashSet ;
30
32
import java .util .List ;
39
41
* @author George van den Driessche
40
42
*/
41
43
@ GwtIncompatible
42
- public class FeatureUtil {
44
+ public final class FeatureUtil {
43
45
/** A cache of annotated objects (typically a Class or Method) to its set of annotations. */
44
- private static Map <AnnotatedElement , List <Annotation >> annotationCache = new HashMap <>();
46
+ private static final Map <AnnotatedElement , List <Annotation >> annotationCache = new HashMap <>();
45
47
46
48
private static final Map <Class <?>, TesterRequirements > classTesterRequirementsCache =
47
49
new HashMap <>();
@@ -181,16 +183,14 @@ private static TesterRequirements buildTesterRequirements(Annotation testerAnnot
181
183
Feature <?>[] presentFeatures ;
182
184
Feature <?>[] absentFeatures ;
183
185
try {
184
- presentFeatures = (Feature []) annotationClass .getMethod ("value" ).invoke (testerAnnotation );
185
- absentFeatures = (Feature []) annotationClass .getMethod ("absent" ).invoke (testerAnnotation );
186
+ presentFeatures = (Feature <?> []) annotationClass .getMethod ("value" ).invoke (testerAnnotation );
187
+ absentFeatures = (Feature <?> []) annotationClass .getMethod ("absent" ).invoke (testerAnnotation );
186
188
} catch (Exception e ) {
187
189
throw new IllegalArgumentException ("Error extracting features from tester annotation." , e );
188
190
}
189
- Set <Feature <?>> allPresentFeatures =
190
- addImpliedFeatures (Helpers .<Feature <?>>copyToSet (presentFeatures ));
191
- Set <Feature <?>> allAbsentFeatures =
192
- addImpliedFeatures (Helpers .<Feature <?>>copyToSet (absentFeatures ));
193
- if (!Collections .disjoint (allPresentFeatures , allAbsentFeatures )) {
191
+ Set <Feature <?>> allPresentFeatures = addImpliedFeatures (copyToSet (presentFeatures ));
192
+ Set <Feature <?>> allAbsentFeatures = copyToSet (absentFeatures );
193
+ if (!disjoint (allPresentFeatures , allAbsentFeatures )) {
194
194
throw new ConflictingRequirementsException (
195
195
"Annotation explicitly or "
196
196
+ "implicitly requires one or more features to be both present "
@@ -239,7 +239,7 @@ public static Iterable<Annotation> getTesterAnnotations(AnnotatedElement classOr
239
239
annotations .add (a );
240
240
}
241
241
}
242
- annotations = Collections . unmodifiableList (annotations );
242
+ annotations = unmodifiableList (annotations );
243
243
annotationCache .put (classOrMethod , annotations );
244
244
}
245
245
return annotations ;
@@ -279,7 +279,7 @@ private static void checkConflict(
279
279
Set <Feature <?>> newFeatures ,
280
280
Object source )
281
281
throws ConflictingRequirementsException {
282
- if (!Collections . disjoint (newFeatures , earlierFeatures )) {
282
+ if (!disjoint (newFeatures , earlierFeatures )) {
283
283
throw new ConflictingRequirementsException (
284
284
String .format (
285
285
Locale .ROOT ,
@@ -292,10 +292,17 @@ private static void checkConflict(
292
292
}
293
293
}
294
294
295
- /** Construct a new {@link java.util.Set} that is the intersection of the given sets. */
295
+ /**
296
+ * Construct a new {@link java.util.Set} that is the intersection of the given sets.
297
+ *
298
+ * @deprecated Use {@link com.google.common.collect.Sets#intersection(Set, Set)} instead.
299
+ */
300
+ @ Deprecated
296
301
public static <T > Set <T > intersection (Set <? extends T > set1 , Set <? extends T > set2 ) {
297
- Set <T > result = Helpers .< T > copyToSet (set1 );
302
+ Set <T > result = copyToSet (set1 );
298
303
result .retainAll (set2 );
299
304
return result ;
300
305
}
306
+
307
+ private FeatureUtil () {}
301
308
}
0 commit comments