package com.fyber.inneractive.sdk.protobuf; import com.ironsource.v8; import java.lang.Comparable; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; /* loaded from: classes2.dex */ public class g1, V> extends AbstractMap { public static final /* synthetic */ int h = 0; public final int a; public List.d> b; public Map c; public boolean d; public volatile g1.f e; public Map f; public volatile g1.b g; public class a implements Iterator> { public int a; public Iterator> b; public a() { this.a = g1.this.b.size(); } @Override // java.util.Iterator public final void remove() { throw new UnsupportedOperationException(); } @Override // java.util.Iterator public final boolean hasNext() { int i = this.a; if (i <= 0 || i > g1.this.b.size()) { if (this.b == null) { this.b = g1.this.f.entrySet().iterator(); } if (!this.b.hasNext()) { return false; } } return true; } @Override // java.util.Iterator public final Object next() { if (this.b == null) { this.b = g1.this.f.entrySet().iterator(); } if (this.b.hasNext()) { if (this.b == null) { this.b = g1.this.f.entrySet().iterator(); } return this.b.next(); } List.d> list = g1.this.b; int i = this.a - 1; this.a = i; return list.get(i); } } public class b extends g1.f { public b() { super(g1.this, 0); } @Override // com.fyber.inneractive.sdk.protobuf.g1.f, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public final Iterator> iterator() { return new a(); } } public static class c { public static final a a = new a(); public static final b b = new b(); public class a implements Iterator { @Override // java.util.Iterator public final boolean hasNext() { return false; } @Override // java.util.Iterator public final Object next() { throw new NoSuchElementException(); } @Override // java.util.Iterator public final void remove() { throw new UnsupportedOperationException(); } } public class b implements Iterable { @Override // java.lang.Iterable public final Iterator iterator() { return c.a; } } } public class d implements Map.Entry, Comparable.d> { public final K a; public V b; public d() { throw null; } public d(K k, V v) { this.a = k; this.b = v; } @Override // java.lang.Comparable public final int compareTo(Object obj) { return this.a.compareTo(((d) obj).a); } @Override // java.util.Map.Entry public final boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; K k = this.a; Object key = entry.getKey(); if (k != null ? k.equals(key) : key == null) { V v = this.b; Object value = entry.getValue(); if (v == null) { if (value == null) { return true; } } else if (v.equals(value)) { return true; } } return false; } @Override // java.util.Map.Entry public final Object getKey() { return this.a; } @Override // java.util.Map.Entry public final V getValue() { return this.b; } @Override // java.util.Map.Entry public final int hashCode() { K k = this.a; int hashCode = k == null ? 0 : k.hashCode(); V v = this.b; return hashCode ^ (v != null ? v.hashCode() : 0); } @Override // java.util.Map.Entry public final V setValue(V v) { g1 g1Var = g1.this; int i = g1.h; g1Var.a(); V v2 = this.b; this.b = v; return v2; } public final String toString() { return this.a + v8.i.b + this.b; } } public class e implements Iterator> { public int a = -1; public boolean b; public Iterator> c; public e() { } @Override // java.util.Iterator public final boolean hasNext() { if (this.a + 1 < g1.this.b.size()) { return true; } if (!g1.this.c.isEmpty()) { if (this.c == null) { this.c = g1.this.c.entrySet().iterator(); } if (this.c.hasNext()) { return true; } } return false; } @Override // java.util.Iterator public final Object next() { this.b = true; int i = this.a + 1; this.a = i; if (i < g1.this.b.size()) { return g1.this.b.get(this.a); } if (this.c == null) { this.c = g1.this.c.entrySet().iterator(); } return this.c.next(); } @Override // java.util.Iterator public final void remove() { if (this.b) { this.b = false; g1 g1Var = g1.this; int i = g1.h; g1Var.a(); if (this.a < g1.this.b.size()) { g1 g1Var2 = g1.this; int i2 = this.a; this.a = i2 - 1; g1Var2.c(i2); return; } if (this.c == null) { this.c = g1.this.c.entrySet().iterator(); } this.c.remove(); return; } throw new IllegalStateException("remove() was called before next()"); } } public class f extends AbstractSet> { public f() { } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean add(Object obj) { Map.Entry entry = (Map.Entry) obj; if (contains(entry)) { return false; } g1.this.put((Comparable) entry.getKey(), entry.getValue()); return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final void clear() { g1.this.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean contains(Object obj) { Map.Entry entry = (Map.Entry) obj; Object obj2 = g1.this.get(entry.getKey()); Object value = entry.getValue(); return obj2 == value || (obj2 != null && obj2.equals(value)); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator> iterator() { return new e(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean remove(Object obj) { Map.Entry entry = (Map.Entry) obj; if (!contains(entry)) { return false; } g1.this.remove(entry.getKey()); return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final int size() { return g1.this.size(); } public /* synthetic */ f(g1 g1Var, int i) { this(); } } public /* synthetic */ g1(int i, int i2) { this(i); } public static f1 b(int i) { return new f1(i); } @Override // java.util.AbstractMap, java.util.Map public final void clear() { a(); if (!this.b.isEmpty()) { this.b.clear(); } if (this.c.isEmpty()) { return; } this.c.clear(); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map public final boolean containsKey(Object obj) { Comparable comparable = (Comparable) obj; return a((g1) comparable) >= 0 || this.c.containsKey(comparable); } @Override // java.util.AbstractMap, java.util.Map public final boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof g1)) { return super.equals(obj); } g1 g1Var = (g1) obj; int size = size(); if (size != g1Var.size()) { return false; } int size2 = this.b.size(); if (size2 != g1Var.b.size()) { return entrySet().equals(g1Var.entrySet()); } for (int i = 0; i < size2; i++) { if (!a(i).equals(g1Var.a(i))) { return false; } } if (size2 != size) { return this.c.equals(g1Var.c); } return true; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map public final V get(Object obj) { Comparable comparable = (Comparable) obj; int a2 = a((g1) comparable); return a2 >= 0 ? this.b.get(a2).b : this.c.get(comparable); } @Override // java.util.AbstractMap, java.util.Map public final int hashCode() { int size = this.b.size(); int i = 0; for (int i2 = 0; i2 < size; i2++) { i += this.b.get(i2).hashCode(); } return this.c.size() > 0 ? i + this.c.hashCode() : i; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map public final V remove(Object obj) { a(); Comparable comparable = (Comparable) obj; int a2 = a((g1) comparable); if (a2 < 0) { if (this.c.isEmpty()) { return null; } return this.c.remove(comparable); } a(); V v = this.b.remove(a2).b; if (!this.c.isEmpty()) { a(); if (this.c.isEmpty() && !(this.c instanceof TreeMap)) { TreeMap treeMap = new TreeMap(); this.c = treeMap; this.f = treeMap.descendingMap(); } Iterator it = ((SortedMap) this.c).entrySet().iterator(); List.d> list = this.b; Map.Entry entry = (Map.Entry) it.next(); list.add(new d((Comparable) entry.getKey(), entry.getValue())); it.remove(); } return v; } @Override // java.util.AbstractMap, java.util.Map public final int size() { return this.c.size() + this.b.size(); } public g1(int i) { this.a = i; this.b = Collections.emptyList(); this.c = Collections.emptyMap(); this.f = Collections.emptyMap(); } public final Map.Entry a(int i) { return this.b.get(i); } public final Iterable> b() { return this.c.isEmpty() ? c.b : this.c.entrySet(); } @Override // java.util.AbstractMap, java.util.Map public final Set> entrySet() { if (this.e == null) { this.e = new f(); } return this.e; } @Override // java.util.AbstractMap, java.util.Map /* renamed from: a, reason: merged with bridge method [inline-methods] */ public final V put(K k, V v) { a(); int a2 = a((g1) k); if (a2 >= 0) { return this.b.get(a2).setValue(v); } a(); if (this.b.isEmpty() && !(this.b instanceof ArrayList)) { this.b = new ArrayList(this.a); } int i = -(a2 + 1); if (i >= this.a) { a(); if (this.c.isEmpty() && !(this.c instanceof TreeMap)) { TreeMap treeMap = new TreeMap(); this.c = treeMap; this.f = treeMap.descendingMap(); } return (V) ((SortedMap) this.c).put(k, v); } int size = this.b.size(); int i2 = this.a; if (size == i2) { g1.d remove = this.b.remove(i2 - 1); a(); if (this.c.isEmpty() && !(this.c instanceof TreeMap)) { TreeMap treeMap2 = new TreeMap(); this.c = treeMap2; this.f = treeMap2.descendingMap(); } ((SortedMap) this.c).put(remove.a, remove.b); } this.b.add(i, new d(k, v)); return null; } public void c() { Map unmodifiableMap; Map unmodifiableMap2; if (this.d) { return; } if (this.c.isEmpty()) { unmodifiableMap = Collections.emptyMap(); } else { unmodifiableMap = Collections.unmodifiableMap(this.c); } this.c = unmodifiableMap; if (this.f.isEmpty()) { unmodifiableMap2 = Collections.emptyMap(); } else { unmodifiableMap2 = Collections.unmodifiableMap(this.f); } this.f = unmodifiableMap2; this.d = true; } public final V c(int i) { a(); V v = this.b.remove(i).b; if (!this.c.isEmpty()) { a(); if (this.c.isEmpty() && !(this.c instanceof TreeMap)) { TreeMap treeMap = new TreeMap(); this.c = treeMap; this.f = treeMap.descendingMap(); } Iterator it = ((SortedMap) this.c).entrySet().iterator(); List.d> list = this.b; Map.Entry entry = (Map.Entry) it.next(); list.add(new d((Comparable) entry.getKey(), entry.getValue())); it.remove(); } return v; } public final int a(K k) { int i; int size = this.b.size(); int i2 = size - 1; if (i2 >= 0) { int compareTo = k.compareTo(this.b.get(i2).a); if (compareTo > 0) { i = size + 1; return -i; } if (compareTo == 0) { return i2; } } int i3 = 0; while (i3 <= i2) { int i4 = (i3 + i2) / 2; int compareTo2 = k.compareTo(this.b.get(i4).a); if (compareTo2 < 0) { i2 = i4 - 1; } else { if (compareTo2 <= 0) { return i4; } i3 = i4 + 1; } } i = i3 + 1; return -i; } public final void a() { if (this.d) { throw new UnsupportedOperationException(); } } }