Example usage for java.lang.reflect Method equals

List of usage examples for java.lang.reflect Method equals

Introduction

In this page you can find the example usage for java.lang.reflect Method equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this Method against the specified object.

Usage

From source file:com.jsen.core.reflect.ClassFunction.java

/**
 * Tests whether is the passed method the object getter method.
 * /*from  w w  w.  ja  v a 2 s. c o m*/
 * @param clazz Class that should contain the object getter method.
 * @param method Method to be tested.
 * @return True if the passed method is object getter method.
 */
public static boolean isObjectGetterMethod(Class<?> clazz, Method method) {
    if (ObjectGetter.class.isAssignableFrom(clazz)) {
        Method getterMethod = ClassFunction.getObjectGetterMetod(clazz);
        return method.equals(getterMethod);
    }
    return false;
}

From source file:jenkins.plugins.git.MethodUtils.java

/**
 * Checks if the  method defined on the base type with the given arguments
 * are overridden in the given derived type.
 *///w w  w.j  a v  a 2 s . c o  m
// TODO replace with core utility method once JENKINS-30002 is available in base version of Jenkins
static boolean isOverridden(@Nonnull Class base, @Nonnull Class derived, @Nonnull String methodName,
        @Nonnull Class... types) {
    Method baseMethod = getMethodImpl(base, methodName, types);
    Method derivedMethod = getMethodImpl(derived, methodName, types);
    return baseMethod == null ? derivedMethod != null && !Modifier.isAbstract(derivedMethod.getModifiers())
            : !baseMethod.equals(derivedMethod);
}

From source file:com.haulmont.cuba.core.config.ConfigUtil.java

public static SourceType getSourceType(Class<?> configInterface, Method method) {
    Source source = method.getAnnotation(Source.class);
    if (source == null) {
        Method getMethod = getGetMethod(configInterface, method);
        if (getMethod != null && !method.equals(getMethod)) {
            source = getMethod.getAnnotation(Source.class);
        }//www  . j a  va2s.c  o  m
        if (source == null) {
            source = configInterface.getAnnotation(Source.class);
            if (source == null)
                return SourceType.DATABASE;
        }
    }
    return source.type();
}

From source file:com.espertech.esper.view.ViewProxy.java

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

    if (!m.equals(target)) {
        return m.invoke(view, args);
    }//from   www. j  av  a  2 s  . com

    Object result = m.invoke(view, args);
    if (AuditPath.isInfoEnabled()) {
        EventBean[] newData = (EventBean[]) args[0];
        EventBean[] oldData = (EventBean[]) args[1];
        AuditPath.auditLog(engineURI, statementName, AuditEnum.VIEW,
                viewName + " insert {" + EventBeanUtility.summarize(newData) + "} remove {"
                        + EventBeanUtility.summarize(oldData) + "}");
    }
    return result;
}

From source file:com.espertech.esper.epl.expression.ExprEvaluatorProxy.java

public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

    if (m.equals(targetEvaluate)) {
        Object result = m.invoke(evaluator, args);
        if (auditLog.isInfoEnabled()) {
            auditLog.info(//from ww w  . j  a v  a 2 s .  c o m
                    "Statement " + statementName + " expression " + expressionToString + " result " + result);
        }
        return result;
    }

    if (m.equals(targetEvaluateCollEvents)) {
        Object result = m.invoke(evaluator, args);
        if (auditLog.isInfoEnabled()) {
            Collection<EventBean> resultBeans = (Collection<EventBean>) result;
            String out = "null";
            if (resultBeans != null) {
                if (resultBeans.isEmpty()) {
                    out = "{}";
                } else {
                    StringWriter buf = new StringWriter();
                    int count = 0;
                    for (EventBean event : resultBeans) {
                        buf.append(" Event ");
                        buf.append(Integer.toString(count++));
                        buf.append(":");
                        EventBeanUtility.appendEvent(buf, event);
                    }
                    out = buf.toString();
                }
            }
            auditLog.info(
                    "Statement " + statementName + " expression " + expressionToString + " result " + out);
        }
        return result;
    }

    if (m.equals(targetEvaluateCollScalar)) {
        Object result = m.invoke(evaluator, args);
        if (auditLog.isInfoEnabled()) {
            auditLog.info(
                    "Statement " + statementName + " expression " + expressionToString + " result " + result);
        }
        return result;
    }

    if (m.equals(targetEvaluateBean)) {
        Object result = m.invoke(evaluator, args);
        if (auditLog.isInfoEnabled()) {
            String out = "null";
            if (result != null) {
                StringWriter buf = new StringWriter();
                EventBeanUtility.appendEvent(buf, (EventBean) result);
                out = buf.toString();
            }
            auditLog.info(
                    "Statement " + statementName + " expression " + expressionToString + " result " + out);
        }
        return result;
    }
    return m.invoke(evaluator, args);
}

From source file:guru.qas.martini.annotation.StepsAnnotationProcessorTest.java

