350 lines
12 KiB
Java
350 lines
12 KiB
Java
package com.squareup.haha.guava.collect;
|
|
|
|
import com.squareup.haha.guava.base.Function;
|
|
import com.squareup.haha.guava.base.Joiner;
|
|
import java.util.AbstractCollection;
|
|
import java.util.AbstractMap;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Maps {
|
|
|
|
/* JADX WARN: $VALUES field not found */
|
|
/* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
|
|
static abstract class EntryFunction implements Function<Map.Entry<?, ?>, Object> {
|
|
public static final EntryFunction KEY = new EntryFunction("KEY", 0) { // from class: com.squareup.haha.guava.collect.Maps.EntryFunction.1
|
|
{
|
|
byte b = 0;
|
|
}
|
|
|
|
@Override // com.squareup.haha.guava.base.Function
|
|
public final /* bridge */ /* synthetic */ Object apply(Map.Entry<?, ?> entry) {
|
|
return entry.getKey();
|
|
}
|
|
};
|
|
public static final EntryFunction VALUE = new EntryFunction("VALUE", 1) { // from class: com.squareup.haha.guava.collect.Maps.EntryFunction.2
|
|
{
|
|
int i = 1;
|
|
byte b = 0;
|
|
}
|
|
|
|
@Override // com.squareup.haha.guava.base.Function
|
|
public final /* bridge */ /* synthetic */ Object apply(Map.Entry<?, ?> entry) {
|
|
return entry.getValue();
|
|
}
|
|
};
|
|
|
|
static {
|
|
EntryFunction[] entryFunctionArr = {KEY, VALUE};
|
|
}
|
|
|
|
private EntryFunction(String str, int i) {
|
|
}
|
|
|
|
/* synthetic */ EntryFunction(String str, int i, byte b) {
|
|
this(str, i);
|
|
}
|
|
}
|
|
|
|
static abstract class EntrySet<K, V> extends Sets$ImprovedAbstractSet<Map.Entry<K, V>> {
|
|
EntrySet() {
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public void clear() {
|
|
map().clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
if (obj instanceof Map.Entry) {
|
|
Map.Entry entry = (Map.Entry) obj;
|
|
Object key = entry.getKey();
|
|
Object safeGet = Maps.safeGet(map(), key);
|
|
if (Joiner.equal(safeGet, entry.getValue()) && (safeGet != null || map().containsKey(key))) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean isEmpty() {
|
|
return map().isEmpty();
|
|
}
|
|
|
|
abstract Map<K, V> map();
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean remove(Object obj) {
|
|
if (contains(obj)) {
|
|
return map().keySet().remove(((Map.Entry) obj).getKey());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // com.squareup.haha.guava.collect.Sets$ImprovedAbstractSet, java.util.AbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean removeAll(Collection<?> collection) {
|
|
try {
|
|
return super.removeAll((Collection) Joiner.checkNotNull(collection));
|
|
} catch (UnsupportedOperationException unused) {
|
|
return Joiner.removeAllImpl(this, collection.iterator());
|
|
}
|
|
}
|
|
|
|
@Override // com.squareup.haha.guava.collect.Sets$ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean retainAll(Collection<?> collection) {
|
|
try {
|
|
return super.retainAll((Collection) Joiner.checkNotNull(collection));
|
|
} catch (UnsupportedOperationException unused) {
|
|
HashSet hashSet = new HashSet(Maps.capacity(collection.size()));
|
|
for (Object obj : collection) {
|
|
if (contains(obj)) {
|
|
hashSet.add(((Map.Entry) obj).getKey());
|
|
}
|
|
}
|
|
return map().keySet().retainAll(hashSet);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return map().size();
|
|
}
|
|
}
|
|
|
|
static abstract class ImprovedAbstractMap<K, V> extends AbstractMap<K, V> {
|
|
private transient Set<Map.Entry<K, V>> entrySet;
|
|
private transient Set<K> keySet;
|
|
private transient Collection<V> values;
|
|
|
|
ImprovedAbstractMap() {
|
|
}
|
|
|
|
abstract Set<Map.Entry<K, V>> createEntrySet();
|
|
|
|
/* renamed from: createKeySet */
|
|
Set<K> mo16createKeySet() {
|
|
return new KeySet(this);
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Set<Map.Entry<K, V>> entrySet() {
|
|
Set<Map.Entry<K, V>> set = this.entrySet;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<Map.Entry<K, V>> createEntrySet = createEntrySet();
|
|
this.entrySet = createEntrySet;
|
|
return createEntrySet;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Set<K> keySet() {
|
|
Set<K> set = this.keySet;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<K> mo16createKeySet = mo16createKeySet();
|
|
this.keySet = mo16createKeySet;
|
|
return mo16createKeySet;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Collection<V> values() {
|
|
Collection<V> collection = this.values;
|
|
if (collection != null) {
|
|
return collection;
|
|
}
|
|
Values values = new Values(this);
|
|
this.values = values;
|
|
return values;
|
|
}
|
|
}
|
|
|
|
static class KeySet<K, V> extends Sets$ImprovedAbstractSet<K> {
|
|
final Map<K, V> map;
|
|
|
|
KeySet(Map<K, V> map) {
|
|
this.map = (Map) Joiner.checkNotNull(map);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public void clear() {
|
|
this.map.clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return this.map.containsKey(obj);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean isEmpty() {
|
|
return this.map.isEmpty();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
|
public Iterator<K> iterator() {
|
|
return Maps.keyIterator(this.map.entrySet().iterator());
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean remove(Object obj) {
|
|
if (!contains(obj)) {
|
|
return false;
|
|
}
|
|
this.map.remove(obj);
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return this.map.size();
|
|
}
|
|
}
|
|
|
|
static class Values<K, V> extends AbstractCollection<V> {
|
|
private Map<K, V> map;
|
|
|
|
Values(Map<K, V> map) {
|
|
this.map = (Map) Joiner.checkNotNull(map);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final void clear() {
|
|
this.map.clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final boolean contains(Object obj) {
|
|
return this.map.containsValue(obj);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final boolean isEmpty() {
|
|
return this.map.isEmpty();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
|
|
public final Iterator<V> iterator() {
|
|
return Maps.valueIterator(this.map.entrySet().iterator());
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final boolean remove(Object obj) {
|
|
try {
|
|
return super.remove(obj);
|
|
} catch (UnsupportedOperationException unused) {
|
|
for (Map.Entry<K, V> entry : this.map.entrySet()) {
|
|
if (Joiner.equal(obj, entry.getValue())) {
|
|
this.map.remove(entry.getKey());
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final boolean removeAll(Collection<?> collection) {
|
|
try {
|
|
return super.removeAll((Collection) Joiner.checkNotNull(collection));
|
|
} catch (UnsupportedOperationException unused) {
|
|
HashSet hashSet = new HashSet();
|
|
for (Map.Entry<K, V> entry : this.map.entrySet()) {
|
|
if (collection.contains(entry.getValue())) {
|
|
hashSet.add(entry.getKey());
|
|
}
|
|
}
|
|
return this.map.keySet().removeAll(hashSet);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final boolean retainAll(Collection<?> collection) {
|
|
try {
|
|
return super.retainAll((Collection) Joiner.checkNotNull(collection));
|
|
} catch (UnsupportedOperationException unused) {
|
|
HashSet hashSet = new HashSet();
|
|
for (Map.Entry<K, V> entry : this.map.entrySet()) {
|
|
if (collection.contains(entry.getValue())) {
|
|
hashSet.add(entry.getKey());
|
|
}
|
|
}
|
|
return this.map.keySet().retainAll(hashSet);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public final int size() {
|
|
return this.map.size();
|
|
}
|
|
}
|
|
|
|
static {
|
|
new Joiner.MapJoiner(Collections2.STANDARD_JOINER, "=", (byte) 0);
|
|
}
|
|
|
|
public static int capacity(int i) {
|
|
if (i >= 3) {
|
|
if (i < 1073741824) {
|
|
return i + (i / 3);
|
|
}
|
|
return Integer.MAX_VALUE;
|
|
}
|
|
if (i >= 0) {
|
|
return i + 1;
|
|
}
|
|
throw new IllegalArgumentException("expectedSize cannot be negative but was: " + i);
|
|
}
|
|
|
|
public static <K, V> Map.Entry<K, V> immutableEntry(K k, V v) {
|
|
return new ImmutableEntry(k, v);
|
|
}
|
|
|
|
static <K, V> Iterator<K> keyIterator(Iterator<Map.Entry<K, V>> it) {
|
|
return Iterators.transform(it, EntryFunction.KEY);
|
|
}
|
|
|
|
public static <K, V> HashMap<K, V> newHashMap() {
|
|
return new HashMap<>();
|
|
}
|
|
|
|
static boolean safeContainsKey(Map<?, ?> map, Object obj) {
|
|
Joiner.checkNotNull(map);
|
|
try {
|
|
return map.containsKey(obj);
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static <V> V safeGet(Map<?, V> map, Object obj) {
|
|
Joiner.checkNotNull(map);
|
|
try {
|
|
return map.get(obj);
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static <V> V safeRemove(Map<?, V> map, Object obj) {
|
|
Joiner.checkNotNull(map);
|
|
try {
|
|
return map.remove(obj);
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static <K, V> Iterator<V> valueIterator(Iterator<Map.Entry<K, V>> it) {
|
|
return Iterators.transform(it, EntryFunction.VALUE);
|
|
}
|
|
}
|