what-the-bank/sources/com/google/common/reflect/AbstractInvocationHandler.java

54 lines
1.8 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.reflect;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
/* loaded from: classes2.dex */
public abstract class AbstractInvocationHandler implements InvocationHandler {
private static final Object[] NO_ARGS = new Object[0];
protected abstract Object handleInvocation(Object obj, Method method, Object[] objArr) throws Throwable;
@Override // java.lang.reflect.InvocationHandler
public final Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
if (objArr == null) {
objArr = NO_ARGS;
}
if (objArr.length == 0 && method.getName().equals("hashCode")) {
return Integer.valueOf(hashCode());
}
if (objArr.length == 1 && method.getName().equals("equals") && method.getParameterTypes()[0] == Object.class) {
Object obj2 = objArr[0];
if (obj2 == null) {
return Boolean.FALSE;
}
if (obj == obj2) {
return Boolean.TRUE;
}
return Boolean.valueOf(isProxyOfSameInterfaces(obj2, obj.getClass()) && equals(Proxy.getInvocationHandler(obj2)));
}
if (objArr.length == 0 && method.getName().equals("toString")) {
return toString();
}
return handleInvocation(obj, method, objArr);
}
public boolean equals(Object obj) {
return super.equals(obj);
}
public int hashCode() {
return super.hashCode();
}
public String toString() {
return super.toString();
}
private static boolean isProxyOfSameInterfaces(Object obj, Class<?> cls) {
return cls.isInstance(obj) || (Proxy.isProxyClass(obj.getClass()) && Arrays.equals(obj.getClass().getInterfaces(), cls.getInterfaces()));
}
}