package f.a.w.e.d;

/* JADX INFO: compiled from: ObservableTake.java */
/* JADX INFO: loaded from: classes.dex */
public final class h0<T> extends f.a.w.e.d.a<T, T> {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final long f3798e;

    /* JADX INFO: compiled from: ObservableTake.java */
    public static final class a<T> implements f.a.n<T>, f.a.t.b {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final f.a.n<? super T> f3799b;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public boolean f3800e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public f.a.t.b f3801f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public long f3802g;

        public a(f.a.n<? super T> nVar, long j2) {
            this.f3799b = nVar;
            this.f3802g = j2;
        }

        @Override // f.a.n
        public void a(Throwable th) {
            if (this.f3800e) {
                f.a.y.a.C0(th);
                return;
            }
            this.f3800e = true;
            this.f3801f.dispose();
            this.f3799b.a(th);
        }

        @Override // f.a.n
        public void b(f.a.t.b bVar) {
            if (f.a.w.a.b.validate(this.f3801f, bVar)) {
                this.f3801f = bVar;
                if (this.f3802g != 0) {
                    this.f3799b.b(this);
                    return;
                }
                this.f3800e = true;
                bVar.dispose();
                f.a.w.a.c.complete(this.f3799b);
            }
        }

        @Override // f.a.n
        public void c(T t) {
            if (this.f3800e) {
                return;
            }
            long j2 = this.f3802g;
            long j3 = j2 - 1;
            this.f3802g = j3;
            if (j2 > 0) {
                boolean z = j3 == 0;
                this.f3799b.c(t);
                if (z) {
                    onComplete();
                }
            }
        }

        @Override // f.a.t.b
        public void dispose() {
            this.f3801f.dispose();
        }

        @Override // f.a.n
        public void onComplete() {
            if (this.f3800e) {
                return;
            }
            this.f3800e = true;
            this.f3801f.dispose();
            this.f3799b.onComplete();
        }
    }

    public h0(f.a.l<T> lVar, long j2) {
        super(lVar);
        this.f3798e = j2;
    }

    @Override // f.a.i
    public void v(f.a.n<? super T> nVar) {
        this.f3744b.d(new a(nVar, this.f3798e));
    }
}
