package q;

import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;

/* loaded from: classes.dex */
public class b implements Iterable {

    /* renamed from: p, reason: collision with root package name */
    c f33082p;

    /* renamed from: q, reason: collision with root package name */
    private c f33083q;

    /* renamed from: r, reason: collision with root package name */
    private final WeakHashMap f33084r = new WeakHashMap();

    /* renamed from: s, reason: collision with root package name */
    private int f33085s = 0;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class a extends e {
        a(c cVar, c cVar2) {
            super(cVar, cVar2);
        }

        @Override // q.b.e
        c b(c cVar) {
            return cVar.f33089s;
        }

        @Override // q.b.e
        c c(c cVar) {
            return cVar.f33088r;
        }
    }

    /* renamed from: q.b$b, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    private static class C0761b extends e {
        C0761b(c cVar, c cVar2) {
            super(cVar, cVar2);
        }

        @Override // q.b.e
        c b(c cVar) {
            return cVar.f33088r;
        }

        @Override // q.b.e
        c c(c cVar) {
            return cVar.f33089s;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class c implements Map.Entry {

        /* renamed from: p, reason: collision with root package name */
        final Object f33086p;

        /* renamed from: q, reason: collision with root package name */
        final Object f33087q;

        /* renamed from: r, reason: collision with root package name */
        c f33088r;

        /* renamed from: s, reason: collision with root package name */
        c f33089s;

        c(Object obj, Object obj2) {
            this.f33086p = obj;
            this.f33087q = obj2;
        }

