java.lang.reflect.Method#equals ( )源码实例Demo

下面列出了java.lang.reflect.Method#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JDKSourceCode1.8   文件: MBeanInfo.java
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
源代码2 项目: openjdk-jdk8u   文件: MBeanInfo.java
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
源代码3 项目: jpa-unit   文件: EntityManagerProducerProxy.java
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    if (method.equals(Disposable.class.getDeclaredMethods()[0])) {
        if (delegateUsed && instance != null) {
            proxied.dispose(instance);
            instance = null;
            delegateUsed = false;
        }
        return null;
    }

    final EntityManager oldInstance = instance;
    instance = EntityManagerHolder.INSTANCE.getEntityManager();

    if (instance == null && oldInstance == null) {
        instance = proxied.produce(ctx);
        delegateUsed = true;
    } else if (instance == null) {
        instance = oldInstance;
    }

    return method.invoke(instance, args);
}
 
源代码4 项目: jdk8u-jdk   文件: MBeanInfo.java
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
源代码5 项目: jdk8u60   文件: MBeanInfo.java
public Boolean run() {
    Method[] methods = immutableClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String methodName = method.getName();
        if (methodName.startsWith("get") &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType().isArray()) {
            try {
                Method submethod =
                    subclass.getMethod(methodName);
                if (!submethod.equals(method))
                    return false;
            } catch (NoSuchMethodException e) {
                return false;
            }
        }
    }
    return true;
}
 
源代码6 项目: caffeine   文件: LocalAsyncLoadingCache.java
/** Returns whether the supplied cache loader has bulk load functionality. */
private static boolean canBulkLoad(AsyncCacheLoader<?, ?> loader) {
  try {
    Class<?> defaultLoaderClass = AsyncCacheLoader.class;
    if (loader instanceof CacheLoader<?, ?>) {
      defaultLoaderClass = CacheLoader.class;

      Method classLoadAll = loader.getClass().getMethod("loadAll", Iterable.class);
      Method defaultLoadAll = CacheLoader.class.getMethod("loadAll", Iterable.class);
      if (!classLoadAll.equals(defaultLoadAll)) {
        return true;
      }
    }

    Method classAsyncLoadAll = loader.getClass().getMethod(
        "asyncLoadAll", Iterable.class, Executor.class);
    Method defaultAsyncLoadAll = defaultLoaderClass.getMethod(
        "asyncLoadAll", Iterable.class, Executor.class);
    return !classAsyncLoadAll.equals(defaultAsyncLoadAll);
  } catch (NoSuchMethodException | SecurityException e) {
    logger.log(Level.WARNING, "Cannot determine if CacheLoader can bulk load", e);
    return false;
  }
}
 
源代码7 项目: jdk8u_jdk   文件: Test4634390.java
private static boolean compare(Method m1, Method m2) {
    if ((m1 == null) && (m2 == null)) {
        return true;
    }
    if ((m1 == null) || (m2 == null)) {
        return false;
    }
    return m1.equals(m2);
}
 
源代码8 项目: openjdk-8-source   文件: PropertyDescriptor.java
/**
 * Package private helper method for Descriptor .equals methods.
 *
 * @param a first method to compare
 * @param b second method to compare
 * @return boolean to indicate that the methods are equivalent
 */
boolean compareMethods(Method a, Method b) {
    // Note: perhaps this should be a protected method in FeatureDescriptor
    if ((a == null) != (b == null)) {
        return false;
    }

    if (a != null && b != null) {
        if (!a.equals(b)) {
            return false;
        }
    }
    return true;
}
 
源代码9 项目: Zebra   文件: ZebraRoutingPointcut.java
boolean match(Method method, Class<?> targetClass) {
	// origin
	if (doMatch(method, targetClass)) {
		return true;
	}
	// cglib
	Class<?> userClass = ClassUtils.getUserClass(targetClass);
	Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass);
	specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
	if (!specificMethod.equals(method)) {
		if (doMatch(specificMethod, userClass)) {
			return true;
		}
	}
	// jdk proxy
	if (Proxy.isProxyClass(targetClass)) {
		Class<?>[] interfaces = targetClass.getInterfaces();
		for (Class<?> interfaceClass : interfaces) {
			Method interfaceMethod = ClassUtils.getMethodIfAvailable(interfaceClass, method.getName(),
			      method.getParameterTypes());
			if (interfaceMethod != null && doMatch(interfaceMethod, interfaceClass)) {
				return true;
			}
		}
	}
	return false;
}
 
源代码10 项目: stategen   文件: JavaMethod.java
private boolean declaredMethodsContains() {
      for(Method m : clazz.getClazz().getDeclaredMethods()) {
    if(m.equals(method.method)) {
        return true;
    }
}
      return false;
  }
 
源代码11 项目: javaee-lab   文件: JpaUtil.java
public String methodToProperty(Method m) {
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(m.getDeclaringClass());
    for (PropertyDescriptor pd : pds) {
        if (m.equals(pd.getReadMethod()) || m.equals(pd.getWriteMethod())) {
            return pd.getName();
        }
    }
    return null;
}
 
