Java Code Examples for java.lang.reflect.Method#equals()
The following examples show how to use
java.lang.reflect.Method#equals() .
These examples are extracted from open source projects.
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 Project: JDKSourceCode1.8 File: MBeanInfo.java License: 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 2
Source Project: openjdk-jdk8u File: MBeanInfo.java License: 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 Project: jpa-unit File: EntityManagerProducerProxy.java License: 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 4
Source Project: jdk8u-jdk File: MBeanInfo.java License: 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 5
Source Project: jdk8u60 File: MBeanInfo.java License: 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 Project: caffeine File: LocalAsyncLoadingCache.java License: 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 7
Source Project: jdk8u_jdk File: Test4634390.java License: 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 8
Source Project: openjdk-8-source File: PropertyDescriptor.java License: 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 9
Source Project: Zebra File: ZebraRoutingPointcut.java License: 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 10
Source Project: stategen File: JavaMethod.java License: 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 11
Source Project: javaee-lab File: JpaUtil.java License: 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 12
Source Project: openjdk-8-source File: TestProvider.java License: 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 13
Source Project: jdk8u60 File: Class.java License: 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 Project: jdk8u_jdk File: Class.java License: 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 15
Source Project: Carbonado File: TriggerManager.java License: 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 16
Source Project: yawp File: EndpointTree.java License: 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 17
Source Project: spring4-understanding File: ExceptionHandlerMethodResolver.java License: 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 18
Source Project: jdk-1.7-annotated File: PropertyDescriptor.java License: 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 19
Source Project: java-technology-stack File: GenericTypeAwarePropertyDescriptor.java License: 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 Project: dolphin File: BridgeMethodResolver.java License: 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); }