91 lines
2.9 KiB
Java
91 lines
2.9 KiB
Java
package io.reactivex.internal.operators.observable;
|
|
|
|
import io.reactivex.ObservableSource;
|
|
import io.reactivex.Observer;
|
|
import io.reactivex.functions.BiPredicate;
|
|
import io.reactivex.functions.Function;
|
|
import io.reactivex.internal.observers.BasicFuseableObserver;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ObservableDistinctUntilChanged<T, K> extends AbstractObservableWithUpstream<T, T> {
|
|
final Function<? super T, K> b;
|
|
final BiPredicate<? super K, ? super K> c;
|
|
|
|
static final class DistinctUntilChangedObserver<T, K> extends BasicFuseableObserver<T, T> {
|
|
final Function<? super T, K> f;
|
|
final BiPredicate<? super K, ? super K> g;
|
|
K h;
|
|
boolean i;
|
|
|
|
DistinctUntilChangedObserver(Observer<? super T> observer, Function<? super T, K> function, BiPredicate<? super K, ? super K> biPredicate) {
|
|
super(observer);
|
|
this.f = function;
|
|
this.g = biPredicate;
|
|
}
|
|
|
|
@Override // io.reactivex.Observer
|
|
public void onNext(T t) {
|
|
if (this.d) {
|
|
return;
|
|
}
|
|
if (this.e != 0) {
|
|
this.a.onNext(t);
|
|
return;
|
|
}
|
|
try {
|
|
K apply = this.f.apply(t);
|
|
if (this.i) {
|
|
boolean a = this.g.a(this.h, apply);
|
|
this.h = apply;
|
|
if (a) {
|
|
return;
|
|
}
|
|
} else {
|
|
this.i = true;
|
|
this.h = apply;
|
|
}
|
|
this.a.onNext(t);
|
|
} catch (Throwable th) {
|
|
a(th);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.internal.fuseable.SimpleQueue
|
|
public T poll() throws Exception {
|
|
while (true) {
|
|
T poll = this.c.poll();
|
|
if (poll == null) {
|
|
return null;
|
|
}
|
|
K apply = this.f.apply(poll);
|
|
if (!this.i) {
|
|
this.i = true;
|
|
this.h = apply;
|
|
return poll;
|
|
}
|
|
if (!this.g.a(this.h, apply)) {
|
|
this.h = apply;
|
|
return poll;
|
|
}
|
|
this.h = apply;
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.internal.fuseable.QueueFuseable
|
|
public int requestFusion(int i) {
|
|
return a(i);
|
|
}
|
|
}
|
|
|
|
public ObservableDistinctUntilChanged(ObservableSource<T> observableSource, Function<? super T, K> function, BiPredicate<? super K, ? super K> biPredicate) {
|
|
super(observableSource);
|
|
this.b = function;
|
|
this.c = biPredicate;
|
|
}
|
|
|
|
@Override // io.reactivex.Observable
|
|
protected void subscribeActual(Observer<? super T> observer) {
|
|
this.a.subscribe(new DistinctUntilChangedObserver(observer, this.b, this.c));
|
|
}
|
|
}
|