源代码12 项目: openjdk-8-source   文件: TestProvider.java
private static void verifyOneInvocation(Method method, Object[] args,
                                        List invocationQueue)
{
    TestProvider.Invocation inv =
        (TestProvider.Invocation) invocationQueue.remove(0);

    if (!method.equals(inv.method)) {
        throw new RuntimeException(
            "unexpected provider method invoked: expected " + method +
            ", detected " + inv.method);
    }

    List expectedArgs = Arrays.asList(args);
    List detectedArgs = Arrays.asList(inv.args);
    if (!expectedArgs.equals(detectedArgs)) {
        throw new RuntimeException("TEST FAILED: " +
            "unexpected provider method invocation arguments: " +
            "expected " + expectedArgs + ", detected " + detectedArgs);
    }

    if (!invocationQueue.isEmpty()) {
        inv = (TestProvider.Invocation)
            invocationQueue.remove(0);
        throw new RuntimeException("TEST FAILED: " +
            "unexpected provider invocation: " + inv.method + " " +
            Arrays.asList(inv.args));
    }
}
 
源代码13 项目: jdk8u60   文件: Class.java
void addIfNotPresent(Method newMethod) {
    for (int i = 0; i < length; i++) {
        Method m = methods[i];
        if (m == newMethod || (m != null && m.equals(newMethod))) {
            return;
        }
    }
    add(newMethod);
}
 
源代码14 项目: jdk8u_jdk   文件: Class.java
void addIfNotPresent(Method newMethod) {
    for (int i = 0; i < length; i++) {
        Method m = methods[i];
        if (m == newMethod || (m != null && m.equals(newMethod))) {
            return;
        }
    }
    add(newMethod);
}
 
源代码15 项目: Carbonado   文件: TriggerManager.java
private static boolean overridesMethod(Class<? extends Trigger> triggerClass, Method method) {
    try {
        return !method.equals(triggerClass.getMethod(method.getName(),
                                                     method.getParameterTypes()));
    } catch (NoSuchMethodException e) {
        return false;
    }
}
 
源代码16 项目: yawp   文件: EndpointTree.java
private void assertActionNotDuplicated(Map<ActionKey, ActionMethod> map, ActionKey actionKey, Method method) {
    if (map.get(actionKey) != null) {
        Method existingMethod = map.get(actionKey).getMethod();

        if (method.equals(existingMethod)) {
            return;
        }

        throw new RuntimeException("Trying to add two actions with the same name '" + actionKey + "' to "
                + endpointClazz.getName() + ": one at " + existingMethod.getDeclaringClass().getName() + " and the other at "
                + method.getDeclaringClass().getName());
    }
}
 
private void addExceptionMapping(Class<? extends Throwable> exceptionType, Method method) {
	Method oldMethod = this.mappedMethods.put(exceptionType, method);
	if (oldMethod != null && !oldMethod.equals(method)) {
		throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" +
				exceptionType + "]: {" + oldMethod + ", " + method + "}");
	}
}
 
源代码18 项目: jdk-1.7-annotated   文件: PropertyDescriptor.java
/**
 * Package private helper method for Descriptor .equals methods.
 *
 * @param a first method to compare
 * @param b second method to compare
 * @return boolean to indicate that the methods are equivalent
 */
boolean compareMethods(Method a, Method b) {
    // Note: perhaps this should be a protected method in FeatureDescriptor
    if ((a == null) != (b == null)) {
        return false;
    }

    if (a != null && b != null) {
        if (!a.equals(b)) {
            return false;
        }
    }
    return true;
}
 
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
		@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
		throws IntrospectionException {

	super(propertyName, null, null);
	this.beanClass = beanClass;

	Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
	Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
	if (writeMethodToUse == null && readMethodToUse != null) {
		// Fallback: Original JavaBeans introspection might not have found matching setter
		// method due to lack of bridge method resolution, in case of the getter using a
		// covariant return type whereas the setter is defined for the concrete property type.
		Method candidate = ClassUtils.getMethodIfAvailable(
				this.beanClass, "set" + StringUtils.capitalize(getName()), (Class<?>[]) null);
		if (candidate != null && candidate.getParameterCount() == 1) {
			writeMethodToUse = candidate;
		}
	}
	this.readMethod = readMethodToUse;
	this.writeMethod = writeMethodToUse;

	if (this.writeMethod != null) {
		if (this.readMethod == null) {
			// Write method not matched against read method: potentially ambiguous through
			// several overloaded variants, in which case an arbitrary winner has been chosen
			// by the JDK's JavaBeans Introspector...
			Set<Method> ambiguousCandidates = new HashSet<>();
			for (Method method : beanClass.getMethods()) {
				if (method.getName().equals(writeMethodToUse.getName()) &&
						!method.equals(writeMethodToUse) && !method.isBridge() &&
						method.getParameterCount() == writeMethodToUse.getParameterCount()) {
					ambiguousCandidates.add(method);
				}
			}
			if (!ambiguousCandidates.isEmpty()) {
				this.ambiguousWriteMethods = ambiguousCandidates;
			}
		}
		this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
		GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
	}

	if (this.readMethod != null) {
		this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
	}
	else if (this.writeMethodParameter != null) {
		this.propertyType = this.writeMethodParameter.getParameterType();
	}

	this.propertyEditorClass = propertyEditorClass;
}
 
源代码20 项目: dolphin   文件: BridgeMethodResolver.java
/**
 * Returns {@code true} if the supplied '{@code candidateMethod}' can be
 * consider a validate candidate for the {@link Method} that is {@link Method#isBridge() bridged}
 * by the supplied {@link Method bridge Method}. This method performs inexpensive
 * checks and can be used quickly filter for a set of possible matches.
 */
private static boolean isBridgedCandidateFor(Method candidateMethod, Method bridgeMethod) {
	return (!candidateMethod.isBridge() && !candidateMethod.equals(bridgeMethod) &&
			candidateMethod.getName().equals(bridgeMethod.getName()) &&
			candidateMethod.getParameterTypes().length == bridgeMethod.getParameterTypes().length);
}