package androidx.room.coroutines;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import kotlin.collections.EmptyList;
import kotlin.collections.n;
import kotlin.coroutines.Continuation;

/* JADX INFO: loaded from: classes.dex */
public final class g implements k3.a, kotlinx.coroutines.sync.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final k3.a f4023a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final kotlinx.coroutines.sync.a f4024b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public kotlin.coroutines.h f4025c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Throwable f4026d;

    public g(k3.a aVar) {
        kotlinx.coroutines.sync.c cVarA = kotlinx.coroutines.sync.d.a();
        nb.g.i(aVar, "delegate");
        this.f4023a = aVar;
        this.f4024b = cVarA;
    }

    @Override // k3.a
    public final k3.c J(String str) {
        nb.g.i(str, "sql");
        return this.f4023a.J(str);
    }

    @Override // java.lang.AutoCloseable
    public final void close() throws Exception {
        this.f4023a.close();
    }

    @Override // kotlinx.coroutines.sync.a
    public final Object e(Continuation continuation) {
        return this.f4024b.e(continuation);
    }

    @Override // kotlinx.coroutines.sync.a
    public final void g(Object obj) {
        this.f4024b.g(obj);
    }

    /* JADX WARN: Removed duplicated region for block: B:56:0x0113 A[LOOP:0: B:54:0x010d->B:56:0x0113, LOOP_END] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void k(StringBuilder sb) {
        ArrayList arrayList;
        Iterable iterableR0;
        Iterator it;
        Object objK1;
        if (this.f4025c == null && this.f4026d == null) {
            sb.append("\t\tStatus: Free connection");
            sb.append('\n');
            return;
        }
        sb.append("\t\tStatus: Acquired connection");
        sb.append('\n');
        kotlin.coroutines.h hVar = this.f4025c;
        if (hVar != null) {
            sb.append("\t\tCoroutine: " + hVar);
            sb.append('\n');
        }
        Throwable th = this.f4026d;
        if (th != null) {
            sb.append("\t\tAcquired:");
            sb.append('\n');
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            th.printStackTrace(printWriter);
            printWriter.flush();
            String string = stringWriter.toString();
            nb.g.h(string, "sw.toString()");
            List listB1 = kotlin.sequences.j.b1(kotlin.text.i.u0(string));
            nb.g.i(listB1, "<this>");
            if (listB1 instanceof Collection) {
                List list = listB1;
                int size = list.size() - 1;
                if (size <= 0) {
                    iterableR0 = EmptyList.f29203a;
                } else if (size == 1) {
                    if (listB1 instanceof List) {
                        objK1 = n.k1(listB1);
                    } else {
                        Iterator it2 = listB1.iterator();
                        if (!it2.hasNext()) {
                            throw new NoSuchElementException("Collection is empty.");
                        }
                        Object next = it2.next();
                        while (it2.hasNext()) {
                            next = it2.next();
                        }
                        objK1 = next;
                    }
                    iterableR0 = hb.a.l0(objK1);
                } else {
                    arrayList = new ArrayList(size);
                    if (listB1 instanceof List) {
                        if (listB1 instanceof RandomAccess) {
                            int size2 = list.size();
                            for (int i10 = 1; i10 < size2; i10++) {
                                arrayList.add(listB1.get(i10));
                            }
                        } else {
                            ListIterator listIterator = listB1.listIterator(1);
                            while (listIterator.hasNext()) {
                                arrayList.add(listIterator.next());
                            }
                        }
                        iterableR0 = arrayList;
                    }
                }
                it = iterableR0.iterator();
                while (it.hasNext()) {
                    sb.append("\t\t" + ((String) it.next()));
                    sb.append('\n');
                }
            }
            arrayList = new ArrayList();
            int i11 = 0;
            for (Object obj : listB1) {
                if (i11 >= 1) {
                    arrayList.add(obj);
                } else {
                    i11++;
                }
            }
            iterableR0 = hb.a.r0(arrayList);
            it = iterableR0.iterator();
            while (it.hasNext()) {
            }
        }
    }

    public final String toString() {
        return this.f4023a.toString();
    }
}