@Test
public void testPostProcessAfterInitialization() throws IOException, NoSuchMethodException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    TestSteps steps = context.getBean(TestSteps.class);

    Class<?> wrapped = AopUtils.getTargetClass(steps);
    Method method = wrapped.getMethod("anotherStep", String.class);

    Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
    Collection<StepImplementation> givens = givenBeanIndex.values();

    List<StepImplementation> matches = Lists.newArrayList();
    for (StepImplementation given : givens) {
        Method givenMethod = given.getMethod();
        if (givenMethod.equals(method)) {
            matches.add(given);//from  w  w  w . jav a  2  s.  c o m
        }
    }

    int count = matches.size();
    assertEquals(count, 1, "wrong number of GivenStep objects registered for TestSteps.anotherStep()");

    StepImplementation match = matches.get(0);
    Pattern pattern = match.getPattern();
    Matcher matcher = pattern.matcher("another \"(.+)\" here");
    assertTrue(matcher.find(), "expected Pattern to match Gherkin regular expression");
    assertEquals(matcher.groupCount(), 1, "wrong number of parameters captured for TestSteps.anotherStep()");
}

From source file:guru.qas.martini.annotation.StepsAnnotationProcessorTest.java

@Test
public void testMultipleGivenRegex() throws NoSuchMethodException {
    MultipleGivenBean source = new MultipleGivenBean();
    ClassPathXmlApplicationContext context = getContext(source);
    process(context, source);//from  ww w.  j ava 2s . c o  m

    MultipleGivenBean steps = context.getBean(MultipleGivenBean.class);
    Class<?> wrapped = AopUtils.getTargetClass(steps);
    Method method = wrapped.getMethod("doSomething");

    Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
    Collection<StepImplementation> givens = givenBeanIndex.values();

    Set<String> matches = Sets.newHashSetWithExpectedSize(2);
    for (StepImplementation given : givens) {
        Method givenMethod = given.getMethod();
        if (givenMethod.equals(method)) {
            Pattern pattern = given.getPattern();
            String regex = pattern.pattern();
            matches.add(regex);
        }
    }

    int count = matches.size();
    assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()");

    Set<String> expected = Sets.newHashSet("this is regular expression one", "this is regular expression two");
    assertEquals(matches, expected, "Steps contain wrong regex Pattern objects");
}

From source file:gda.jython.accesscontrol.ProtectedMethodComponent.java

/**
 * @param method/*  www. j  a  va2  s  .  co m*/
 * @return true if the given method is one of the PyObject invoke methods
 */
public boolean isAnInvokeMethod(Method method) {
    return method.equals(jythonInvoke) || method.equals(jythonInvoke1) || method.equals(jythonInvoke2)
            || method.equals(jythonInvoke3) || method.equals(jythonInvoke4);
}

From source file:savetheenvironment.refresh.RefreshableFactoryBean.java

@Override
@SuppressWarnings("unchecked")
public T getObject() throws Exception {

    if (null == this.atomicReference.get()) {
        updateBeanReference();//from  www.j  a va 2 s  . c om
    }

    T beanReference = atomicReference.get();

    ProxyFactory pf = new ProxyFactory(beanReference);
    pf.setProxyTargetClass(true);
    List<Class<?>> listOfClasses = new ArrayList<Class<?>>();
    listOfClasses.add(Refreshable.class);
    listOfClasses.add(ApplicationListener.class);
    listOfClasses.add(DisposableBean.class);
    listOfClasses.addAll(Arrays.asList(beanReference.getClass().getInterfaces()));
    pf.setInterfaces(listOfClasses.toArray(new Class[listOfClasses.size()]));
    pf.addAdvice(new MethodInterceptor() {

        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            Method method = invocation.getMethod();
            // if someone externally calls refresh, then rebuild the reference
            if (method.equals(refreshMethod)) {
                updateBeanReference();
                return atomicReference.get();
            } else if (method.equals(disposeMethod)) {
                T atomicT = atomicReference.get();
                if (atomicT instanceof DisposableBean) {
                    ((DisposableBean) atomicT).destroy();
                }
            } else if (method.equals(onApplicationEventMethod)) {
                Object[] arguments = invocation.getArguments();
                if (arguments[0] instanceof RefreshEvent) {
                    updateBeanReference();
                }
                return null;
            }
            // otherwise send the request on through to the underlying object unchanged
            Object ref = atomicReference.get();
            return method.invoke(ref, invocation.getArguments());

        }
    });
    Object o = pf.getProxy();
    return (T) o;
}

From source file:com.bstek.dorado.util.proxy.MethodInterceptorDispatcher.java

public Object invoke(Object object, Method method, Method procssed, Object[] args) throws Throwable {
    if (method.equals(EQUALS_METHOD)) {
        Object proxyTarget = ProxyBeanUtils.getProxyTarget(args[0]);
        if (proxyTarget == object)
            return Boolean.TRUE;
        args = new Object[] { proxyTarget };
    } else if (object instanceof Serializable && method.getName().equals(WRITE_REPLACE)
            && method.getReturnType().equals(Object.class)) {
        try {/*from w  w w.  jav  a  2s  . c  om*/
            Class<?> realClass = ProxyBeanUtils.getProxyTargetType(object);
            realClass.getMethod(WRITE_REPLACE, new Class<?>[0]);
        } catch (NoSuchMethodException e) {
            return getObjectForSerialization(object);
        }
    }

    if (subMethodInterceptors != null && filterMethod(method)) {
        MethodInterceptorChain methodInterceptorChain = new MethodInterceptorChain(subMethodInterceptors,
                createJavassistFinalMethodInterceptor(method, procssed),
                getMethodInterceptorFilter(object, method, args));

        MethodInvocation mockMethodInvocation = createMethodInvocation(object, method, args,
                methodInterceptorChain);
        MethodInterceptor methodInterceptor = methodInterceptorChain.next(mockMethodInvocation);
        return methodInterceptor.invoke(mockMethodInvocation);
    } else {
        return procssed.invoke(object, args);
    }
}