本文整理匯總了Java中java.lang.reflect.Method.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Method.equals方法的具體用法?Java Method.equals怎麽用?Java Method.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Method
的用法示例。
在下文中一共展示了Method.equals方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import java.lang.reflect.Method; //導入方法依賴的package包/類
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: invoke
import java.lang.reflect.Method; //導入方法依賴的package包/類
public Object invoke(
final Object proxy, final Method method, final Object[] args) throws Throwable {
if (method.equals(CLOSE_METHOD)) {
close();
return null;
} else {
try {
return method.invoke(this.original, args);
} catch (final InvocationTargetException ex) {
final Throwable cause = ex.getCause();
if (cause != null) {
throw cause;
} else {
throw ex;
}
}
}
}
示例3: hasObjectMethod
import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
* This Method checks if an instance of an object has an asked method.
*
* @param ontologyObject the ontology object
* @param methode2check the methode2check
* @return true, if the method is available
*/
private boolean hasObjectMethod(Object ontologyObject, Method methode2check) {
if (ontologyObject==null) return false;
Method[] meths = ontologyObject.getClass().getMethods();
for (int i = 0; i < meths.length; i++) {
Method meth = meths[i];
if (meth.equals(methode2check)) {
return true;
}
}
return false;
}
示例4: matchInheritance
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static boolean matchInheritance(final Method subclassMethod, final Method superclassMethod) {
if (Modifier.isStatic(superclassMethod.getModifiers()) || subclassMethod.equals(superclassMethod)) {
return false;
}
if (matchSignature(subclassMethod, superclassMethod)) {
final Package subclassPackage = subclassMethod.getDeclaringClass().getPackage();
final Package superclassPackage = superclassMethod.getDeclaringClass().getPackage();
final int superMethodModifiers = superclassMethod.getModifiers();
return isAccessable(subclassPackage, superclassPackage, superMethodModifiers);
} else {
return false;
}
}
示例5: main
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
System.setSecurityManager(new SecurityManager());
Derived bean = new Derived();
Class<?> type = bean.getClass();
Method method1 = test("reflection", bean, type.getMethod("isAllowed"));
Method method2 = test("bean introspection", bean, BeanUtils.getPropertyDescriptor(type, "allowed").getReadMethod());
if (!method1.equals(method2)) {
throw new Error("first method is not equal to the second one");
}
}
示例6: compare
import java.lang.reflect.Method; //導入方法依賴的package包/類
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);
}
示例7: GenericTypeAwarePropertyDescriptor
import java.lang.reflect.Method; //導入方法依賴的package包/類
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
throws IntrospectionException {
super(propertyName, null, null);
this.beanClass = beanClass;
this.propertyEditorClass = propertyEditorClass;
Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
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.getParameterTypes().length == 1) {
writeMethodToUse = candidate;
}
}
this.readMethod = readMethodToUse;
this.writeMethod = writeMethodToUse;
if (this.writeMethod != null && 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<Method>();
for (Method method : beanClass.getMethods()) {
if (method.getName().equals(writeMethodToUse.getName()) &&
!method.equals(writeMethodToUse) && !method.isBridge()) {
ambiguousCandidates.add(method);
}
}
if (!ambiguousCandidates.isEmpty()) {
this.ambiguousWriteMethods = ambiguousCandidates;
}
}
}
示例8: compareMethods
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static boolean compareMethods(Method a, Method b) {
if ((a == null) != (b == null)) {
return false;
}
if (a != null) {
if (!a.equals(b)) {
return false;
}
}
return true;
}
示例9: findPropertyForMethod
import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
* Find a JavaBeans {@code PropertyDescriptor} for the given method,
* with the method either being the read method or the write method for
* that bean property.
* @param method the method to find a corresponding PropertyDescriptor for
* @return the corresponding PropertyDescriptor, or {@code null} if none
* @throws BeansException if PropertyDescriptor lookup fails
*/
public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException {
Assert.notNull(method, "Method must not be null");
PropertyDescriptor[] pds = getPropertyDescriptors(method.getDeclaringClass());
for (PropertyDescriptor pd : pds) {
if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) {
return pd;
}
}
return null;
}
示例10: testMultipleGivenRegex
import java.lang.reflect.Method; //導入方法依賴的package包/類
@Test
public void testMultipleGivenRegex() throws NoSuchMethodException {
MultipleGivenBean source = new MultipleGivenBean();
ClassPathXmlApplicationContext context = getContext(source);
process(context, source);
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");
}
示例11: invoke
import java.lang.reflect.Method; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked"})
public Object invoke(Object proxy, Method method, Object[] args) {
if (method.equals(this.completeMethod)) {
int result = complete((String)args[0], ((Integer) args[1]).intValue(),
(List<String>) args[2]);
return Integer.valueOf(result);
}
throw new NoSuchMethodError(method.toString());
}
示例12: findMethod
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static Method findMethod(Class<? extends Snippets> declaringClass, String methodName, Method except) {
for (Method m : declaringClass.getDeclaredMethods()) {
if (m.getName().equals(methodName) && !m.equals(except)) {
return m;
}
}
return null;
}
示例13: addIfNotPresent
import java.lang.reflect.Method; //導入方法依賴的package包/類
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: verifyOneInvocation
import java.lang.reflect.Method; //導入方法依賴的package包/類
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));
}
}
示例15: newResultSet
import java.lang.reflect.Method; //導入方法依賴的package包/類
public static ResultSet newResultSet(final Object... defs) throws NoSuchMethodException, SecurityException {
if (defs.length % 2 != 0) {
throw new IllegalArgumentException();
}
Method wasNull = ResultSet.class.getMethod("wasNull");
Map<Method, Object> values = new HashMap<>();
for (int i = 0; i < defs.length; i += 2) {
Method target = defs[i].equals("wasNull") ? wasNull : ResultSet.class.getMethod(defs[i].toString(), int.class);
values.put(target, defs[i + 1]);
}
AtomicBoolean flg = new AtomicBoolean(false);
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (values.containsKey(method)) {
Object o = values.get(method);
flg.set(o == null);
return o;
}
if (wasNull.equals(method)) {
return flg.get();
}
return null;
}
};
return (ResultSet) Proxy.newProxyInstance(Helper.class.getClassLoader(), new Class[] { ResultSet.class }, handler);
}