31
31
import java .util .TreeMap ;
32
32
import java .util .TreeSet ;
33
33
import java .util .function .BiPredicate ;
34
- import java .util .function .Predicate ;
35
34
import java .util .function .Supplier ;
36
35
import java .util .stream .Collectors ;
37
36
import java .util .stream .Stream ;
@@ -73,7 +72,7 @@ public class JavaPackage implements DescribedIterable<JavaClass>, Comparable<Jav
73
72
*/
74
73
private JavaPackage (Classes classes , PackageName name , boolean includeSubPackages ) {
75
74
76
- this (classes .that ( resideInAPackage ( name . asFilter ( includeSubPackages )) ), name , includeSubPackages
75
+ this (classes .thatResideIn ( name , includeSubPackages ), name , includeSubPackages
77
76
? SingletonSupplier .of (() -> detectSubPackages (classes , name ))
78
77
: SingletonSupplier .of (JavaPackages .NONE ));
79
78
}
@@ -92,7 +91,7 @@ private JavaPackage(Classes classes, PackageName name, Supplier<JavaPackages> su
92
91
Assert .notNull (name , "PackageName must not be null!" );
93
92
Assert .notNull (subpackages , "Sub-packages must not be null!" );
94
93
95
- this .classes = classes .that ( resideInAPackage ( name . asFilter ( true )) );
94
+ this .classes = classes .thatResideIn ( name , true );
96
95
this .name = name ;
97
96
this .subPackages = subpackages ;
98
97
this .directSubPackages = SingletonSupplier .of (() -> subPackages .get ().stream ()
@@ -206,15 +205,12 @@ public Stream<JavaPackage> getSubPackagesAnnotatedWith(Class<? extends Annotatio
206
205
207
206
Assert .notNull (annotation , "Annotation must not be null!" );
208
207
209
- return classes .that (ARE_PACKAGE_INFOS .and (are (metaAnnotatedWith (annotation )))).stream () //
210
- .map (JavaClass ::getPackageName ) //
211
- .filter (Predicate .not (name ::hasName ))
212
- .distinct () //
213
- .map (it -> of (classes , it ));
208
+ return getSubPackages ().stream ()
209
+ .filter (it -> it .hasAnnotation (annotation ));
214
210
}
215
211
216
212
/**
217
- * Returns all sub-packages that match the given {@link BiPredicate} for the canidate package and its trailing name
213
+ * Returns all sub-packages that match the given {@link BiPredicate} for the candidate package and its trailing name
218
214
* relative to the current one.
219
215
*
220
216
* @param filter must not be {@literal null}.
@@ -388,7 +384,7 @@ Optional<JavaPackage> getSubPackage(String localName) {
388
384
389
385
/**
390
386
* Finds the annotation of the given type declared on the package itself or any type located the direct package's
391
- * types .
387
+ * types.
392
388
*
393
389
* @param <A> the type of the annotation.
394
390
* @param annotationType must not be {@literal null}.
@@ -502,6 +498,17 @@ public int hashCode() {
502
498
return Objects .hash (classes , directSubPackages .get (), name );
503
499
}
504
500
501
+ /**
502
+ * Returns whether the current {@link JavaPackage}
503
+ *
504
+ * @param <A>
505
+ * @param annotationType
506
+ * @return
507
+ */
508
+ private <A extends Annotation > boolean hasAnnotation (Class <A > annotationType ) {
509
+ return findAnnotation (annotationType ).isPresent ();
510
+ }
511
+
505
512
static Comparator <JavaPackage > reverse () {
506
513
return (left , right ) -> -left .compareTo (right );
507
514
}
0 commit comments