what-the-bank/sources/o/NIm.java

137 lines
4.7 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package o;
import com.google.common.base.Ascii;
import com.google.common.base.Preconditions;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Map;
import java.util.WeakHashMap;
/* loaded from: classes2.dex */
public final class NIm {
private static final Map<Field, NIm> e = new WeakHashMap();
public final Field a;
public final String b;
private final Method[] c;
final boolean d;
public static NIm e(Enum<?> r3) {
try {
NIm b = b(r3.getClass().getField(r3.name()));
Preconditions.checkArgument(b != null, "enum constant missing @Value or @NullValue annotation: %s", r3);
return b;
} catch (NoSuchFieldException e2) {
throw new RuntimeException(e2);
}
}
public static NIm b(Field field) {
String str = null;
if (field == null) {
return null;
}
Map<Field, NIm> map = e;
synchronized (map) {
NIm nIm = map.get(field);
boolean isEnumConstant = field.isEnumConstant();
if (nIm == null && (isEnumConstant || !Modifier.isStatic(field.getModifiers()))) {
if (isEnumConstant) {
EOP eop = (EOP) field.getAnnotation(EOP.class);
if (eop != null) {
str = eop.b();
} else if (((Hgd) field.getAnnotation(Hgd.class)) == null) {
return null;
}
} else {
InterfaceC16620pkx interfaceC16620pkx = (InterfaceC16620pkx) field.getAnnotation(InterfaceC16620pkx.class);
if (interfaceC16620pkx == null) {
return null;
}
str = interfaceC16620pkx.e();
field.setAccessible(true);
}
if ("##default".equals(str)) {
str = field.getName();
}
nIm = new NIm(field, str);
map.put(field, nIm);
}
return nIm;
}
}
private NIm(Field field, String str) {
this.a = field;
this.b = str == null ? null : str.intern();
this.d = C1169XbG.c((Type) field.getType());
ArrayList arrayList = new ArrayList();
for (Method method : field.getDeclaringClass().getDeclaredMethods()) {
String lowerCase = Ascii.toLowerCase(method.getName());
StringBuilder sb = new StringBuilder("set");
sb.append(Ascii.toLowerCase(field.getName()));
if (lowerCase.equals(sb.toString()) && method.getParameterTypes().length == 1) {
arrayList.add(method);
}
}
this.c = (Method[]) arrayList.toArray(new Method[0]);
}
public final void c(Object obj, Object obj2) {
Method[] methodArr = this.c;
if (methodArr.length > 0) {
for (Method method : methodArr) {
if (obj2 == null || method.getParameterTypes()[0].isAssignableFrom(obj2.getClass())) {
try {
method.invoke(obj, obj2);
return;
} catch (IllegalAccessException | InvocationTargetException unused) {
continue;
}
}
}
}
a(this.a, obj, obj2);
}
public static Object d(Field field, Object obj) {
try {
return field.get(obj);
} catch (IllegalAccessException e2) {
throw new IllegalArgumentException(e2);
}
}
private static void a(Field field, Object obj, Object obj2) {
if (Modifier.isFinal(field.getModifiers())) {
Object d = d(field, obj);
if (obj2 == null) {
if (d == null) {
return;
}
} else if (obj2.equals(d)) {
return;
}
StringBuilder sb = new StringBuilder("expected final value <");
sb.append(d);
sb.append("> but was <");
sb.append(obj2);
sb.append("> on ");
sb.append(field.getName());
sb.append(" field in ");
sb.append(obj.getClass().getName());
throw new IllegalArgumentException(sb.toString());
}
try {
field.set(obj, obj2);
} catch (IllegalAccessException e2) {
throw new IllegalArgumentException(e2);
} catch (SecurityException e3) {
throw new IllegalArgumentException(e3);
}
}
}