3131import java .util .TreeMap ;
3232import java .util .TreeSet ;
3333import java .util .function .BiPredicate ;
34- import java .util .function .Predicate ;
3534import java .util .function .Supplier ;
3635import java .util .stream .Collectors ;
3736import java .util .stream .Stream ;
@@ -73,7 +72,7 @@ public class JavaPackage implements DescribedIterable<JavaClass>, Comparable<Jav
7372 */
7473 private JavaPackage (Classes classes , PackageName name , boolean includeSubPackages ) {
7574
76- this (classes .that ( resideInAPackage ( name . asFilter ( includeSubPackages )) ), name , includeSubPackages
75+ this (classes .thatResideIn ( name , includeSubPackages ), name , includeSubPackages
7776 ? SingletonSupplier .of (() -> detectSubPackages (classes , name ))
7877 : SingletonSupplier .of (JavaPackages .NONE ));
7978 }
@@ -92,7 +91,7 @@ private JavaPackage(Classes classes, PackageName name, Supplier<JavaPackages> su
9291 Assert .notNull (name , "PackageName must not be null!" );
9392 Assert .notNull (subpackages , "Sub-packages must not be null!" );
9493
95- this .classes = classes .that ( resideInAPackage ( name . asFilter ( true )) );
94+ this .classes = classes .thatResideIn ( name , true );
9695 this .name = name ;
9796 this .subPackages = subpackages ;
9897 this .directSubPackages = SingletonSupplier .of (() -> subPackages .get ().stream ()
@@ -206,15 +205,12 @@ public Stream<JavaPackage> getSubPackagesAnnotatedWith(Class<? extends Annotatio
206205
207206 Assert .notNull (annotation , "Annotation must not be null!" );
208207
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 ));
214210 }
215211
216212 /**
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
218214 * relative to the current one.
219215 *
220216 * @param filter must not be {@literal null}.
@@ -388,7 +384,7 @@ Optional<JavaPackage> getSubPackage(String localName) {
388384
389385 /**
390386 * Finds the annotation of the given type declared on the package itself or any type located the direct package's
391- * types .
387+ * types.
392388 *
393389 * @param <A> the type of the annotation.
394390 * @param annotationType must not be {@literal null}.
@@ -502,6 +498,17 @@ public int hashCode() {
502498 return Objects .hash (classes , directSubPackages .get (), name );
503499 }
504500
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+
505512 static Comparator <JavaPackage > reverse () {
506513 return (left , right ) -> -left .compareTo (right );
507514 }
0 commit comments