136 lines
3.8 KiB
Java
136 lines
3.8 KiB
Java
package io.reactivex.disposables;
|
|
|
|
import io.reactivex.exceptions.CompositeException;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.internal.disposables.DisposableContainer;
|
|
import io.reactivex.internal.functions.ObjectHelper;
|
|
import io.reactivex.internal.util.ExceptionHelper;
|
|
import io.reactivex.internal.util.OpenHashSet;
|
|
import java.util.ArrayList;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class CompositeDisposable implements Disposable, DisposableContainer {
|
|
OpenHashSet<Disposable> a;
|
|
volatile boolean b;
|
|
|
|
@Override // io.reactivex.internal.disposables.DisposableContainer
|
|
public boolean a(Disposable disposable) {
|
|
if (!c(disposable)) {
|
|
return false;
|
|
}
|
|
disposable.dispose();
|
|
return true;
|
|
}
|
|
|
|
public boolean b() {
|
|
return this.b;
|
|
}
|
|
|
|
@Override // io.reactivex.internal.disposables.DisposableContainer
|
|
public boolean c(Disposable disposable) {
|
|
ObjectHelper.a(disposable, "Disposable item is null");
|
|
if (this.b) {
|
|
return false;
|
|
}
|
|
synchronized (this) {
|
|
if (this.b) {
|
|
return false;
|
|
}
|
|
OpenHashSet<Disposable> openHashSet = this.a;
|
|
if (openHashSet != null && openHashSet.b(disposable)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.disposables.Disposable
|
|
public void dispose() {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
synchronized (this) {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
this.b = true;
|
|
OpenHashSet<Disposable> openHashSet = this.a;
|
|
this.a = null;
|
|
a(openHashSet);
|
|
}
|
|
}
|
|
|
|
@Override // io.reactivex.internal.disposables.DisposableContainer
|
|
public boolean b(Disposable disposable) {
|
|
ObjectHelper.a(disposable, "d is null");
|
|
if (!this.b) {
|
|
synchronized (this) {
|
|
if (!this.b) {
|
|
OpenHashSet<Disposable> openHashSet = this.a;
|
|
if (openHashSet == null) {
|
|
openHashSet = new OpenHashSet<>();
|
|
this.a = openHashSet;
|
|
}
|
|
openHashSet.a((OpenHashSet<Disposable>) disposable);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
disposable.dispose();
|
|
return false;
|
|
}
|
|
|
|
public void a() {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
synchronized (this) {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
OpenHashSet<Disposable> openHashSet = this.a;
|
|
this.a = null;
|
|
a(openHashSet);
|
|
}
|
|
}
|
|
|
|
public int c() {
|
|
if (this.b) {
|
|
return 0;
|
|
}
|
|
synchronized (this) {
|
|
if (this.b) {
|
|
return 0;
|
|
}
|
|
OpenHashSet<Disposable> openHashSet = this.a;
|
|
return openHashSet != null ? openHashSet.c() : 0;
|
|
}
|
|
}
|
|
|
|
void a(OpenHashSet<Disposable> openHashSet) {
|
|
if (openHashSet == null) {
|
|
return;
|
|
}
|
|
ArrayList arrayList = null;
|
|
for (Object obj : openHashSet.a()) {
|
|
if (obj instanceof Disposable) {
|
|
try {
|
|
((Disposable) obj).dispose();
|
|
} catch (Throwable th) {
|
|
Exceptions.b(th);
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.add(th);
|
|
}
|
|
}
|
|
}
|
|
if (arrayList != null) {
|
|
if (arrayList.size() == 1) {
|
|
throw ExceptionHelper.a((Throwable) arrayList.get(0));
|
|
}
|
|
throw new CompositeException(arrayList);
|
|
}
|
|
}
|
|
}
|