package androidx.collection; import java.lang.reflect.Array; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; /* loaded from: classes.dex */ abstract class MapCollections { MapCollections.EntrySet a; MapCollections.KeySet b; MapCollections.ValuesCollection c; final class ArrayIterator implements Iterator { final int a; int b; int c; boolean d = false; ArrayIterator(int i) { this.a = i; this.b = MapCollections.this.c(); } @Override // java.util.Iterator public boolean hasNext() { return this.c < this.b; } @Override // java.util.Iterator public T next() { if (!hasNext()) { throw new NoSuchElementException(); } T t = (T) MapCollections.this.a(this.c, this.a); this.c++; this.d = true; return t; } @Override // java.util.Iterator public void remove() { if (!this.d) { throw new IllegalStateException(); } this.c--; this.b--; this.d = false; MapCollections.this.a(this.c); } } final class EntrySet implements Set> { EntrySet() { } public boolean a(Map.Entry entry) { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public /* bridge */ /* synthetic */ boolean add(Object obj) { a((Map.Entry) obj); throw null; } @Override // java.util.Set, java.util.Collection public boolean addAll(Collection> collection) { int c = MapCollections.this.c(); for (Map.Entry entry : collection) { MapCollections.this.a((MapCollections) entry.getKey(), (K) entry.getValue()); } return c != MapCollections.this.c(); } @Override // java.util.Set, java.util.Collection public void clear() { MapCollections.this.a(); } @Override // java.util.Set, java.util.Collection public boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; int a = MapCollections.this.a(entry.getKey()); if (a < 0) { return false; } return ContainerHelpers.a(MapCollections.this.a(a, 1), entry.getValue()); } @Override // java.util.Set, java.util.Collection public boolean containsAll(Collection collection) { Iterator it = collection.iterator(); while (it.hasNext()) { if (!contains(it.next())) { return false; } } return true; } @Override // java.util.Set, java.util.Collection public boolean equals(Object obj) { return MapCollections.a((Set) this, obj); } @Override // java.util.Set, java.util.Collection public int hashCode() { int i = 0; for (int c = MapCollections.this.c() - 1; c >= 0; c--) { Object a = MapCollections.this.a(c, 0); Object a2 = MapCollections.this.a(c, 1); i += (a == null ? 0 : a.hashCode()) ^ (a2 == null ? 0 : a2.hashCode()); } return i; } @Override // java.util.Set, java.util.Collection public boolean isEmpty() { return MapCollections.this.c() == 0; } @Override // java.util.Set, java.util.Collection, java.lang.Iterable public Iterator> iterator() { return new MapIterator(); } @Override // java.util.Set, java.util.Collection public boolean remove(Object obj) { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public boolean removeAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public boolean retainAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public int size() { return MapCollections.this.c(); } @Override // java.util.Set, java.util.Collection public Object[] toArray() { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public T[] toArray(T[] tArr) { throw new UnsupportedOperationException(); } } final class KeySet implements Set { KeySet() { } @Override // java.util.Set, java.util.Collection public boolean add(K k) { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public boolean addAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // java.util.Set, java.util.Collection public void clear() { MapCollections.this.a(); } @Override // java.util.Set, java.util.Collection public boolean contains(Object obj) { return MapCollections.this.a(obj) >= 0; } @Override // java.util.Set, java.util.Collection public boolean containsAll(Collection collection) { return MapCollections.a((Map) MapCollections.this.b(), collection); } @Override // java.util.Set, java.util.Collection public boolean equals(Object obj) { return MapCollections.a((Set) this, obj); } @Override // java.util.Set, java.util.Collection public int hashCode() { int i = 0; for (int c = MapCollections.this.c() - 1; c >= 0; c--) { Object a = MapCollections.this.a(c, 0); i += a == null ? 0 : a.hashCode(); } return i; } @Override // java.util.Set, java.util.Collection public boolean isEmpty() { return MapCollections.this.c() == 0; } @Override // java.util.Set, java.util.Collection, java.lang.Iterable public Iterator iterator() { return new ArrayIterator(0); } @Override // java.util.Set, java.util.Collection public boolean remove(Object obj) { int a = MapCollections.this.a(obj); if (a < 0) { return false; } MapCollections.this.a(a); return true; } @Override // java.util.Set, java.util.Collection public boolean removeAll(Collection collection) { return MapCollections.b(MapCollections.this.b(), collection); } @Override // java.util.Set, java.util.Collection public boolean retainAll(Collection collection) { return MapCollections.c(MapCollections.this.b(), collection); } @Override // java.util.Set, java.util.Collection public int size() { return MapCollections.this.c(); } @Override // java.util.Set, java.util.Collection public Object[] toArray() { return MapCollections.this.b(0); } @Override // java.util.Set, java.util.Collection public T[] toArray(T[] tArr) { return (T[]) MapCollections.this.a(tArr, 0); } } final class MapIterator implements Iterator>, Map.Entry { int a; boolean c = false; int b = -1; MapIterator() { this.a = MapCollections.this.c() - 1; } @Override // java.util.Map.Entry public boolean equals(Object obj) { if (!this.c) { throw new IllegalStateException("This container does not support retaining Map.Entry objects"); } if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return ContainerHelpers.a(entry.getKey(), MapCollections.this.a(this.b, 0)) && ContainerHelpers.a(entry.getValue(), MapCollections.this.a(this.b, 1)); } @Override // java.util.Map.Entry public K getKey() { if (this.c) { return (K) MapCollections.this.a(this.b, 0); } throw new IllegalStateException("This container does not support retaining Map.Entry objects"); } @Override // java.util.Map.Entry public V getValue() { if (this.c) { return (V) MapCollections.this.a(this.b, 1); } throw new IllegalStateException("This container does not support retaining Map.Entry objects"); } @Override // java.util.Iterator public boolean hasNext() { return this.b < this.a; } @Override // java.util.Map.Entry public int hashCode() { if (!this.c) { throw new IllegalStateException("This container does not support retaining Map.Entry objects"); } Object a = MapCollections.this.a(this.b, 0); Object a2 = MapCollections.this.a(this.b, 1); return (a == null ? 0 : a.hashCode()) ^ (a2 != null ? a2.hashCode() : 0); } @Override // java.util.Iterator public /* bridge */ /* synthetic */ Object next() { next(); return this; } @Override // java.util.Iterator public void remove() { if (!this.c) { throw new IllegalStateException(); } MapCollections.this.a(this.b); this.b--; this.a--; this.c = false; } @Override // java.util.Map.Entry public V setValue(V v) { if (this.c) { return (V) MapCollections.this.a(this.b, (int) v); } throw new IllegalStateException("This container does not support retaining Map.Entry objects"); } public String toString() { return getKey() + "=" + getValue(); } @Override // java.util.Iterator public Map.Entry next() { if (!hasNext()) { throw new NoSuchElementException(); } this.b++; this.c = true; return this; } } final class ValuesCollection implements Collection { ValuesCollection() { } @Override // java.util.Collection public boolean add(V v) { throw new UnsupportedOperationException(); } @Override // java.util.Collection public boolean addAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // java.util.Collection public void clear() { MapCollections.this.a(); } @Override // java.util.Collection public boolean contains(Object obj) { return MapCollections.this.b(obj) >= 0; } @Override // java.util.Collection public boolean containsAll(Collection collection) { Iterator it = collection.iterator(); while (it.hasNext()) { if (!contains(it.next())) { return false; } } return true; } @Override // java.util.Collection public boolean isEmpty() { return MapCollections.this.c() == 0; } @Override // java.util.Collection, java.lang.Iterable public Iterator iterator() { return new ArrayIterator(1); } @Override // java.util.Collection public boolean remove(Object obj) { int b = MapCollections.this.b(obj); if (b < 0) { return false; } MapCollections.this.a(b); return true; } @Override // java.util.Collection public boolean removeAll(Collection collection) { int c = MapCollections.this.c(); int i = 0; boolean z = false; while (i < c) { if (collection.contains(MapCollections.this.a(i, 1))) { MapCollections.this.a(i); i--; c--; z = true; } i++; } return z; } @Override // java.util.Collection public boolean retainAll(Collection collection) { int c = MapCollections.this.c(); int i = 0; boolean z = false; while (i < c) { if (!collection.contains(MapCollections.this.a(i, 1))) { MapCollections.this.a(i); i--; c--; z = true; } i++; } return z; } @Override // java.util.Collection public int size() { return MapCollections.this.c(); } @Override // java.util.Collection public Object[] toArray() { return MapCollections.this.b(1); } @Override // java.util.Collection public T[] toArray(T[] tArr) { return (T[]) MapCollections.this.a(tArr, 1); } } MapCollections() { } public static boolean a(Map map, Collection collection) { Iterator it = collection.iterator(); while (it.hasNext()) { if (!map.containsKey(it.next())) { return false; } } return true; } public static boolean b(Map map, Collection collection) { int size = map.size(); Iterator it = collection.iterator(); while (it.hasNext()) { map.remove(it.next()); } return size != map.size(); } public static boolean c(Map map, Collection collection) { int size = map.size(); Iterator it = map.keySet().iterator(); while (it.hasNext()) { if (!collection.contains(it.next())) { it.remove(); } } return size != map.size(); } protected abstract int a(Object obj); protected abstract Object a(int i, int i2); protected abstract V a(int i, V v); protected abstract void a(); protected abstract void a(int i); protected abstract void a(K k, V v); protected abstract int b(Object obj); protected abstract Map b(); protected abstract int c(); public Set> d() { if (this.a == null) { this.a = new EntrySet(); } return this.a; } public Set e() { if (this.b == null) { this.b = new KeySet(); } return this.b; } public Collection f() { if (this.c == null) { this.c = new ValuesCollection(); } return this.c; } public T[] a(T[] tArr, int i) { int c = c(); if (tArr.length < c) { tArr = (T[]) ((Object[]) Array.newInstance(tArr.getClass().getComponentType(), c)); } for (int i2 = 0; i2 < c; i2++) { tArr[i2] = a(i2, i); } if (tArr.length > c) { tArr[c] = null; } return tArr; } public Object[] b(int i) { int c = c(); Object[] objArr = new Object[c]; for (int i2 = 0; i2 < c; i2++) { objArr[i2] = a(i2, i); } return objArr; } public static boolean a(Set set, Object obj) { if (set == obj) { return true; } if (obj instanceof Set) { Set set2 = (Set) obj; try { if (set.size() == set2.size()) { if (set.containsAll(set2)) { return true; } } return false; } catch (ClassCastException | NullPointerException unused) { } } return false; } }