@@ -1405,11 +1405,11 @@ private static Optional<Method> findMethod(Class<?> clazz, Predicate<Method> pre
14051405
14061406 for (Class <?> current = clazz ; isSearchable (current ); current = current .getSuperclass ()) {
14071407 // Search for match in current type
1408- List <Method > methods = current .isInterface () ? getMethods (current , predicate )
1409- : getDeclaredMethods ( current , predicate , BOTTOM_UP );
1410- if (! methods . isEmpty ( )) {
1411- // Since the predicate has already been applied, return the first match.
1412- return Optional . of ( methods . get ( 0 ));
1408+ List <Method > methods = current .isInterface () ? getMethods (current ) : getDeclaredMethods ( current , BOTTOM_UP );
1409+ for ( Method method : methods ) {
1410+ if (predicate . test ( method )) {
1411+ return Optional . of ( method );
1412+ }
14131413 }
14141414
14151415 // Search for match in interfaces implemented by current type
@@ -1504,8 +1504,8 @@ private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, Predicate<
15041504 Preconditions .notNull (traversalMode , "HierarchyTraversalMode must not be null" );
15051505
15061506 // @formatter:off
1507- List <Method > localMethods = getDeclaredMethods (clazz , predicate , traversalMode ).stream ()
1508- .filter (method -> !method .isSynthetic ())
1507+ List <Method > localMethods = getDeclaredMethods (clazz , traversalMode ).stream ()
1508+ .filter (predicate . and ( method -> !method .isSynthetic () ))
15091509 .collect (toList ());
15101510 List <Method > superclassMethods = getSuperclassMethods (clazz , predicate , traversalMode ).stream ()
15111511 .filter (method -> !isMethodShadowedByLocalMethods (method , localMethods ))
@@ -1546,26 +1546,24 @@ private static List<Field> getDeclaredFields(Class<?> clazz) {
15461546
15471547 /**
15481548 * Custom alternative to {@link Class#getMethods()} that sorts the methods
1549- * which match the supplied predicate and converts them to a mutable list.
1549+ * and converts them to a mutable list.
15501550 */
1551- private static List <Method > getMethods (Class <?> clazz , Predicate < Method > predicate ) {
1552- return toSortedMutableList (clazz .getMethods (), predicate );
1551+ private static List <Method > getMethods (Class <?> clazz ) {
1552+ return toSortedMutableList (clazz .getMethods ());
15531553 }
15541554
15551555 /**
15561556 * Custom alternative to {@link Class#getDeclaredMethods()} that sorts the
1557- * methods which match the supplied predicate and converts them to a mutable list.
1557+ * methods and converts them to a mutable list.
15581558 *
15591559 * <p>In addition, the list returned by this method includes interface
15601560 * default methods which are either prepended or appended to the list of
15611561 * declared methods depending on the supplied traversal mode.
15621562 */
1563- private static List <Method > getDeclaredMethods (Class <?> clazz , Predicate <Method > predicate ,
1564- HierarchyTraversalMode traversalMode ) {
1565-
1563+ private static List <Method > getDeclaredMethods (Class <?> clazz , HierarchyTraversalMode traversalMode ) {
15661564 // Note: getDefaultMethods() already sorts the methods,
1567- List <Method > defaultMethods = getDefaultMethods (clazz , predicate );
1568- List <Method > declaredMethods = toSortedMutableList (clazz .getDeclaredMethods (), predicate );
1565+ List <Method > defaultMethods = getDefaultMethods (clazz );
1566+ List <Method > declaredMethods = toSortedMutableList (clazz .getDeclaredMethods ());
15691567
15701568 // Take the traversal mode into account in order to retain the inherited
15711569 // nature of interface default methods.
@@ -1582,23 +1580,23 @@ private static List<Method> getDeclaredMethods(Class<?> clazz, Predicate<Method>
15821580 /**
15831581 * Get a sorted, mutable list of all default methods present in interfaces
15841582 * implemented by the supplied class which are also <em>visible</em> within
1585- * the supplied class and match the supplied predicate .
1583+ * the supplied class.
15861584 *
15871585 * @see <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#d5e9652">Method Visibility</a>
15881586 * in the Java Language Specification
15891587 */
1590- private static List <Method > getDefaultMethods (Class <?> clazz , Predicate < Method > predicate ) {
1588+ private static List <Method > getDefaultMethods (Class <?> clazz ) {
15911589 // @formatter:off
15921590 // Visible default methods are interface default methods that have not
15931591 // been overridden.
15941592 List <Method > visibleDefaultMethods = Arrays .stream (clazz .getMethods ())
1595- .filter (predicate . and ( Method ::isDefault ) )
1593+ .filter (Method ::isDefault )
15961594 .collect (toCollection (ArrayList ::new ));
15971595 if (visibleDefaultMethods .isEmpty ()) {
15981596 return visibleDefaultMethods ;
15991597 }
16001598 return Arrays .stream (clazz .getInterfaces ())
1601- .map (ifc -> getMethods ( ifc , predicate ) )
1599+ .map (ReflectionUtils :: getMethods )
16021600 .flatMap (List ::stream )
16031601 .filter (visibleDefaultMethods ::contains )
16041602 .collect (toCollection (ArrayList ::new ));
@@ -1614,10 +1612,9 @@ private static List<Field> toSortedMutableList(Field[] fields) {
16141612 // @formatter:on
16151613 }
16161614
1617- private static List <Method > toSortedMutableList (Method [] methods , Predicate < Method > predicate ) {
1615+ private static List <Method > toSortedMutableList (Method [] methods ) {
16181616 // @formatter:off
16191617 return Arrays .stream (methods )
1620- .filter (predicate )
16211618 .sorted (ReflectionUtils ::defaultMethodSorter )
16221619 // Use toCollection() instead of toList() to ensure list is mutable.
16231620 .collect (toCollection (ArrayList ::new ));
@@ -1656,8 +1653,8 @@ private static List<Method> getInterfaceMethods(Class<?> clazz, Predicate<Method
16561653 for (Class <?> ifc : clazz .getInterfaces ()) {
16571654
16581655 // @formatter:off
1659- List <Method > localInterfaceMethods = getMethods (ifc , predicate ).stream ()
1660- .filter (method -> !isAbstract (method ))
1656+ List <Method > localInterfaceMethods = getMethods (ifc ).stream ()
1657+ .filter (predicate . and ( method -> !isAbstract (method ) ))
16611658 .collect (toList ());
16621659
16631660 List <Method > superinterfaceMethods = getInterfaceMethods (ifc , predicate , traversalMode ).stream ()
0 commit comments