mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-15 10:27:17 +01:00
209 lines
7 KiB
Java
209 lines
7 KiB
Java
package io.reactivex.rxjava3.subscribers;
|
|
|
|
import io.reactivex.rxjava3.annotations.NonNull;
|
|
import io.reactivex.rxjava3.core.FlowableSubscriber;
|
|
import io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper;
|
|
import io.reactivex.rxjava3.observers.BaseTestConsumer;
|
|
import java.util.List;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import org.reactivestreams.Subscriber;
|
|
import org.reactivestreams.Subscription;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes10.dex */
|
|
public class TestSubscriber<T> extends BaseTestConsumer<T, TestSubscriber<T>> implements FlowableSubscriber<T>, Subscription {
|
|
private volatile boolean cancelled;
|
|
private final Subscriber<? super T> downstream;
|
|
private final AtomicLong missedRequested;
|
|
private final AtomicReference<Subscription> upstream;
|
|
|
|
public TestSubscriber(@NonNull Subscriber<? super T> subscriber, long j) {
|
|
if (j < 0) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Negative initial request not allowed");
|
|
throw null;
|
|
}
|
|
this.downstream = subscriber;
|
|
this.upstream = new AtomicReference<>();
|
|
this.missedRequested = new AtomicLong(j);
|
|
}
|
|
|
|
@NonNull
|
|
public static <T> TestSubscriber<T> create() {
|
|
return new TestSubscriber<>();
|
|
}
|
|
|
|
@Override // io.reactivex.rxjava3.observers.BaseTestConsumer
|
|
public final TestSubscriber<T> assertSubscribed() {
|
|
if (this.upstream.get() != null) {
|
|
return this;
|
|
}
|
|
throw fail("Not subscribed!");
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public final void cancel() {
|
|
if (this.cancelled) {
|
|
return;
|
|
}
|
|
this.cancelled = true;
|
|
SubscriptionHelper.cancel(this.upstream);
|
|
}
|
|
|
|
@Override // io.reactivex.rxjava3.observers.BaseTestConsumer, io.reactivex.rxjava3.disposables.Disposable
|
|
public final void dispose() {
|
|
cancel();
|
|
}
|
|
|
|
public final boolean hasSubscription() {
|
|
return this.upstream.get() != null;
|
|
}
|
|
|
|
public final boolean isCancelled() {
|
|
return this.cancelled;
|
|
}
|
|
|
|
@Override // io.reactivex.rxjava3.observers.BaseTestConsumer, io.reactivex.rxjava3.disposables.Disposable
|
|
public final boolean isDisposed() {
|
|
return this.cancelled;
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onComplete() {
|
|
if (!this.checkSubscriptionOnce) {
|
|
this.checkSubscriptionOnce = true;
|
|
if (this.upstream.get() == null) {
|
|
this.errors.add(new IllegalStateException("onSubscribe not called in proper order"));
|
|
}
|
|
}
|
|
try {
|
|
this.lastThread = Thread.currentThread();
|
|
this.completions++;
|
|
this.downstream.onComplete();
|
|
} finally {
|
|
this.done.countDown();
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onError(@NonNull Throwable th) {
|
|
if (!this.checkSubscriptionOnce) {
|
|
this.checkSubscriptionOnce = true;
|
|
if (this.upstream.get() == null) {
|
|
this.errors.add(new IllegalStateException("onSubscribe not called in proper order"));
|
|
}
|
|
}
|
|
try {
|
|
this.lastThread = Thread.currentThread();
|
|
List<Throwable> list = this.errors;
|
|
if (th == null) {
|
|
list.add(new NullPointerException("onError received a null Throwable"));
|
|
} else {
|
|
list.add(th);
|
|
}
|
|
this.downstream.onError(th);
|
|
this.done.countDown();
|
|
} catch (Throwable th2) {
|
|
this.done.countDown();
|
|
throw th2;
|
|
}
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onNext(@NonNull T t) {
|
|
if (!this.checkSubscriptionOnce) {
|
|
this.checkSubscriptionOnce = true;
|
|
if (this.upstream.get() == null) {
|
|
this.errors.add(new IllegalStateException("onSubscribe not called in proper order"));
|
|
}
|
|
}
|
|
this.lastThread = Thread.currentThread();
|
|
this.values.add(t);
|
|
if (t == null) {
|
|
this.errors.add(new NullPointerException("onNext received a null value"));
|
|
}
|
|
this.downstream.onNext(t);
|
|
}
|
|
|
|
@Override // io.reactivex.rxjava3.core.FlowableSubscriber, org.reactivestreams.Subscriber
|
|
public void onSubscribe(@NonNull Subscription subscription) {
|
|
this.lastThread = Thread.currentThread();
|
|
if (subscription == null) {
|
|
this.errors.add(new NullPointerException("onSubscribe received a null Subscription"));
|
|
return;
|
|
}
|
|
AtomicReference<Subscription> atomicReference = this.upstream;
|
|
while (!atomicReference.compareAndSet(null, subscription)) {
|
|
if (atomicReference.get() != null) {
|
|
subscription.cancel();
|
|
if (this.upstream.get() != SubscriptionHelper.CANCELLED) {
|
|
this.errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + subscription));
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
this.downstream.onSubscribe(subscription);
|
|
long andSet = this.missedRequested.getAndSet(0L);
|
|
if (andSet != 0) {
|
|
subscription.request(andSet);
|
|
}
|
|
onStart();
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public final void request(long j) {
|
|
SubscriptionHelper.deferredRequest(this.upstream, this.missedRequested, j);
|
|
}
|
|
|
|
public final TestSubscriber<T> requestMore(long j) {
|
|
request(j);
|
|
return this;
|
|
}
|
|
|
|
@NonNull
|
|
public static <T> TestSubscriber<T> create(long j) {
|
|
return new TestSubscriber<>(j);
|
|
}
|
|
|
|
public static <T> TestSubscriber<T> create(@NonNull Subscriber<? super T> subscriber) {
|
|
return new TestSubscriber<>(subscriber);
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public enum EmptySubscriber implements FlowableSubscriber<Object> {
|
|
INSTANCE;
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onComplete() {
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onError(Throwable th) {
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscriber
|
|
public void onNext(Object obj) {
|
|
}
|
|
|
|
@Override // io.reactivex.rxjava3.core.FlowableSubscriber, org.reactivestreams.Subscriber
|
|
public void onSubscribe(Subscription subscription) {
|
|
}
|
|
}
|
|
|
|
public void onStart() {
|
|
}
|
|
|
|
public TestSubscriber(long j) {
|
|
this(EmptySubscriber.INSTANCE, j);
|
|
}
|
|
|
|
public TestSubscriber(@NonNull Subscriber<? super T> subscriber) {
|
|
this(subscriber, Long.MAX_VALUE);
|
|
}
|
|
|
|
public TestSubscriber() {
|
|
this(EmptySubscriber.INSTANCE, Long.MAX_VALUE);
|
|
}
|
|
}
|