package h;

import d.C0424d;
import g.C0474a;
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.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import l.C0611c;

/* JADX INFO: loaded from: classes.dex */
public abstract class l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final C0611c f4139a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    protected final Class f4140b;

    public l(Class cls, C0611c c0611c) {
        this.f4140b = cls;
        this.f4139a = c0611c;
    }

    private static void a(Field field, Method method, Object obj, Object obj2) throws IllegalAccessException, InvocationTargetException {
        if (d(field, obj, obj2)) {
            return;
        }
        obj.getClass().getDeclaredMethod("set" + method.getName().substring(3), method.getReturnType()).invoke(obj, obj2);
    }

    private static boolean d(Field field, Object obj, Object obj2) throws IllegalAccessException {
        if (field == null || Modifier.isFinal(field.getModifiers())) {
            return false;
        }
        field.set(obj, obj2);
        return true;
    }

    public int b() {
        return 0;
    }

    public abstract void c(C0474a c0474a, Object obj, Type type, Map map);

    public void e(Object obj, int i2) {
        g(obj, Integer.valueOf(i2));
    }

    public void f(Object obj, long j2) {
        g(obj, Long.valueOf(j2));
    }

    public void g(Object obj, Object obj2) {
        C0611c c0611c;
        Method method;
        String str;
        if (obj2 == null && this.f4139a.f5264y.isPrimitive()) {
            return;
        }
        C0611c c0611c2 = this.f4139a;
        if (c0611c2.f5264y == String.class && (str = c0611c2.f5259i0) != null && str.equals("trim")) {
            obj2 = ((String) obj2).trim();
        }
        try {
            c0611c = this.f4139a;
            method = c0611c.f5256g;
        } catch (Exception e2) {
            throw new C0424d("set property error, " + this.f4140b.getName() + "#" + this.f4139a.f5250b, e2);
        }
        if (method == null) {
            Field field = c0611c.f5262r;
            if (!c0611c.f5245L) {
                if (field != null) {
                    field.set(obj, obj2);
                    return;
                }
                return;
            }
            Class cls = c0611c.f5264y;
            if (cls == AtomicInteger.class) {
                AtomicInteger atomicInteger = (AtomicInteger) field.get(obj);
                if (atomicInteger != null) {
                    atomicInteger.set(((AtomicInteger) obj2).get());
                    return;
                }
                return;
            }
            if (cls == AtomicLong.class) {
                AtomicLong atomicLong = (AtomicLong) field.get(obj);
                if (atomicLong != null) {
                    atomicLong.set(((AtomicLong) obj2).get());
                    return;
                }
                return;
            }
            if (cls == AtomicBoolean.class) {
                AtomicBoolean atomicBoolean = (AtomicBoolean) field.get(obj);
                if (atomicBoolean != null) {
                    atomicBoolean.set(((AtomicBoolean) obj2).get());
                    return;
                }
                return;
            }
            if (Map.class.isAssignableFrom(cls)) {
                Map map = (Map) field.get(obj);
                if (map != null && map != Collections.emptyMap() && !map.getClass().getName().startsWith("java.util.Collections$Unmodifiable")) {
                    map.putAll((Map) obj2);
                    return;
                }
                return;
            }
            Collection collection = (Collection) field.get(obj);
            if (collection != null && obj2 != null && collection != Collections.emptySet() && collection != Collections.emptyList() && !collection.getClass().getName().startsWith("java.util.Collections$Unmodifiable")) {
                collection.clear();
                collection.addAll((Collection) obj2);
                return;
            }
            return;
        }
        if (!c0611c.f5245L) {
            method.invoke(obj, obj2);
            return;
        }
        Class cls2 = c0611c.f5264y;
        if (cls2 == AtomicInteger.class) {
            AtomicInteger atomicInteger2 = (AtomicInteger) method.invoke(obj, null);
            if (atomicInteger2 != null) {
                atomicInteger2.set(((AtomicInteger) obj2).get());
                return;
            } else {
                a(this.f4139a.f5262r, method, obj, obj2);
                return;
            }
        }
        if (cls2 == AtomicLong.class) {
            AtomicLong atomicLong2 = (AtomicLong) method.invoke(obj, null);
            if (atomicLong2 != null) {
                atomicLong2.set(((AtomicLong) obj2).get());
                return;
            } else {
                a(this.f4139a.f5262r, method, obj, obj2);
                return;
            }
        }
        if (cls2 == AtomicBoolean.class) {
            AtomicBoolean atomicBoolean2 = (AtomicBoolean) method.invoke(obj, null);
            if (atomicBoolean2 != null) {
                atomicBoolean2.set(((AtomicBoolean) obj2).get());
                return;
            } else {
                a(this.f4139a.f5262r, method, obj, obj2);
                return;
            }
        }
        if (Map.class.isAssignableFrom(method.getReturnType())) {
            try {
                Map map2 = (Map) method.invoke(obj, null);
                if (map2 == null) {
                    if (obj2 != null) {
                        a(this.f4139a.f5262r, method, obj, obj2);
                        return;
                    }
                    return;
                }
                if (map2 != Collections.emptyMap() && !map2.getClass().getName().startsWith("java.util.Collections$Unmodifiable")) {
                    if (map2.getClass().getName().equals("o1.y")) {
                        a(this.f4139a.f5262r, method, obj, obj2);
                        return;
                    } else {
                        map2.putAll((Map) obj2);
                        return;
                    }
                }
                return;
            } catch (InvocationTargetException unused) {
                a(this.f4139a.f5262r, method, obj, obj2);
                return;
            }
        }
        try {
            Collection collection2 = (Collection) method.invoke(obj, null);
            if (collection2 == null || obj2 == null) {
                if (collection2 != null || obj2 == null) {
                    return;
                }
                a(this.f4139a.f5262r, method, obj, obj2);
                return;
            }
            String name = collection2.getClass().getName();
            if (collection2 != Collections.emptySet() && collection2 != Collections.emptyList() && !name.startsWith("java.util.Collections$Unmodifiable")) {
                if (!collection2.isEmpty()) {
                    collection2.clear();
                }
                if (!name.equals("o1.x") && !name.equals("o1.z")) {
                    collection2.addAll((Collection) obj2);
                    return;
                }
                a(this.f4139a.f5262r, method, obj, obj2);
                return;
            }
            return;
        } catch (InvocationTargetException unused2) {
            a(this.f4139a.f5262r, method, obj, obj2);
            return;
        }
        throw new C0424d("set property error, " + this.f4140b.getName() + "#" + this.f4139a.f5250b, e2);
    }

    public void h(Object obj, String str) {
        g(obj, str);
    }

    public void i(Object obj, boolean z2) {
        g(obj, Boolean.valueOf(z2));
    }
}
