class ReflectionUtils {

    public static List<Method> findMethods(Class<?> clazz, String nameRegex,
            ParamCount numberOfParams) {
        // Create the Pattern and Matcher outside the loop to optimize
        // performance (and possibly memory usage).
        Pattern p = Pattern.compile(nameRegex);
        Matcher m = p.matcher("");

        List<Method> methods = new ArrayList<Method>();
        for (Method method : clazz.getMethods()) {
            if (numberOfParams.matches(method.getParameterTypes().length)
                    && m.reset(method.getName()).matches()) {
                methods.add(method);
            }
        }
        return methods;
    }

}

class ReflectionUtilsTest {

    @Test
    public void test_findMethodsByConstantParamCount_constant3() {

        assertEquals(
                0,
                findMethods(SubClassToExamine.class, "setFooBar",
                        ParamCount.constant(3)).size());
    }

}