package com.google.android.gms.internal.p002firebaseauthapi; 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; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class zzafj extends AbstractMap { private final int zza; private boolean zzd; private volatile zzafh zze; private List zzb = Collections.emptyList(); private Map zzc = Collections.emptyMap(); private Map zzf = Collections.emptyMap(); private final int zzk(Comparable comparable) { int size = this.zzb.size(); int i = size - 1; if (i >= 0) { int compareTo = comparable.compareTo(((zzafd) this.zzb.get(i)).zza()); if (compareTo <= 0) { if (compareTo == 0) { return i; } } return -(size + 1); } size = 0; while (size <= i) { int i2 = (size + i) / 2; int compareTo2 = comparable.compareTo(((zzafd) this.zzb.get(i2)).zza()); if (compareTo2 < 0) { i = i2 - 1; } else { if (compareTo2 <= 0) { return i2; } size = i2 + 1; } } return -(size + 1); } /* JADX INFO: Access modifiers changed from: private */ public final Object zzl(int i) { zzn(); Object value = ((zzafd) this.zzb.remove(i)).getValue(); if (!this.zzc.isEmpty()) { Iterator it = zzm().entrySet().iterator(); List list = this.zzb; Map.Entry entry = (Map.Entry) it.next(); list.add(new zzafd(this, (Comparable) entry.getKey(), entry.getValue())); it.remove(); } return value; } private final SortedMap zzm() { zzn(); 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 zzn() { if (this.zzd) { throw new UnsupportedOperationException(); } } @Override // java.util.AbstractMap, java.util.Map public final void clear() { zzn(); if (!this.zzb.isEmpty()) { this.zzb.clear(); } 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 zzk(comparable) >= 0 || this.zzc.containsKey(comparable); } @Override // java.util.AbstractMap, java.util.Map public final Set entrySet() { if (this.zze == null) { this.zze = new zzafh(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 zzafj)) { return super.equals(obj); } zzafj zzafjVar = (zzafj) obj; int size = size(); if (size != zzafjVar.size()) { return false; } int zzb = zzb(); if (zzb != zzafjVar.zzb()) { return entrySet().equals(zzafjVar.entrySet()); } for (int i = 0; i < zzb; i++) { if (!zzg(i).equals(zzafjVar.zzg(i))) { return false; } } if (zzb != size) { return this.zzc.equals(zzafjVar.zzc); } return true; } @Override // java.util.AbstractMap, java.util.Map public final Object get(Object obj) { Comparable comparable = (Comparable) obj; int zzk = zzk(comparable); if (zzk >= 0) { return ((zzafd) this.zzb.get(zzk)).getValue(); } return this.zzc.get(comparable); } @Override // java.util.AbstractMap, java.util.Map public final int hashCode() { int zzb = zzb(); int i = 0; for (int i2 = 0; i2 < zzb; i2++) { i += ((zzafd) this.zzb.get(i2)).hashCode(); } return this.zzc.size() > 0 ? i + this.zzc.hashCode() : i; } @Override // java.util.AbstractMap, java.util.Map public final Object remove(Object obj) { zzn(); Comparable comparable = (Comparable) obj; int zzk = zzk(comparable); if (zzk >= 0) { return zzl(zzk); } 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.size() + this.zzc.size(); } public void zza() { Map unmodifiableMap; Map unmodifiableMap2; if (this.zzd) { return; } if (this.zzc.isEmpty()) { unmodifiableMap = Collections.emptyMap(); } else { unmodifiableMap = Collections.unmodifiableMap(this.zzc); } this.zzc = unmodifiableMap; if (this.zzf.isEmpty()) { unmodifiableMap2 = Collections.emptyMap(); } else { unmodifiableMap2 = Collections.unmodifiableMap(this.zzf); } this.zzf = unmodifiableMap2; this.zzd = true; } public final int zzb() { return this.zzb.size(); } public final Iterable zzc() { return this.zzc.isEmpty() ? zzafc.zza() : this.zzc.entrySet(); } @Override // java.util.AbstractMap, java.util.Map /* renamed from: zze, reason: merged with bridge method [inline-methods] */ public final Object put(Comparable comparable, Object obj) { zzn(); int zzk = zzk(comparable); if (zzk >= 0) { return ((zzafd) this.zzb.get(zzk)).setValue(obj); } zzn(); if (this.zzb.isEmpty() && !(this.zzb instanceof ArrayList)) { this.zzb = new ArrayList(this.zza); } int i = -(zzk + 1); if (i >= this.zza) { return zzm().put(comparable, obj); } int size = this.zzb.size(); int i2 = this.zza; if (size == i2) { zzafd zzafdVar = (zzafd) this.zzb.remove(i2 - 1); zzm().put(zzafdVar.zza(), zzafdVar.getValue()); } this.zzb.add(i, new zzafd(this, comparable, obj)); return null; } public final Map.Entry zzg(int i) { return (Map.Entry) this.zzb.get(i); } public final boolean zzj() { return this.zzd; } }