103 lines
2.9 KiB
Java
103 lines
2.9 KiB
Java
package io.reactivex.internal.operators.observable;
|
|
|
|
import io.reactivex.Observable;
|
|
import io.reactivex.ObservableSource;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.Single;
|
|
import io.reactivex.SingleObserver;
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.internal.disposables.DisposableHelper;
|
|
import io.reactivex.internal.fuseable.FuseToObservable;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.NoSuchElementException;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ObservableElementAtSingle<T> extends Single<T> implements FuseToObservable<T> {
|
|
final ObservableSource<T> a;
|
|
final long b;
|
|
final T c;
|
|
|
|
static final class ElementAtObserver<T> implements Observer<T>, Disposable {
|
|
final SingleObserver<? super T> a;
|
|
final long b;
|
|
final T c;
|
|
Disposable d;
|
|
long e;
|
|
boolean f;
|
|
|
|
ElementAtObserver(SingleObserver<? super T> singleObserver, long j, T t) {
|
|
this.a = singleObserver;
|
|
this.b = j;
|
|
this.c = t;
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
this.d.dispose();
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onComplete() {
|
|
if (this.f) {
|
|
return;
|
|
}
|
|
this.f = true;
|
|
T t = this.c;
|
|
if (t != null) {
|
|
this.a.onSuccess(t);
|
|
} else {
|
|
this.a.onError(new NoSuchElementException());
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
if (this.f) {
|
|
RxJavaPlugins.b(th);
|
|
} else {
|
|
this.f = true;
|
|
this.a.onError(th);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onNext(T t) {
|
|
if (this.f) {
|
|
return;
|
|
}
|
|
long j = this.e;
|
|
if (j != this.b) {
|
|
this.e = j + 1;
|
|
return;
|
|
}
|
|
this.f = true;
|
|
this.d.dispose();
|
|
this.a.onSuccess(t);
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onSubscribe(Disposable disposable) {
|
|
if (DisposableHelper.validate(this.d, disposable)) {
|
|
this.d = disposable;
|
|
this.a.onSubscribe(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ObservableElementAtSingle(ObservableSource<T> observableSource, long j, T t) {
|
|
this.a = observableSource;
|
|
this.b = j;
|
|
this.c = t;
|
|
}
|
|
|
|
@Override // io.reactivex.internal.fuseable.FuseToObservable
|
|
public Observable<T> a() {
|
|
return RxJavaPlugins.a(new ObservableElementAt(this.a, this.b, this.c, true));
|
|
}
|
|
|
|
@Override // io.reactivex.Single
|
|
public void b(SingleObserver<? super T> singleObserver) {
|
|
this.a.subscribe(new ElementAtObserver(singleObserver, this.b, this.c));
|
|
}
|
|
}
|