/** * Creates a Predicate that invokes a method on the input object. * The method must return either a boolean or a non-null Boolean, * and have no parameters. If the input object is null, a * PredicateException is thrown. * <p> * For example, <code>PredicateUtils.invokerPredicate("isEmpty");</code> * will call the <code>isEmpty</code> method on the input object to * determine the predicate result. * * @param <T> the type that the predicate queries * @param methodName the method name to call on the input object, may not be null * @return the predicate * @throws NullPointerException if the methodName is null. * @see InvokerTransformer * @see TransformerPredicate */ public static <T> Predicate<T> invokerPredicate(final String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asPredicate(InvokerTransformer.<Object, Boolean>invokerTransformer(methodName)); }
/** * Creates a Predicate that invokes a method on the input object. * The method must return either a boolean or a non-null Boolean, * and have no parameters. If the input object is null, a * PredicateException is thrown. * <p> * For example, <code>PredicateUtils.invokerPredicate("isEmpty");</code> * will call the <code>isEmpty</code> method on the input object to * determine the predicate result. * * @param <T> the type that the predicate queries * @param methodName the method name to call on the input object, may not be null * @param paramTypes the parameter types * @param args the arguments * @return the predicate * @throws NullPointerException if the method name is null * @throws IllegalArgumentException if the paramTypes and args don't match * @see InvokerTransformer * @see TransformerPredicate */ public static <T> Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes, final Object[] args) { // reuse transformer as it has caching - this is lazy really, should have inner class here return asPredicate(InvokerTransformer.<Object, Boolean>invokerTransformer(methodName, paramTypes, args)); }