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; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class zzlx, V> extends AbstractMap { private final int zza; private boolean zzd; private volatile zzlw zze; private List zzb = Collections.emptyList(); private Map zzc = Collections.emptyMap(); private Map zzf = Collections.emptyMap(); private final int zzk(K k) { int size = this.zzb.size(); int i = size - 1; if (i >= 0) { int compareTo = k.compareTo(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 = k.compareTo(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 V zzl(int i) { zzn(); V v = (V) this.zzb.remove(i).getValue(); if (!this.zzc.isEmpty()) { Iterator> it = zzm().entrySet().iterator(); List list = this.zzb; Map.Entry next = it.next(); list.add(new zzlu(this, next.getKey(), next.getValue())); it.remove(); } return v; } 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(); } /* 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 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 zzlw(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 zzlx)) { return super.equals(obj); } zzlx zzlxVar = (zzlx) obj; int size = size(); if (size != zzlxVar.size()) { return false; } int zzb = zzb(); if (zzb != zzlxVar.zzb()) { return entrySet().equals(zzlxVar.entrySet()); } for (int i = 0; i < zzb; i++) { if (!zzg(i).equals(zzlxVar.zzg(i))) { return false; } } if (zzb != size) { return this.zzc.equals(zzlxVar.zzc); } 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 zzk = zzk(comparable); if (zzk >= 0) { return (V) 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 += this.zzb.get(i2).hashCode(); } return this.zzc.size() > 0 ? i + this.zzc.hashCode() : i; } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map public final V remove(Object obj) { zzn(); Comparable comparable = (Comparable) obj; int zzk = zzk(comparable); if (zzk >= 0) { return (V) 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() ? zzlt.zza() : this.zzc.entrySet(); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractMap, java.util.Map /* renamed from: zze, reason: merged with bridge method [inline-methods] */ public final V put(K k, V v) { zzn(); int zzk = zzk(k); if (zzk >= 0) { return (V) this.zzb.get(zzk).setValue(v); } 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(k, v); } int size = this.zzb.size(); int i2 = this.zza; if (size == i2) { zzlu remove = this.zzb.remove(i2 - 1); zzm().put(remove.zza(), remove.getValue()); } this.zzb.add(i, new zzlu(this, k, v)); return null; } public final Map.Entry zzg(int i) { return this.zzb.get(i); } public final boolean zzj() { return this.zzd; } }