package com.google.android.gms.internal.measurement; import java.lang.Comparable; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; /* loaded from: classes.dex */ class zzwo, V> extends AbstractMap { private final int a; private List b; private Map c; private boolean d; private volatile zzwx e; private Map f; private volatile zzwr g; private zzwo(int i) { this.a = i; this.b = Collections.emptyList(); this.c = Collections.emptyMap(); this.f = Collections.emptyMap(); } static > zzwo b(int i) { return new zzwp(i); } /* JADX INFO: Access modifiers changed from: private */ public final void f() { if (this.d) { throw new UnsupportedOperationException(); } } private final SortedMap g() { f(); if (this.c.isEmpty() && !(this.c instanceof TreeMap)) { this.c = new TreeMap(); this.f = ((TreeMap) this.c).descendingMap(); } return (SortedMap) this.c; } public final boolean a() { return this.d; } public final int c() { return this.b.size(); } @Override // java.util.AbstractMap, java.util.Map public void clear() { f(); 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 boolean containsKey(Object obj) { Comparable comparable = (Comparable) obj; return a((zzwo) comparable) >= 0 || this.c.containsKey(comparable); } public final Iterable> d() { return this.c.isEmpty() ? zzws.a() : this.c.entrySet(); } final Set> e() { if (this.g == null) { this.g = new zzwr(this, null); } return this.g; } @Override // java.util.AbstractMap, java.util.Map public Set> entrySet() { if (this.e == null) { this.e = new zzwx(this, null); } return this.e; } @Override // java.util.AbstractMap, java.util.Map public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof zzwo)) { return super.equals(obj); } zzwo zzwoVar = (zzwo) obj; int size = size(); if (size != zzwoVar.size()) { return false; } int c = c(); if (c != zzwoVar.c()) { return entrySet().equals(zzwoVar.entrySet()); } for (int i = 0; i < c; i++) { if (!a(i).equals(zzwoVar.a(i))) { return false; } } if (c != size) { return this.c.equals(zzwoVar.c); } return true; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map public V get(Object obj) { Comparable comparable = (Comparable) obj; int a = a((zzwo) comparable); return a >= 0 ? (V) this.b.get(a).getValue() : this.c.get(comparable); } @Override // java.util.AbstractMap, java.util.Map public int hashCode() { int c = c(); int i = 0; for (int i2 = 0; i2 < c; 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 /* synthetic */ Object put(Object obj, Object obj2) { return a((zzwo) obj, (Comparable) obj2); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map public V remove(Object obj) { f(); Comparable comparable = (Comparable) obj; int a = a((zzwo) comparable); if (a >= 0) { return (V) c(a); } if (this.c.isEmpty()) { return null; } return this.c.remove(comparable); } @Override // java.util.AbstractMap, java.util.Map public int size() { return this.b.size() + this.c.size(); } /* JADX INFO: Access modifiers changed from: private */ public final V c(int i) { f(); V v = (V) this.b.remove(i).getValue(); if (!this.c.isEmpty()) { Iterator> it = g().entrySet().iterator(); this.b.add(new zzwv(this, it.next())); it.remove(); } return v; } public final Map.Entry a(int i) { return this.b.get(i); } public void b() { if (this.d) { return; } this.c = this.c.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(this.c); this.f = this.f.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(this.f); this.d = true; } /* JADX WARN: Multi-variable type inference failed */ public final V a(K k, V v) { f(); int a = a((zzwo) k); if (a >= 0) { return (V) this.b.get(a).setValue(v); } f(); if (this.b.isEmpty() && !(this.b instanceof ArrayList)) { this.b = new ArrayList(this.a); } int i = -(a + 1); if (i >= this.a) { return g().put(k, v); } int size = this.b.size(); int i2 = this.a; if (size == i2) { zzwv remove = this.b.remove(i2 - 1); g().put((Comparable) remove.getKey(), remove.getValue()); } this.b.add(i, new zzwv(this, k, v)); return null; } /* synthetic */ zzwo(int i, zzwp zzwpVar) { this(i); } private final int a(K k) { int size = this.b.size() - 1; if (size >= 0) { int compareTo = k.compareTo((Comparable) this.b.get(size).getKey()); if (compareTo > 0) { return -(size + 2); } if (compareTo == 0) { return size; } } int i = 0; while (i <= size) { int i2 = (i + size) / 2; int compareTo2 = k.compareTo((Comparable) this.b.get(i2).getKey()); if (compareTo2 < 0) { size = i2 - 1; } else { if (compareTo2 <= 0) { return i2; } i = i2 + 1; } } return -(i + 1); } }