package nr;

/* loaded from: classes5.dex */
class e {

    /* renamed from: a, reason: collision with root package name */
    private final c[] f30376a;

    /* renamed from: b, reason: collision with root package name */
    private a[] f30377b = new a[16];

    /* loaded from: classes5.dex */
    static class a {

        /* renamed from: a, reason: collision with root package name */
        final Class f30378a;

        /* renamed from: b, reason: collision with root package name */
        final c f30379b;

        a(Class cls, c cVar) {
            this.f30378a = cls;
            this.f30379b = cVar;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public e(c[] cVarArr) {
        this.f30376a = cVarArr;
    }

    private static c c(e eVar, Class cls) {
        c[] cVarArr = eVar.f30376a;
        int length = cVarArr.length;
        int i10 = length;
        while (true) {
            length--;
            if (length < 0) {
                if (cls == null || i10 == 0) {
                    return null;
                }
                if (i10 == 1) {
                    return cVarArr[0];
                }
                int i11 = i10;
                while (true) {
                    i10--;
                    if (i10 < 0) {
                        break;
                    }
                    Class c10 = cVarArr[i10].c();
                    int i12 = i11;
                    while (true) {
                        i11--;
                        if (i11 >= 0) {
                            if (i11 != i10 && cVarArr[i11].c().isAssignableFrom(c10)) {
                                eVar = eVar.a(i11, null);
                                cVarArr = eVar.f30376a;
                                i12 = cVarArr.length;
                                i10 = i12 - 1;
                            }
                        }
                    }
                    i11 = i12;
                }
                if (i11 == 1) {
                    return cVarArr[0];
                }
                StringBuilder sb2 = new StringBuilder();
                sb2.append("Unable to find best converter for type \"");
                sb2.append(cls.getName());
                sb2.append("\" from remaining set: ");
                for (int i13 = 0; i13 < i11; i13++) {
                    c cVar = cVarArr[i13];
                    Class c11 = cVar.c();
                    sb2.append(cVar.getClass().getName());
                    sb2.append('[');
                    sb2.append(c11 == null ? null : c11.getName());
                    sb2.append("], ");
                }
                throw new IllegalStateException(sb2.toString());
            }
            c cVar2 = cVarArr[length];
            Class c12 = cVar2.c();
            if (c12 == cls) {
                return cVar2;
            }
            if (c12 == null || (cls != null && !c12.isAssignableFrom(cls))) {
                eVar = eVar.a(length, null);
                cVarArr = eVar.f30376a;
                i10 = cVarArr.length;
            }
        }
    }

    e a(int i10, c[] cVarArr) {
        c[] cVarArr2 = this.f30376a;
        int length = cVarArr2.length;
        if (i10 >= length) {
            throw new IndexOutOfBoundsException();
        }
        if (cVarArr != null) {
            cVarArr[0] = cVarArr2[i10];
        }
        c[] cVarArr3 = new c[length - 1];
        int i11 = 0;
        for (int i12 = 0; i12 < length; i12++) {
            if (i12 != i10) {
                cVarArr3[i11] = cVarArr2[i12];
                i11++;
            }
        }
        return new e(cVarArr3);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Code restructure failed: missing block: B:47:0x0052, code lost:
    
        r7 = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:51:0x000e, code lost:
    
        r3 = 0;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public c b(Class cls) {
        int i10;
        int i11;
        a[] aVarArr = this.f30377b;
        int length = aVarArr.length;
        if (cls != null) {
            i10 = cls.hashCode() & (length - 1);
            while (true) {
                a aVar = aVarArr[i10];
                if (aVar == null) {
                    c c10 = c(this, cls);
                    a aVar2 = new a(cls, c10);
                    a[] aVarArr2 = (a[]) aVarArr.clone();
                    aVarArr2[i10] = aVar2;
                    for (int i12 = 0; i12 < length; i12++) {
                        if (aVarArr2[i12] == null) {
                            this.f30377b = aVarArr2;
                            return c10;
                        }
                    }
                    int i13 = length << 1;
                    a[] aVarArr3 = new a[i13];
                    for (int i14 = 0; i14 < length; i14++) {
                        a aVar3 = aVarArr2[i14];
                        Class cls2 = aVar3.f30378a;
                        if (cls2 != null) {
                            i11 = cls2.hashCode() & (i13 - 1);
                            while (aVarArr3[i11] != null) {
                                i11++;
                                if (i11 >= i13) {
                                }
                            }
                            aVarArr3[i11] = aVar3;
                        }
                        i11 = 0;
                    }
                    this.f30377b = aVarArr3;
                    return c10;
                }
                if (aVar.f30378a == cls) {
                    return aVar.f30379b;
                }
                i10++;
                if (i10 >= length) {
                }
            }
        }
        i10 = 0;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int d() {
        return this.f30376a.length;
    }
}
