/** * Returns a predicate that matches a method with the given name, and parameters that * {@link org.apache.brooklyn.util.core.flags.TypeCoercions#tryCoerce(Object, com.google.common.reflect.TypeToken)} can process * from the given list of arguments. * * @param methodName name of the method * @param arguments arguments that is intended to be given * @return a predicate that will match a compatible method */ public static Predicate<Method> matchMultiParameterMethod(final String methodName, final List<?> arguments) { return Predicates.and(matchMethodByName(methodName), matchMultiParameterMethod(arguments)); }
@Test public void testMatchMultiParameterMethod() throws Exception { Predicate<Method> predicate = MethodCoercions.matchMultiParameterMethod("multiParameterMethod", ImmutableList.of("true", "42")); assertFalse(predicate.apply(singleParameterMethod)); assertTrue(predicate.apply(multiParameterMethod)); assertFalse(predicate.apply(singleCollectionParameterMethod)); }
@Test public void testMatchMultiParameterMethodWithoutName() throws Exception { Predicate<Method> predicate = MethodCoercions.matchMultiParameterMethod(ImmutableList.of("true", "42")); assertFalse(predicate.apply(singleParameterMethod)); assertTrue(predicate.apply(multiParameterMethod)); assertFalse(predicate.apply(singleCollectionParameterMethod)); }
Optional<Method> matchingMethod = Iterables.tryFind(methods, matchMultiParameterMethod(arguments)); if (matchingMethod.isPresent()) { Method method = matchingMethod.get();