package i.a.n.d;

import i.a.g;

/* JADX INFO: compiled from: BasicFuseableObserver.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class a<T, R> implements g<T>, i.a.n.c.a<R> {
    protected final g<? super R> b;
    protected i.a.k.b d;
    protected i.a.n.c.a<T> e;
    protected boolean f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    protected int f833g;

    public a(g<? super R> gVar) {
        this.b = gVar;
    }

    @Override // i.a.g
    public void a(Throwable th) {
        if (this.f) {
            i.a.p.a.l(th);
        } else {
            this.f = true;
            this.b.a(th);
        }
    }

    @Override // i.a.g
    public void b() {
        if (this.f) {
            return;
        }
        this.f = true;
        this.b.b();
    }

    @Override // i.a.g
    public final void c(i.a.k.b bVar) {
        if (i.a.n.a.b.validate(this.d, bVar)) {
            this.d = bVar;
            if (bVar instanceof i.a.n.c.a) {
                this.e = (i.a.n.c.a) bVar;
            }
            if (f()) {
                this.b.c(this);
                e();
            }
        }
    }

    @Override // i.a.n.c.e
    public void clear() {
        this.e.clear();
    }

    @Override // i.a.k.b
    public void dispose() {
        this.d.dispose();
    }

    protected void e() {
    }

    protected boolean f() {
        return true;
    }

    protected final void g(Throwable th) {
        i.a.l.b.b(th);
        this.d.dispose();
        a(th);
    }

    protected final int h(int i2) {
        i.a.n.c.a<T> aVar = this.e;
        if (aVar == null || (i2 & 4) != 0) {
            return 0;
        }
        int iRequestFusion = aVar.requestFusion(i2);
        if (iRequestFusion != 0) {
            this.f833g = iRequestFusion;
        }
        return iRequestFusion;
    }

    @Override // i.a.k.b
    public boolean isDisposed() {
        return this.d.isDisposed();
    }

    @Override // i.a.n.c.e
    public boolean isEmpty() {
        return this.e.isEmpty();
    }

    @Override // i.a.n.c.e
    public final boolean offer(R r) {
        throw new UnsupportedOperationException("Should not be called!");
    }
}
