package p034l;

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

/* renamed from: l.b */
/* loaded from: classes.dex */
public class C1408b<K, V> implements Iterable<Map.Entry<K, V>> {

    /* renamed from: d */
    public C1411c<K, V> f3122d;

    /* renamed from: e */
    public C1411c<K, V> f3123e;

    /* renamed from: f */
    public WeakHashMap<InterfaceC1414f<K, V>, Boolean> f3124f = new WeakHashMap<>();

    /* renamed from: g */
    public int f3125g = 0;

    /* renamed from: l.b$a */
    /* loaded from: classes.dex */
    public static class C1409a<K, V> extends AbstractC1413e<K, V> {
        public C1409a(C1411c<K, V> c1411c, C1411c<K, V> c1411c2) {
            super(c1411c, c1411c2);
        }

        @Override // p034l.C1408b.AbstractC1413e
        /* renamed from: b */
        public C1411c<K, V> mo1399b(C1411c<K, V> c1411c) {
            return c1411c.f3129g;
        }

        @Override // p034l.C1408b.AbstractC1413e
        /* renamed from: c */
        public C1411c<K, V> mo1398c(C1411c<K, V> c1411c) {
            return c1411c.f3128f;
        }
    }

    /* renamed from: l.b$b */
    /* loaded from: classes.dex */
    public static class C1410b<K, V> extends AbstractC1413e<K, V> {
        public C1410b(C1411c<K, V> c1411c, C1411c<K, V> c1411c2) {
            super(c1411c, c1411c2);
        }

        @Override // p034l.C1408b.AbstractC1413e
        /* renamed from: b */
        public C1411c<K, V> mo1399b(C1411c<K, V> c1411c) {
            return c1411c.f3128f;
        }

        @Override // p034l.C1408b.AbstractC1413e
        /* renamed from: c */
        public C1411c<K, V> mo1398c(C1411c<K, V> c1411c) {
            return c1411c.f3129g;
        }
    }

    /* renamed from: l.b$c */
    /* loaded from: classes.dex */
    public static class C1411c<K, V> implements Map.Entry<K, V> {

        /* renamed from: d */
        public final K f3126d;

        /* renamed from: e */
        public final V f3127e;

        /* renamed from: f */
        public C1411c<K, V> f3128f;

        /* renamed from: g */
        public C1411c<K, V> f3129g;

        public C1411c(K k, V v) {
            this.f3126d = k;
            this.f3127e = v;
        }

        @Override // java.util.Map.Entry
        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (obj instanceof C1411c) {
                C1411c c1411c = (C1411c) obj;
                return this.f3126d.equals(c1411c.f3126d) && this.f3127e.equals(c1411c.f3127e);
            }
            return false;
        }

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

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

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

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

