MethodFinderUtils { public static Method findAnnotatedMethod( final Object pojo, final Class<? extends Annotation> annotationClass, final Map<Class<?>, Optional<Method>> methods) { val clz = pojo.getClass(); val annotatedMethodIfAny = methods.computeIfAbsent(clz, __->search(clz, annotationClass, methods)); return annotatedMethodIfAny.orElse(null); } private  MethodFinderUtils(); static Method findMethod(
            final Class<?> type,
            final String name,
            final Class<?> expectedReturnType,
            final Class<?>[] paramTypes); static Method findMethod_returningAnyOf(
            final Class<?>[] returnTypes,
            final Class<?> type,
            final String name,
            final Class<?>[] paramTypes); static Optional<Method> findNoArgMethod(final Class<?> type, final String name, final Class<?> returnType); static Optional<Method> findSingleArgMethod(final Class<?> type, final String name, final Class<?> returnType); static Stream<Method> streamMethods(final Class<?> type, final Can<String> names, final Class<?> returnType); static List<Method> findMethodsWithAnnotation(
            final Class<?> type, 
            final Class<? extends Annotation> annotationClass); static void removeMethod(final MethodRemover methodRemover, final Method method); static Class<?>[] paramTypesOrNull(final Class<?> type); static boolean allParametersOfSameType(final Class<?>[] params); static Method findAnnotatedMethod(
            final Object pojo,
            final Class<? extends Annotation> annotationClass,
            final Map<Class<?>, Optional<Method>> methods); static Method findMethod_returningBoolean(
            final Class<?> type,
            final String name,
            final Class<?>[] paramTypes); static Method findMethod_returningText(
            final Class<?> type,
            final String name,
            final Class<?>[] paramTypes); static Method findMethod_returningNonScalar(
            final Class<?> type,
            final String name, 
            final Class<?> elementReturnType,
            final Class<?>[] paramTypes); static MethodAndPpmConstructor findMethodWithPPMArg(
            final Class<?> type, 
            final String name, 
            final Class<?> returnType,
            final Class<?>[] paramTypes,
            final Can<Class<?>> additionalParamTypes); static MethodAndPpmConstructor findMethodWithPPMArg_returningAnyOf(
            final Class<?>[] returnTypes,
            final Class<?> type,
            final String name,
            final Class<?>[] paramTypes,
            final Can<Class<?>> additionalParamTypes); static MethodAndPpmConstructor findMethodWithPPMArg_returningBoolean(
            final Class<?> type, 
            final String name,
            final Class<?>[] paramTypes,
            final Can<Class<?>> additionalParamTypes); static MethodAndPpmConstructor findMethodWithPPMArg_returningText(
            final Class<?> type, 
            final String name,
            final Class<?>[] paramTypes,
            final Can<Class<?>> additionalParamTypes); static MethodAndPpmConstructor findMethodWithPPMArg_returningNonScalar(
            final Class<?> type, 
            final String name, 
            final Class<?> elementReturnType,
            final Class<?>[] paramTypes, 
            final Can<Class<?>> additionalParamTypes);  }
@Test public void whenExists() throws Exception { final Map<Class<?>, Optional<Method>> cache = _Maps.newHashMap(); final Method method = MethodFinderUtils.findAnnotatedMethod(new WithPostConstruct(), PostConstruct.class, cache); assertThat(method, is(not(nullValue()))); final Optional<Method> actual = cache.get(WithPostConstruct.class); assertThat(actual, is(not(nullValue()))); assertThat(actual.isPresent(), is(true)); assertThat(actual.orElse(null), is(method)); }
@Test public void whenDoesNotExist() throws Exception { final Map<Class<?>, Optional<Method>> cache = _Maps.newHashMap(); final Method method = MethodFinderUtils.findAnnotatedMethod(new NoPostConstruct(), PostConstruct.class, cache); assertThat(method, is(nullValue())); final Optional<Method> actual = cache.get(NoPostConstruct.class); assertThat(actual, is(not(nullValue()))); assertThat(actual.isPresent(), is(false)); assertThat(actual.orElse(null), is(nullValue())); }