        @Override // java.util.Map.Entry
        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof c)) {
                return false;
            }
            c cVar = (c) obj;
            return this.f33086p.equals(cVar.f33086p) && this.f33087q.equals(cVar.f33087q);
        }

        @Override // java.util.Map.Entry
        public Object getKey() {
            return this.f33086p;
        }

        @Override // java.util.Map.Entry
        public Object getValue() {
            return this.f33087q;
        }

        @Override // java.util.Map.Entry
        public int hashCode() {
            return this.f33087q.hashCode() ^ this.f33086p.hashCode();
        }

        @Override // java.util.Map.Entry
        public Object setValue(Object obj) {
            throw new UnsupportedOperationException("An entry modification is not supported");
        }

        public String toString() {
            return this.f33086p + "=" + this.f33087q;
        }
    }

    /* loaded from: classes.dex */
    public class d extends f implements Iterator {

        /* renamed from: p, reason: collision with root package name */
        private c f33090p;

        /* renamed from: q, reason: collision with root package name */
        private boolean f33091q = true;

        d() {
        }

        @Override // q.b.f
        void a(c cVar) {
            c cVar2 = this.f33090p;
            if (cVar == cVar2) {
                c cVar3 = cVar2.f33089s;
                this.f33090p = cVar3;
                this.f33091q = cVar3 == null;
            }
        }

        @Override // java.util.Iterator
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public Map.Entry next() {
            if (this.f33091q) {
                this.f33091q = false;
                this.f33090p = b.this.f33082p;
            } else {
                c cVar = this.f33090p;
                this.f33090p = cVar != null ? cVar.f33088r : null;
            }
            return this.f33090p;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            if (this.f33091q) {
                return b.this.f33082p != null;
            }
            c cVar = this.f33090p;
            return (cVar == null || cVar.f33088r == null) ? false : true;
        }
    }

    /* loaded from: classes.dex */
    private static abstract class e extends f implements Iterator {

        /* renamed from: p, reason: collision with root package name */
        c f33093p;

        /* renamed from: q, reason: collision with root package name */
        c f33094q;

        e(c cVar, c cVar2) {
            this.f33093p = cVar2;
            this.f33094q = cVar;
        }

        private c e() {
            c cVar = this.f33094q;
            c cVar2 = this.f33093p;
            if (cVar == cVar2 || cVar2 == null) {
                return null;
            }
            return c(cVar);
        }

        @Override // q.b.f
        public void a(c cVar) {
            if (this.f33093p == cVar && cVar == this.f33094q) {
                this.f33094q = null;
                this.f33093p = null;
            }
            c cVar2 = this.f33093p;
            if (cVar2 == cVar) {
                this.f33093p = b(cVar2);
            }
            if (this.f33094q == cVar) {
                this.f33094q = e();
            }
        }

        abstract c b(c cVar);

        abstract c c(c cVar);

        @Override // java.util.Iterator
        /* renamed from: d, reason: merged with bridge method [inline-methods] */
        public Map.Entry next() {
            c cVar = this.f33094q;
            this.f33094q = e();
            return cVar;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.f33094q != null;
        }
    }

    /* loaded from: classes.dex */
    public static abstract class f {
        abstract void a(c cVar);
    }

    public Iterator descendingIterator() {
        C0761b c0761b = new C0761b(this.f33083q, this.f33082p);
        this.f33084r.put(c0761b, Boolean.FALSE);
        return c0761b;
    }

    public Map.Entry e() {
        return this.f33082p;
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof b)) {
            return false;
        }
        b bVar = (b) obj;
        if (size() != bVar.size()) {
            return false;
        }
        Iterator it = iterator();
        Iterator it2 = bVar.iterator();
        while (it.hasNext() && it2.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Object next = it2.next();
            if ((entry == null && next != null) || (entry != null && !entry.equals(next))) {
                return false;
            }
        }
        return (it.hasNext() || it2.hasNext()) ? false : true;
    }

    protected c g(Object obj) {
        c cVar = this.f33082p;
        while (cVar != null && !cVar.f33086p.equals(obj)) {
            cVar = cVar.f33088r;
        }
        return cVar;
    }

    public int hashCode() {
        Iterator it = iterator();
        int i10 = 0;
        while (it.hasNext()) {
            i10 += ((Map.Entry) it.next()).hashCode();
        }
        return i10;
    }

    public d i() {
        d dVar = new d();
        this.f33084r.put(dVar, Boolean.FALSE);
        return dVar;
    }

    @Override // java.lang.Iterable
    public Iterator iterator() {
        a aVar = new a(this.f33082p, this.f33083q);
        this.f33084r.put(aVar, Boolean.FALSE);
        return aVar;
    }

    public Map.Entry k() {
        return this.f33083q;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public c l(Object obj, Object obj2) {
        c cVar = new c(obj, obj2);
        this.f33085s++;
        c cVar2 = this.f33083q;
        if (cVar2 == null) {
            this.f33082p = cVar;
            this.f33083q = cVar;
            return cVar;
        }
        cVar2.f33088r = cVar;
        cVar.f33089s = cVar2;
        this.f33083q = cVar;
        return cVar;
    }

    public Object m(Object obj, Object obj2) {
        c g10 = g(obj);
        if (g10 != null) {
            return g10.f33087q;
        }
        l(obj, obj2);
        return null;
    }

    public Object n(Object obj) {
        c g10 = g(obj);
        if (g10 == null) {
            return null;
        }
        this.f33085s--;
        if (!this.f33084r.isEmpty()) {
            Iterator it = this.f33084r.keySet().iterator();
            while (it.hasNext()) {
                ((f) it.next()).a(g10);
            }
        }
        c cVar = g10.f33089s;
        if (cVar != null) {
            cVar.f33088r = g10.f33088r;
        } else {
            this.f33082p = g10.f33088r;
        }
        c cVar2 = g10.f33088r;
        if (cVar2 != null) {
            cVar2.f33089s = cVar;
        } else {
            this.f33083q = cVar;
        }
        g10.f33088r = null;
        g10.f33089s = null;
        return g10.f33087q;
    }

    public int size() {
        return this.f33085s;
    }

    public String toString() {
        StringBuilder sb2 = new StringBuilder();
        sb2.append("[");
        Iterator it = iterator();
        while (it.hasNext()) {
            sb2.append(((Map.Entry) it.next()).toString());
            if (it.hasNext()) {
                sb2.append(", ");
            }
        }
        sb2.append("]");
        return sb2.toString();
    }
}
