package com.google.android.gms.internal.ads;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/* JADX INFO: loaded from: classes2.dex */
public final class ds1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Object[] f10502a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f10503b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public cs1 f10504c;

    public ds1() {
        this(4);
    }

    public final void a(Object obj, Object obj2) {
        int i10 = this.f10503b + 1;
        Object[] objArr = this.f10502a;
        int length = objArr.length;
        int i11 = i10 + i10;
        if (i11 > length) {
            this.f10502a = Arrays.copyOf(objArr, zr1.d(length, i11));
        }
        ih1.w(obj, obj2);
        Object[] objArr2 = this.f10502a;
        int i12 = this.f10503b;
        int i13 = i12 + i12;
        objArr2[i13] = obj;
        objArr2[i13 + 1] = obj2;
        this.f10503b = i12 + 1;
    }

    public final void b(Set set) {
        if (set instanceof Collection) {
            int size = set.size() + this.f10503b;
            Object[] objArr = this.f10502a;
            int length = objArr.length;
            int i10 = size + size;
            if (i10 > length) {
                this.f10502a = Arrays.copyOf(objArr, zr1.d(length, i10));
            }
        }
        Iterator it = set.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            a(entry.getKey(), entry.getValue());
        }
    }

    public final zzgui c() {
        return d(true);
    }

    public final zzgui d(boolean z10) {
        cs1 cs1Var;
        cs1 cs1Var2;
        if (z10 && (cs1Var2 = this.f10504c) != null) {
            throw cs1Var2.a();
        }
        zzgwf zzgwfVarE = zzgwf.e(this.f10503b, this.f10502a, this);
        if (!z10 || (cs1Var = this.f10504c) == null) {
            return zzgwfVarE;
        }
        throw cs1Var.a();
    }

    public ds1(int i10) {
        this.f10502a = new Object[i10 + i10];
        this.f10503b = 0;
    }
}
