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

import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;

/* JADX INFO: loaded from: classes2.dex */
public abstract class mu1 extends ou1 {
    public static final cv1 R = new cv1(0, mu1.class);
    public final boolean Q;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public zzgub f14358l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final boolean f14359m;

    public mu1(zzguf zzgufVar, boolean z10, boolean z11) {
        int size = zzgufVar.size();
        this.f15171h = null;
        this.f15172i = size;
        this.f14358l = zzgufVar;
        this.f14359m = z10;
        this.Q = z11;
    }

    @Override // com.google.android.gms.internal.ads.cu1
    public final void e() {
        zzgub zzgubVar = this.f14358l;
        s(1);
        if ((zzgubVar != null) && (this.f11887a instanceof wt1)) {
            boolean zM = m();
            ct1 ct1VarC = zzgubVar.c();
            while (ct1VarC.hasNext()) {
                ((Future) ct1VarC.next()).cancel(zM);
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.cu1
    public final String f() {
        zzgub zzgubVar = this.f14358l;
        return zzgubVar != null ? "futures=".concat(zzgubVar.toString()) : super.f();
    }

    public abstract void s(int i10);

    public final void t(int i10, com.google.common.util.concurrent.w wVar) {
        try {
            if (wVar.isCancelled()) {
                this.f14358l = null;
                cancel(false);
            } else {
                try {
                    y(i10, ih1.q(wVar));
                } catch (ExecutionException e10) {
                    u(e10.getCause());
                } catch (Throwable th) {
                    u(th);
                }
            }
        } finally {
            v(null);
        }
    }

    public final void u(Throwable th) {
        th.getClass();
        if (this.f14359m && !d(th)) {
            Set set = this.f15171h;
            if (set == null) {
                Set setNewSetFromMap = Collections.newSetFromMap(new ConcurrentHashMap());
                x(setNewSetFromMap);
                ou1.f15169j.m(this, setNewSetFromMap);
                set = this.f15171h;
                Objects.requireNonNull(set);
            }
            for (Throwable cause = th; cause != null; cause = cause.getCause()) {
                if (set.add(cause)) {
                }
            }
            R.b().logp(Level.SEVERE, "com.google.common.util.concurrent.AggregateFuture", "log", true != (th instanceof Error) ? "Got more than one input Future failure. Logging failures after the first" : "Input Future failed with Error", th);
            return;
        }
        boolean z10 = th instanceof Error;
        if (z10) {
            R.b().logp(Level.SEVERE, "com.google.common.util.concurrent.AggregateFuture", "log", true != z10 ? "Got more than one input Future failure. Logging failures after the first" : "Input Future failed with Error", th);
        }
    }

    public final void v(zzgub zzgubVar) {
        int iO = ou1.f15169j.o(this);
        int i10 = 0;
        ih1.f1("Less than 0 remaining futures", iO >= 0);
        if (iO == 0) {
            if (zzgubVar != null) {
                ct1 ct1VarC = zzgubVar.c();
                while (ct1VarC.hasNext()) {
                    Future future = (Future) ct1VarC.next();
                    if (!future.isCancelled()) {
                        try {
                            y(i10, ih1.q(future));
                        } catch (ExecutionException e10) {
                            u(e10.getCause());
                        } catch (Throwable th) {
                            u(th);
                        }
                    }
                    i10++;
                }
            }
            this.f15171h = null;
            z();
            s(2);
        }
    }

    public final void w() {
        Objects.requireNonNull(this.f14358l);
        if (this.f14358l.isEmpty()) {
            z();
            return;
        }
        zzgzd zzgzdVar = zzgzd.f19813a;
        int i10 = 1;
        if (this.f14359m) {
            ct1 ct1VarC = this.f14358l.c();
            int i11 = 0;
            while (ct1VarC.hasNext()) {
                com.google.common.util.concurrent.w wVar = (com.google.common.util.concurrent.w) ct1VarC.next();
                int i12 = i11 + 1;
                if (wVar.isDone()) {
                    t(i11, wVar);
                } else {
                    wVar.g(new ms0(this, i11, wVar, i10), zzgzdVar);
                }
                i11 = i12;
            }
            return;
        }
        zzgub zzgubVar = this.f14358l;
        zzgub zzgubVar2 = true != this.Q ? null : zzgubVar;
        nw0 nw0Var = new nw0(this, zzgubVar2, 19);
        ct1 ct1VarC2 = zzgubVar.c();
        while (ct1VarC2.hasNext()) {
            com.google.common.util.concurrent.w wVar2 = (com.google.common.util.concurrent.w) ct1VarC2.next();
            if (wVar2.isDone()) {
                v(zzgubVar2);
            } else {
                wVar2.g(nw0Var, zzgzdVar);
            }
        }
    }

    public final void x(Set set) {
        set.getClass();
        if (this.f11887a instanceof wt1) {
            return;
        }
        Throwable thA = a();
        Objects.requireNonNull(thA);
        while (thA != null && set.add(thA)) {
            thA = thA.getCause();
        }
    }

    public abstract void y(int i10, Object obj);

    public abstract void z();
}
