Java Code Examples for java.lang.reflect.Method#equals()
The following examples show how to use
java.lang.reflect.Method#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalAsyncLoadingCache.java From caffeine with Apache License 2.0 | 6 votes |
/** 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; } }
Example 2
Source File: MBeanInfo.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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; }
Example 3
Source File: MBeanInfo.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example 4
Source File: MBeanInfo.java From JDKSourceCode1.8 with MIT License | 6 votes |
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; }
Example 5
Source File: MBeanInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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; }
Example 6
Source File: EntityManagerProducerProxy.java From jpa-unit with Apache License 2.0 | 6 votes |
@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); }
Example 7
Source File: PropertyDescriptor.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 8
Source File: PropertyDescriptor.java From jdk-1.7-annotated with Apache License 2.0 | 5 votes |
/** * 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; }
Example 9
Source File: ExceptionHandlerMethodResolver.java From spring4-understanding with Apache License 2.0 | 5 votes |
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 + "}"); } }
Example 10
Source File: EndpointTree.java From yawp with MIT License | 5 votes |
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()); } }
Example 11
Source File: TriggerManager.java From Carbonado with Apache License 2.0 | 5 votes |
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; } }
Example 12
Source File: Class.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example 13
Source File: Class.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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); }
Example 14
Source File: TestProvider.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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)); } }
Example 15
Source File: JpaUtil.java From javaee-lab with Apache License 2.0 | 5 votes |
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; }
Example 16
Source File: JavaMethod.java From stategen with GNU Affero General Public License v3.0 | 5 votes |
private boolean declaredMethodsContains() { for(Method m : clazz.getClazz().getDeclaredMethods()) { if(m.equals(method.method)) { return true; } } return false; }
Example 17
Source File: ZebraRoutingPointcut.java From Zebra with Apache License 2.0 | 5 votes |
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; }
Example 18
Source File: Test4634390.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example 19
Source File: GenericTypeAwarePropertyDescriptor.java From java-technology-stack with MIT License | 4 votes |
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; }
Example 20
Source File: BridgeMethodResolver.java From dolphin with Apache License 2.0 | 2 votes |
/** * 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); }