106 lines
3.0 KiB
Java
106 lines
3.0 KiB
Java
package io.reactivex.internal.disposables;
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
import io.reactivex.exceptions.CompositeException;
|
|
import io.reactivex.exceptions.Exceptions;
|
|
import io.reactivex.internal.functions.ObjectHelper;
|
|
import io.reactivex.internal.util.ExceptionHelper;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class ListCompositeDisposable implements Disposable, DisposableContainer {
|
|
List<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;
|
|
}
|
|
|
|
@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) {
|
|
List list = this.a;
|
|
if (list == null) {
|
|
list = new LinkedList();
|
|
this.a = list;
|
|
}
|
|
list.add(disposable);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
disposable.dispose();
|
|
return false;
|
|
}
|
|
|
|
@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;
|
|
}
|
|
List<Disposable> list = this.a;
|
|
if (list != null && list.remove(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;
|
|
List<Disposable> list = this.a;
|
|
this.a = null;
|
|
a(list);
|
|
}
|
|
}
|
|
|
|
void a(List<Disposable> list) {
|
|
if (list == null) {
|
|
return;
|
|
}
|
|
ArrayList arrayList = null;
|
|
Iterator<Disposable> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
try {
|
|
it.next().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);
|
|
}
|
|
}
|
|
}
|