168 lines
4.8 KiB
Java
168 lines
4.8 KiB
Java
package rx.subjects;
|
|
|
|
import j0.l.a.e;
|
|
import j0.q.c;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import rx.Observable;
|
|
import rx.functions.Action1;
|
|
public final class BehaviorSubject<T> extends Subject<T, T> {
|
|
public static final Object[] j = new Object[0];
|
|
public final c<T> k;
|
|
|
|
public static class a implements Action1<c.b<T>> {
|
|
public final /* synthetic */ c i;
|
|
|
|
public a(c cVar) {
|
|
this.i = cVar;
|
|
}
|
|
|
|
@Override // rx.functions.Action1
|
|
public void call(Object obj) {
|
|
boolean z2;
|
|
Throwable th;
|
|
Throwable th2;
|
|
c.b bVar = (c.b) obj;
|
|
Object obj2 = this.i.latest;
|
|
synchronized (bVar) {
|
|
if (bVar.j) {
|
|
if (!bVar.k) {
|
|
bVar.j = false;
|
|
z2 = true;
|
|
bVar.k = obj2 != null;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (obj2 != null) {
|
|
List<Object> list = null;
|
|
boolean z3 = true;
|
|
while (true) {
|
|
if (list != null) {
|
|
try {
|
|
for (Object obj3 : list) {
|
|
if (obj3 != null) {
|
|
e.a(bVar.i, obj3);
|
|
}
|
|
}
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
z2 = false;
|
|
if (!z2) {
|
|
synchronized (bVar) {
|
|
bVar.k = false;
|
|
}
|
|
}
|
|
throw th;
|
|
}
|
|
}
|
|
if (z3) {
|
|
e.a(bVar.i, obj2);
|
|
z3 = false;
|
|
}
|
|
synchronized (bVar) {
|
|
try {
|
|
list = bVar.l;
|
|
bVar.l = null;
|
|
if (list == null) {
|
|
bVar.k = false;
|
|
try {
|
|
return;
|
|
} catch (Throwable th4) {
|
|
th2 = th4;
|
|
}
|
|
}
|
|
} catch (Throwable th5) {
|
|
th2 = th5;
|
|
z2 = false;
|
|
try {
|
|
throw th2;
|
|
} catch (Throwable th6) {
|
|
th = th6;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public BehaviorSubject(Observable.a<T> aVar, c<T> cVar) {
|
|
super(aVar);
|
|
this.k = cVar;
|
|
}
|
|
|
|
public static <T> BehaviorSubject<T> k0() {
|
|
return m0(null, false);
|
|
}
|
|
|
|
public static <T> BehaviorSubject<T> l0(T t) {
|
|
return m0(t, true);
|
|
}
|
|
|
|
public static <T> BehaviorSubject<T> m0(T t, boolean z2) {
|
|
c cVar = new c();
|
|
if (z2) {
|
|
if (t == null) {
|
|
t = (T) e.b;
|
|
}
|
|
cVar.latest = t;
|
|
}
|
|
a aVar = new a(cVar);
|
|
cVar.onAdded = aVar;
|
|
cVar.onTerminated = aVar;
|
|
return new BehaviorSubject<>(cVar, cVar);
|
|
}
|
|
|
|
public T n0() {
|
|
Object obj = this.k.latest;
|
|
if (obj != null && !(obj instanceof e.c) && !e.c(obj)) {
|
|
return (T) e.b(obj);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onCompleted() {
|
|
if (this.k.latest == null || this.k.active) {
|
|
Object obj = e.a;
|
|
for (c.b<T> bVar : this.k.b(obj)) {
|
|
bVar.a(obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onError(Throwable th) {
|
|
if (this.k.latest == null || this.k.active) {
|
|
e.c cVar = new e.c(th);
|
|
ArrayList arrayList = null;
|
|
for (c.b<T> bVar : this.k.b(cVar)) {
|
|
try {
|
|
bVar.a(cVar);
|
|
} catch (Throwable th2) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.add(th2);
|
|
}
|
|
}
|
|
c.q.a.k.a.Z(arrayList);
|
|
}
|
|
}
|
|
|
|
@Override // j0.g
|
|
public void onNext(T t) {
|
|
if (this.k.latest == null || this.k.active) {
|
|
if (t == null) {
|
|
t = (T) e.b;
|
|
}
|
|
c<T> cVar = this.k;
|
|
cVar.latest = t;
|
|
for (c.b bVar : cVar.get().e) {
|
|
bVar.a(t);
|
|
}
|
|
}
|
|
}
|
|
}
|