117 lines
3.9 KiB
Java
117 lines
3.9 KiB
Java
package io.reactivex.internal.operators.observable;
|
|
|
|
import io.reactivex.ObservableSource;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.functions.Function;
|
|
import io.reactivex.internal.disposables.EmptyDisposable;
|
|
import io.reactivex.internal.functions.ObjectHelper;
|
|
import io.reactivex.internal.observers.BasicFuseableObserver;
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.Collection;
|
|
import java.util.concurrent.Callable;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ObservableDistinct<T, K> extends AbstractObservableWithUpstream<T, T> {
|
|
final Function<? super T, K> b;
|
|
final Callable<? extends Collection<? super K>> c;
|
|
|
|
static final class DistinctObserver<T, K> extends BasicFuseableObserver<T, T> {
|
|
final Collection<? super K> f;
|
|
final Function<? super T, K> g;
|
|
|
|
DistinctObserver(Observer<? super T> observer, Function<? super T, K> function, Collection<? super K> collection) {
|
|
super(observer);
|
|
this.g = function;
|
|
this.f = collection;
|
|
}
|
|
|
|
@Override // io.reactivex.internal.observers.BasicFuseableObserver, io.reactivex.internal.fuseable.SimpleQueue
|
|
public void clear() {
|
|
this.f.clear();
|
|
super.clear();
|
|
}
|
|
|
|
@Override // io.reactivex.internal.observers.BasicFuseableObserver, io.reactivex.Observer
|
|
public void onComplete() {
|
|
if (this.d) {
|
|
return;
|
|
}
|
|
this.d = true;
|
|
this.f.clear();
|
|
this.a.onComplete();
|
|
}
|
|
|
|
@Override // io.reactivex.internal.observers.BasicFuseableObserver, io.reactivex.Observer
|
|
public void onError(Throwable th) {
|
|
if (this.d) {
|
|
RxJavaPlugins.b(th);
|
|
return;
|
|
}
|
|
this.d = true;
|
|
this.f.clear();
|
|
this.a.onError(th);
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onNext(T t) {
|
|
if (this.d) {
|
|
return;
|
|
}
|
|
if (this.e != 0) {
|
|
this.a.onNext(null);
|
|
return;
|
|
}
|
|
try {
|
|
K apply = this.g.apply(t);
|
|
ObjectHelper.a(apply, "The keySelector returned a null key");
|
|
if (this.f.add(apply)) {
|
|
this.a.onNext(t);
|
|
}
|
|
} catch (Throwable th) {
|
|
a(th);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.internal.fuseable.SimpleQueue
|
|
public T poll() throws Exception {
|
|
T poll;
|
|
Collection<? super K> collection;
|
|
K apply;
|
|
do {
|
|
poll = this.c.poll();
|
|
if (poll == null) {
|
|
break;
|
|
}
|
|
collection = this.f;
|
|
apply = this.g.apply(poll);
|
|
ObjectHelper.a(apply, "The keySelector returned a null key");
|
|
} while (!collection.add(apply));
|
|
return poll;
|
|
}
|
|
|
|
@Override // io.reactivex.internal.fuseable.QueueFuseable
|
|
public int requestFusion(int i) {
|
|
return a(i);
|
|
}
|
|
}
|
|
|
|
public ObservableDistinct(ObservableSource<T> observableSource, Function<? super T, K> function, Callable<? extends Collection<? super K>> callable) {
|
|
super(observableSource);
|
|
this.b = function;
|
|
this.c = callable;
|
|
}
|
|
|
|
@Override // io.reactivex.Observable
|
|
protected void subscribeActual(Observer<? super T> observer) {
|
|
try {
|
|
Collection<? super K> call = this.c.call();
|
|
ObjectHelper.a(call, "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
|
|
this.a.subscribe(new DistinctObserver(observer, this.b, call));
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
EmptyDisposable.error(th, observer);
|
|
}
|
|
}
|
|
}
|