package c.a.n;

import java.util.ArrayList;

/* JADX INFO: compiled from: CompositeDisposable.java */
/* JADX INFO: loaded from: classes.dex */
public final class a implements b, c.a.q.a.a {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    c.a.q.h.c<b> f1729c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    volatile boolean f1730d;

    @Override // c.a.q.a.a
    public boolean a(b bVar) {
        if (!c(bVar)) {
            return false;
        }
        bVar.dispose();
        return true;
    }

    @Override // c.a.q.a.a
    public boolean b(b bVar) {
        c.a.q.b.b.c(bVar, "d is null");
        if (!this.f1730d) {
            synchronized (this) {
                if (!this.f1730d) {
                    c.a.q.h.c<b> cVar = this.f1729c;
                    if (cVar == null) {
                        cVar = new c.a.q.h.c<>();
                        this.f1729c = cVar;
                    }
                    cVar.a(bVar);
                    return true;
                }
            }
        }
        bVar.dispose();
        return false;
    }

    @Override // c.a.q.a.a
    public boolean c(b bVar) {
        c.a.q.b.b.c(bVar, "Disposable item is null");
        if (this.f1730d) {
            return false;
        }
        synchronized (this) {
            if (this.f1730d) {
                return false;
            }
            c.a.q.h.c<b> cVar = this.f1729c;
            if (cVar != null && cVar.e(bVar)) {
                return true;
            }
            return false;
        }
    }

    public void d() {
        if (this.f1730d) {
            return;
        }
        synchronized (this) {
            if (this.f1730d) {
                return;
            }
            c.a.q.h.c<b> cVar = this.f1729c;
            this.f1729c = null;
            e(cVar);
        }
    }

    @Override // c.a.n.b
    public void dispose() {
        if (this.f1730d) {
            return;
        }
        synchronized (this) {
            if (this.f1730d) {
                return;
            }
            this.f1730d = true;
            c.a.q.h.c<b> cVar = this.f1729c;
            this.f1729c = null;
            e(cVar);
        }
    }

    void e(c.a.q.h.c<b> cVar) {
        if (cVar == null) {
            return;
        }
        ArrayList arrayList = null;
        for (Object obj : cVar.b()) {
            if (obj instanceof b) {
                try {
                    ((b) obj).dispose();
                } catch (Throwable th) {
                    c.a.o.b.b(th);
                    if (arrayList == null) {
                        arrayList = new ArrayList();
                    }
                    arrayList.add(th);
                }
            }
        }
        if (arrayList != null) {
            if (arrayList.size() != 1) {
                throw new c.a.o.a(arrayList);
            }
            throw c.a.q.h.b.a((Throwable) arrayList.get(0));
        }
    }

    public boolean f() {
        return this.f1730d;
    }
}
