package com.google.android.gms.internal.ads; import java.util.AbstractMap; import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; /* loaded from: classes3.dex */ class zzhad extends AbstractMap { private Object[] zza; private int zzb; private boolean zzd; private volatile zzhab zze; private Map zzc = Collections.emptyMap(); private Map zzf = Collections.emptyMap(); private zzhad() { } private final int zzl(Comparable comparable) { int i = this.zzb; int i2 = i - 1; int i3 = 0; if (i2 >= 0) { int compareTo = comparable.compareTo(((zzgzz) this.zza[i2]).zza()); if (compareTo > 0) { return -(i + 1); } if (compareTo == 0) { return i2; } } while (i3 <= i2) { int i4 = (i3 + i2) / 2; int compareTo2 = comparable.compareTo(((zzgzz) this.zza[i4]).zza()); if (compareTo2 < 0) { i2 = i4 - 1; } else { if (compareTo2 <= 0) { return i4; } i3 = i4 + 1; } } return -(i3 + 1); } /* JADX INFO: Access modifiers changed from: private */ public final Object zzm(int i) { zzo(); Object value = ((zzgzz) this.zza[i]).getValue(); Object[] objArr = this.zza; System.arraycopy(objArr, i + 1, objArr, i, (this.zzb - i) - 1); this.zzb--; if (!this.zzc.isEmpty()) { Iterator it = zzn().entrySet().iterator(); Object[] objArr2 = this.zza; int i2 = this.zzb; Map.Entry entry = (Map.Entry) it.next(); objArr2[i2] = new zzgzz(this, (Comparable) entry.getKey(), entry.getValue()); this.zzb++; it.remove(); } return value; } private final SortedMap zzn() { zzo(); if (this.zzc.isEmpty() && !(this.zzc instanceof TreeMap)) { TreeMap treeMap = new TreeMap(); this.zzc = treeMap; this.zzf = treeMap.descendingMap(); } return (SortedMap) this.zzc; } /* JADX INFO: Access modifiers changed from: private */ public final void zzo() { if (this.zzd) { throw new UnsupportedOperationException(); } } @Override // java.util.AbstractMap, java.util.Map public final void clear() { zzo(); if (this.zzb != 0) { this.zza = null; this.zzb = 0; } if (this.zzc.isEmpty()) { return; } this.zzc.clear(); } @Override // java.util.AbstractMap, java.util.Map public final boolean containsKey(Object obj) { Comparable comparable = (Comparable) obj; return zzl(comparable) >= 0 || this.zzc.containsKey(comparable); } @Override // java.util.AbstractMap, java.util.Map public final Set entrySet() { if (this.zze == null) { this.zze = new zzhab(this, null); } return this.zze; } @Override // java.util.AbstractMap, java.util.Map public final boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof zzhad)) { return super.equals(obj); } zzhad zzhadVar = (zzhad) obj; int size = size(); if (size != zzhadVar.size()) { return false; } int i = this.zzb; if (i != zzhadVar.zzb) { return entrySet().equals(zzhadVar.entrySet()); } for (int i2 = 0; i2 < i; i2++) { if (!zzg(i2).equals(zzhadVar.zzg(i2))) { return false; } } if (i != size) { return this.zzc.equals(zzhadVar.zzc); } return true; } @Override // java.util.AbstractMap, java.util.Map public final Object get(Object obj) { Comparable comparable = (Comparable) obj; int zzl = zzl(comparable); return zzl >= 0 ? ((zzgzz) this.zza[zzl]).getValue() : this.zzc.get(comparable); } @Override // java.util.AbstractMap, java.util.Map public final int hashCode() { int i = this.zzb; int i2 = 0; for (int i3 = 0; i3 < i; i3++) { i2 += this.zza[i3].hashCode(); } return this.zzc.size() > 0 ? i2 + this.zzc.hashCode() : i2; } @Override // java.util.AbstractMap, java.util.Map public final Object remove(Object obj) { zzo(); Comparable comparable = (Comparable) obj; int zzl = zzl(comparable); if (zzl >= 0) { return zzm(zzl); } if (this.zzc.isEmpty()) { return null; } return this.zzc.remove(comparable); } @Override // java.util.AbstractMap, java.util.Map public final int size() { return this.zzb + this.zzc.size(); } public void zza() { if (this.zzd) { return; } this.zzc = this.zzc.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(this.zzc); this.zzf = this.zzf.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(this.zzf); this.zzd = true; } public final int zzc() { return this.zzb; } public final Iterable zzd() { return this.zzc.isEmpty() ? Collections.emptySet() : this.zzc.entrySet(); } @Override // java.util.AbstractMap, java.util.Map /* renamed from: zzf, reason: merged with bridge method [inline-methods] */ public final Object put(Comparable comparable, Object obj) { zzo(); int zzl = zzl(comparable); if (zzl >= 0) { return ((zzgzz) this.zza[zzl]).setValue(obj); } zzo(); if (this.zza == null) { this.zza = new Object[16]; } int i = -(zzl + 1); if (i >= 16) { return zzn().put(comparable, obj); } if (this.zzb == 16) { zzgzz zzgzzVar = (zzgzz) this.zza[15]; this.zzb = 15; zzn().put(zzgzzVar.zza(), zzgzzVar.getValue()); } Object[] objArr = this.zza; int length = objArr.length; System.arraycopy(objArr, i, objArr, i + 1, 15 - i); this.zza[i] = new zzgzz(this, comparable, obj); this.zzb++; return null; } public final boolean zzj() { return this.zzd; } public final Map.Entry zzg(int i) { if (i < this.zzb) { return (zzgzz) this.zza[i]; } throw new ArrayIndexOutOfBoundsException(i); } public /* synthetic */ zzhad(zzhac zzhacVar) { } }