        public String toString() {
            return this.f3126d + "=" + this.f3127e;
        }
    }

    /* renamed from: l.b$d */
    /* loaded from: classes.dex */
    public class C1412d implements Iterator<Map.Entry<K, V>>, InterfaceC1414f<K, V> {

        /* renamed from: d */
        public C1411c<K, V> f3130d;

        /* renamed from: e */
        public boolean f3131e = true;

        public C1412d() {
        }

        @Override // p034l.C1408b.InterfaceC1414f
        /* renamed from: a */
        public void mo1395a(C1411c<K, V> c1411c) {
            C1411c<K, V> c1411c2 = this.f3130d;
            if (c1411c == c1411c2) {
                C1411c<K, V> c1411c3 = c1411c2.f3129g;
                this.f3130d = c1411c3;
                this.f3131e = c1411c3 == null;
            }
        }

        @Override // java.util.Iterator
        /* renamed from: b */
        public Map.Entry<K, V> next() {
            C1411c<K, V> c1411c;
            if (this.f3131e) {
                this.f3131e = false;
                c1411c = C1408b.this.f3122d;
            } else {
                C1411c<K, V> c1411c2 = this.f3130d;
                c1411c = c1411c2 != null ? c1411c2.f3128f : null;
            }
            this.f3130d = c1411c;
            return this.f3130d;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            if (this.f3131e) {
                return C1408b.this.f3122d != null;
            }
            C1411c<K, V> c1411c = this.f3130d;
            return (c1411c == null || c1411c.f3128f == null) ? false : true;
        }
    }

    /* renamed from: l.b$e */
    /* loaded from: classes.dex */
    public static abstract class AbstractC1413e<K, V> implements Iterator<Map.Entry<K, V>>, InterfaceC1414f<K, V> {

        /* renamed from: d */
        public C1411c<K, V> f3133d;

        /* renamed from: e */
        public C1411c<K, V> f3134e;

        public AbstractC1413e(C1411c<K, V> c1411c, C1411c<K, V> c1411c2) {
            this.f3133d = c1411c2;
            this.f3134e = c1411c;
        }

        @Override // p034l.C1408b.InterfaceC1414f
        /* renamed from: a */
        public void mo1395a(C1411c<K, V> c1411c) {
            if (this.f3133d == c1411c && c1411c == this.f3134e) {
                this.f3134e = null;
                this.f3133d = null;
            }
            C1411c<K, V> c1411c2 = this.f3133d;
            if (c1411c2 == c1411c) {
                this.f3133d = mo1399b(c1411c2);
            }
            if (this.f3134e == c1411c) {
                this.f3134e = m1396e();
            }
        }

        /* renamed from: b */
        public abstract C1411c<K, V> mo1399b(C1411c<K, V> c1411c);

        /* renamed from: c */
        public abstract C1411c<K, V> mo1398c(C1411c<K, V> c1411c);

        @Override // java.util.Iterator
        /* renamed from: d */
        public Map.Entry<K, V> next() {
            C1411c<K, V> c1411c = this.f3134e;
            this.f3134e = m1396e();
            return c1411c;
        }

        /* renamed from: e */
        public final C1411c<K, V> m1396e() {
            C1411c<K, V> c1411c = this.f3134e;
            C1411c<K, V> c1411c2 = this.f3133d;
            if (c1411c == c1411c2 || c1411c2 == null) {
                return null;
            }
            return mo1398c(c1411c);
        }

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

    /* renamed from: l.b$f */
    /* loaded from: classes.dex */
    public interface InterfaceC1414f<K, V> {
        /* renamed from: a */
        void mo1395a(C1411c<K, V> c1411c);
    }

    /* renamed from: a */
    public Map.Entry<K, V> m1407a() {
        return this.f3122d;
    }

    /* renamed from: b */
    public C1411c<K, V> mo1406b(K k) {
        C1411c<K, V> c1411c = this.f3122d;
        while (c1411c != null && !c1411c.f3126d.equals(k)) {
            c1411c = c1411c.f3128f;
        }
        return c1411c;
    }

    /* renamed from: c */
    public C1408b<K, V>.C1412d m1405c() {
        C1408b<K, V>.C1412d c1412d = new C1412d();
        this.f3124f.put(c1412d, Boolean.FALSE);
        return c1412d;
    }

    /* renamed from: d */
    public Map.Entry<K, V> m1404d() {
        return this.f3123e;
    }

    public Iterator<Map.Entry<K, V>> descendingIterator() {
        C1410b c1410b = new C1410b(this.f3123e, this.f3122d);
        this.f3124f.put(c1410b, Boolean.FALSE);
        return c1410b;
    }

    /* renamed from: e */
    public C1411c<K, V> m1403e(K k, V v) {
        C1411c<K, V> c1411c = new C1411c<>(k, v);
        this.f3125g++;
        C1411c<K, V> c1411c2 = this.f3123e;
        if (c1411c2 == null) {
            this.f3122d = c1411c;
        } else {
            c1411c2.f3128f = c1411c;
            c1411c.f3129g = c1411c2;
        }
        this.f3123e = c1411c;
        return c1411c;
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof C1408b) {
            C1408b c1408b = (C1408b) obj;
            if (size() != c1408b.size()) {
                return false;
            }
            Iterator<Map.Entry<K, V>> it = iterator();
            Iterator<Map.Entry<K, V>> it2 = c1408b.iterator();
            while (it.hasNext() && it2.hasNext()) {
                Map.Entry<K, V> next = it.next();
                Map.Entry<K, V> next2 = it2.next();
                if ((next == null && next2 != null) || (next != null && !next.equals(next2))) {
                    return false;
                }
            }
            return (it.hasNext() || it2.hasNext()) ? false : true;
        }
        return false;
    }

    /* renamed from: f */
    public V mo1402f(K k, V v) {
        C1411c<K, V> mo1406b = mo1406b(k);
        if (mo1406b != null) {
            return mo1406b.f3127e;
        }
        m1403e(k, v);
        return null;
    }

    /* renamed from: g */
    public V mo1401g(K k) {
        C1411c<K, V> mo1406b = mo1406b(k);
        if (mo1406b == null) {
            return null;
        }
        this.f3125g--;
        if (!this.f3124f.isEmpty()) {
            for (InterfaceC1414f<K, V> interfaceC1414f : this.f3124f.keySet()) {
                interfaceC1414f.mo1395a(mo1406b);
            }
        }
        C1411c<K, V> c1411c = mo1406b.f3129g;
        C1411c<K, V> c1411c2 = mo1406b.f3128f;
        if (c1411c != null) {
            c1411c.f3128f = c1411c2;
        } else {
            this.f3122d = c1411c2;
        }
        C1411c<K, V> c1411c3 = mo1406b.f3128f;
        if (c1411c3 != null) {
            c1411c3.f3129g = c1411c;
        } else {
            this.f3123e = c1411c;
        }
        mo1406b.f3128f = null;
        mo1406b.f3129g = null;
        return mo1406b.f3127e;
    }

    public int hashCode() {
        Iterator<Map.Entry<K, V>> it = iterator();
        int i = 0;
        while (it.hasNext()) {
            i += it.next().hashCode();
        }
        return i;
    }

    @Override // java.lang.Iterable
    public Iterator<Map.Entry<K, V>> iterator() {
        C1409a c1409a = new C1409a(this.f3122d, this.f3123e);
        this.f3124f.put(c1409a, Boolean.FALSE);
        return c1409a;
    }

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

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