discord-jadx/app/src/main/java/c/f/j/p/k0.java

425 lines
13 KiB
Java

package c.f.j.p;
import android.util.Pair;
import androidx.annotation.VisibleForTesting;
import c.f.j.d.d;
import com.airbnb.lottie.parser.AnimatableValueParser;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArraySet;
/* compiled from: MultiplexProducer */
public abstract class k0<K, T extends Closeable> implements v0<T> {
@VisibleForTesting
public final Map<K, k0<K, T>.b> a;
public final v0<T> b;
/* renamed from: c reason: collision with root package name */
public final boolean f481c;
public final String d;
public final String e;
/* compiled from: MultiplexProducer */
@VisibleForTesting
public class b {
public final K a;
public final CopyOnWriteArraySet<Pair<l<T>, w0>> b = new CopyOnWriteArraySet<>();
/* renamed from: c reason: collision with root package name */
public T f482c;
public float d;
public int e;
public d f;
public k0<K, T>.b.a g;
/* compiled from: MultiplexProducer */
public class a extends b<T> {
public a(a aVar) {
}
/* JADX INFO: finally extract failed */
@Override // c.f.j.p.b
public void g() {
try {
c.f.j.r.b.b();
b bVar = b.this;
synchronized (bVar) {
if (bVar.g == this) {
bVar.g = null;
bVar.f = null;
bVar.b(bVar.f482c);
bVar.f482c = null;
bVar.i(c.f.d.l.a.UNSET);
}
}
c.f.j.r.b.b();
} catch (Throwable th) {
c.f.j.r.b.b();
throw th;
}
}
/* JADX INFO: finally extract failed */
@Override // c.f.j.p.b
public void h(Throwable th) {
try {
c.f.j.r.b.b();
b.this.f(this, th);
c.f.j.r.b.b();
} catch (Throwable th2) {
c.f.j.r.b.b();
throw th2;
}
}
/* JADX INFO: finally extract failed */
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: c.f.j.p.k0$b */
/* JADX WARN: Multi-variable type inference failed */
@Override // c.f.j.p.b
public void i(Object obj, int i) {
Closeable closeable = (Closeable) obj;
try {
c.f.j.r.b.b();
b.this.g(this, closeable, i);
c.f.j.r.b.b();
} catch (Throwable th) {
c.f.j.r.b.b();
throw th;
}
}
/* JADX INFO: finally extract failed */
@Override // c.f.j.p.b
public void j(float f) {
try {
c.f.j.r.b.b();
b.this.h(this, f);
c.f.j.r.b.b();
} catch (Throwable th) {
c.f.j.r.b.b();
throw th;
}
}
}
public b(K k) {
this.a = k;
}
/* JADX DEBUG: Multi-variable search result rejected for r8v0, resolved type: c.f.j.p.l<T extends java.io.Closeable> */
/* JADX DEBUG: Multi-variable search result rejected for r1v6, resolved type: c.f.j.p.k0 */
/* JADX WARN: Multi-variable type inference failed */
public boolean a(l<T> lVar, w0 w0Var) {
k0<K, T>.b bVar;
List<x0> k;
List<x0> l;
List<x0> j;
Closeable closeable;
float f;
int i;
Pair create = Pair.create(lVar, w0Var);
synchronized (this) {
k0 k0Var = k0.this;
K k2 = this.a;
synchronized (k0Var) {
bVar = k0Var.a.get(k2);
}
if (bVar != this) {
return false;
}
this.b.add(create);
k = k();
l = l();
j = j();
closeable = this.f482c;
f = this.d;
i = this.e;
}
d.s(k);
d.t(l);
d.r(j);
synchronized (create) {
synchronized (this) {
if (closeable != this.f482c) {
closeable = null;
} else if (closeable != null) {
closeable = k0.this.c(closeable);
}
}
if (closeable != null) {
if (f > 0.0f) {
lVar.a(f);
}
lVar.b(closeable, i);
b(closeable);
}
}
w0Var.f(new l0(this, create));
return true;
}
public final void b(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public final synchronized boolean c() {
Iterator it = this.b.iterator();
while (it.hasNext()) {
if (((w0) ((Pair) it.next()).second).p()) {
return true;
}
}
return false;
}
public final synchronized boolean d() {
Iterator it = this.b.iterator();
while (it.hasNext()) {
if (!((w0) ((Pair) it.next()).second).k()) {
return false;
}
}
return true;
}
public final synchronized d e() {
d dVar;
dVar = d.LOW;
Iterator it = this.b.iterator();
while (it.hasNext()) {
d c2 = ((w0) ((Pair) it.next()).second).c();
if (dVar != null) {
if (c2 != null) {
if (dVar.ordinal() > c2.ordinal()) {
}
}
}
dVar = c2;
}
return dVar;
}
public void f(k0<K, T>.b.a aVar, Throwable th) {
Iterator it;
synchronized (this) {
if (this.g == aVar) {
it = this.b.iterator();
this.b.clear();
k0.this.e(this.a, this);
b(this.f482c);
this.f482c = null;
} else {
return;
}
}
while (it.hasNext()) {
Pair pair = (Pair) it.next();
synchronized (pair) {
((w0) pair.second).o().k((w0) pair.second, k0.this.d, th, null);
((l) pair.first).c(th);
}
}
}
/* JADX WARNING: Unknown variable types count: 1 */
public void g(k0<K, T>.b.a aVar, T t, int i) {
Iterator it;
int size;
synchronized (this) {
if (this.g == aVar) {
b(this.f482c);
this.f482c = null;
it = this.b.iterator();
size = this.b.size();
if (b.f(i)) {
this.f482c = k0.this.c(t);
this.e = i;
} else {
this.b.clear();
k0.this.e(this.a, this);
}
} else {
return;
}
}
while (it.hasNext()) {
Pair pair = (Pair) it.next();
synchronized (pair) {
if (b.e(i)) {
((w0) pair.second).o().j((w0) pair.second, k0.this.d, null);
d dVar = this.f;
if (dVar != null) {
((w0) pair.second).j(dVar.h);
}
((w0) pair.second).d(k0.this.e, Integer.valueOf(size));
}
((l) pair.first).b(t, i);
}
}
}
public void h(k0<K, T>.b.a aVar, float f) {
Iterator it;
synchronized (this) {
if (this.g == aVar) {
this.d = f;
it = this.b.iterator();
} else {
return;
}
}
while (it.hasNext()) {
Pair pair = (Pair) it.next();
synchronized (pair) {
((l) pair.first).a(f);
}
}
}
public final void i(c.f.d.l.a aVar) {
synchronized (this) {
boolean z2 = true;
AnimatableValueParser.j(Boolean.valueOf(this.f == null));
AnimatableValueParser.j(Boolean.valueOf(this.g == null));
if (this.b.isEmpty()) {
k0.this.e(this.a, this);
return;
}
w0 w0Var = (w0) ((Pair) this.b.iterator().next()).second;
d dVar = new d(w0Var.e(), w0Var.getId(), null, w0Var.o(), w0Var.b(), w0Var.q(), d(), c(), e(), w0Var.g());
this.f = dVar;
dVar.j(w0Var.a());
Objects.requireNonNull(aVar);
if (aVar != c.f.d.l.a.UNSET) {
d dVar2 = this.f;
int ordinal = aVar.ordinal();
if (ordinal != 0) {
if (ordinal == 1) {
z2 = false;
} else if (ordinal != 2) {
throw new IllegalStateException("Unrecognized TriState value: " + aVar);
} else {
throw new IllegalStateException("No boolean equivalent for UNSET");
}
}
dVar2.d("started_as_prefetch", Boolean.valueOf(z2));
}
k0<K, T>.b.a aVar2 = new a(null);
this.g = aVar2;
k0.this.b.b(aVar2, this.f);
}
}
public final synchronized List<x0> j() {
d dVar = this.f;
ArrayList arrayList = null;
if (dVar == null) {
return null;
}
boolean c2 = c();
synchronized (dVar) {
if (c2 != dVar.k) {
dVar.k = c2;
arrayList = new ArrayList(dVar.m);
}
}
return arrayList;
}
public final synchronized List<x0> k() {
d dVar = this.f;
ArrayList arrayList = null;
if (dVar == null) {
return null;
}
boolean d = d();
synchronized (dVar) {
if (d != dVar.i) {
dVar.i = d;
arrayList = new ArrayList(dVar.m);
}
}
return arrayList;
}
public final synchronized List<x0> l() {
d dVar = this.f;
if (dVar == null) {
return null;
}
return dVar.v(e());
}
}
public k0(v0<T> v0Var, String str, String str2) {
this.b = v0Var;
this.a = new HashMap();
this.f481c = false;
this.d = str;
this.e = str2;
}
public k0(v0<T> v0Var, String str, String str2, boolean z2) {
this.b = v0Var;
this.a = new HashMap();
this.f481c = z2;
this.d = str;
this.e = str2;
}
/* JADX INFO: finally extract failed */
@Override // c.f.j.p.v0
public void b(l<T> lVar, w0 w0Var) {
boolean z2;
k0<K, T>.b bVar;
try {
c.f.j.r.b.b();
w0Var.o().e(w0Var, this.d);
K d = d(w0Var);
do {
z2 = false;
synchronized (this) {
synchronized (this) {
bVar = this.a.get(d);
}
}
if (bVar == null) {
synchronized (this) {
bVar = new b(d);
this.a.put(d, bVar);
z2 = true;
}
}
} while (!bVar.a(lVar, w0Var));
if (z2) {
bVar.i(c.f.d.l.a.f(w0Var.k()));
}
c.f.j.r.b.b();
} catch (Throwable th) {
c.f.j.r.b.b();
throw th;
}
}
public abstract T c(T t);
public abstract K d(w0 w0Var);
public synchronized void e(K k, k0<K, T>.b bVar) {
if (this.a.get(k) == bVar) {
this.a.remove(k);
}
}
}