943 lines
30 KiB
Java
943 lines
30 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Function;
|
|
import com.google.common.base.Objects;
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.base.Predicate;
|
|
import com.google.common.base.Predicates;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.Sets;
|
|
import java.util.AbstractCollection;
|
|
import java.util.AbstractMap;
|
|
import java.util.Collection;
|
|
import java.util.Comparator;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.NavigableMap;
|
|
import java.util.NavigableSet;
|
|
import java.util.Set;
|
|
import java.util.SortedMap;
|
|
import java.util.SortedSet;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Maps {
|
|
|
|
static abstract class DescendingMap<K, V> extends ForwardingMap<K, V> implements NavigableMap<K, V> {
|
|
private transient Comparator<? super K> a;
|
|
private transient Set<Map.Entry<K, V>> b;
|
|
private transient NavigableSet<K> c;
|
|
|
|
DescendingMap() {
|
|
}
|
|
|
|
private static <T> Ordering<T> a(Comparator<T> comparator) {
|
|
return Ordering.a(comparator).b();
|
|
}
|
|
|
|
abstract Iterator<Map.Entry<K, V>> b();
|
|
|
|
abstract NavigableMap<K, V> c();
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> ceilingEntry(K k) {
|
|
return c().floorEntry(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public K ceilingKey(K k) {
|
|
return c().floorKey(k);
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public Comparator<? super K> comparator() {
|
|
Comparator<? super K> comparator = this.a;
|
|
if (comparator != null) {
|
|
return comparator;
|
|
}
|
|
Comparator<? super K> comparator2 = c().comparator();
|
|
if (comparator2 == null) {
|
|
comparator2 = Ordering.c();
|
|
}
|
|
Ordering a = a(comparator2);
|
|
this.a = a;
|
|
return a;
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public NavigableSet<K> descendingKeySet() {
|
|
return c().navigableKeySet();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public NavigableMap<K, V> descendingMap() {
|
|
return c();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ForwardingMap, java.util.Map
|
|
public Set<Map.Entry<K, V>> entrySet() {
|
|
Set<Map.Entry<K, V>> set = this.b;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<Map.Entry<K, V>> a = a();
|
|
this.b = a;
|
|
return a;
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> firstEntry() {
|
|
return c().lastEntry();
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public K firstKey() {
|
|
return c().lastKey();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> floorEntry(K k) {
|
|
return c().ceilingEntry(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public K floorKey(K k) {
|
|
return c().ceilingKey(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public NavigableMap<K, V> headMap(K k, boolean z) {
|
|
return c().tailMap(k, z).descendingMap();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> higherEntry(K k) {
|
|
return c().lowerEntry(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public K higherKey(K k) {
|
|
return c().lowerKey(k);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ForwardingMap, java.util.Map
|
|
public Set<K> keySet() {
|
|
return navigableKeySet();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> lastEntry() {
|
|
return c().firstEntry();
|
|
}
|
|
|
|
@Override // java.util.SortedMap
|
|
public K lastKey() {
|
|
return c().firstKey();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> lowerEntry(K k) {
|
|
return c().higherEntry(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public K lowerKey(K k) {
|
|
return c().higherKey(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public NavigableSet<K> navigableKeySet() {
|
|
NavigableSet<K> navigableSet = this.c;
|
|
if (navigableSet != null) {
|
|
return navigableSet;
|
|
}
|
|
NavigableKeySet navigableKeySet = new NavigableKeySet(this);
|
|
this.c = navigableKeySet;
|
|
return navigableKeySet;
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> pollFirstEntry() {
|
|
return c().pollLastEntry();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public Map.Entry<K, V> pollLastEntry() {
|
|
return c().pollFirstEntry();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public NavigableMap<K, V> subMap(K k, boolean z, K k2, boolean z2) {
|
|
return c().subMap(k2, z2, k, z).descendingMap();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap
|
|
public NavigableMap<K, V> tailMap(K k, boolean z) {
|
|
return c().headMap(k, z).descendingMap();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ForwardingObject
|
|
public String toString() {
|
|
return standardToString();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ForwardingMap, java.util.Map
|
|
public Collection<V> values() {
|
|
return new Values(this);
|
|
}
|
|
|
|
Set<Map.Entry<K, V>> a() {
|
|
return new EntrySet<K, V>() { // from class: com.google.common.collect.Maps.DescendingMap.1EntrySetImpl
|
|
@Override // com.google.common.collect.Maps.EntrySet
|
|
Map<K, V> c() {
|
|
return DescendingMap.this;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
|
public Iterator<Map.Entry<K, V>> iterator() {
|
|
return DescendingMap.this.b();
|
|
}
|
|
};
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // com.google.common.collect.ForwardingMap, com.google.common.collect.ForwardingObject
|
|
public final Map<K, V> delegate() {
|
|
return c();
|
|
}
|
|
|
|
@Override // java.util.NavigableMap, java.util.SortedMap
|
|
public SortedMap<K, V> headMap(K k) {
|
|
return headMap(k, false);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap, java.util.SortedMap
|
|
public SortedMap<K, V> subMap(K k, K k2) {
|
|
return subMap(k, true, k2, false);
|
|
}
|
|
|
|
@Override // java.util.NavigableMap, java.util.SortedMap
|
|
public SortedMap<K, V> tailMap(K k) {
|
|
return tailMap(k, true);
|
|
}
|
|
}
|
|
|
|
private enum EntryFunction implements Function<Map.Entry<?, ?>, Object> {
|
|
KEY { // from class: com.google.common.collect.Maps.EntryFunction.1
|
|
@Override // com.google.common.base.Function
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public Object apply(Map.Entry<?, ?> entry) {
|
|
return entry.getKey();
|
|
}
|
|
},
|
|
VALUE { // from class: com.google.common.collect.Maps.EntryFunction.2
|
|
@Override // com.google.common.base.Function
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public Object apply(Map.Entry<?, ?> entry) {
|
|
return entry.getValue();
|
|
}
|
|
}
|
|
}
|
|
|
|
static abstract class EntrySet<K, V> extends Sets.ImprovedAbstractSet<Map.Entry<K, V>> {
|
|
EntrySet() {
|
|
}
|
|
|
|
abstract Map<K, V> c();
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public void clear() {
|
|
c().clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
if (!(obj instanceof Map.Entry)) {
|
|
return false;
|
|
}
|
|
Map.Entry entry = (Map.Entry) obj;
|
|
Object key = entry.getKey();
|
|
Object e = Maps.e(c(), key);
|
|
if (Objects.a(e, entry.getValue())) {
|
|
return e != null || c().containsKey(key);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean isEmpty() {
|
|
return c().isEmpty();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean remove(Object obj) {
|
|
if (contains(obj)) {
|
|
return c().keySet().remove(((Map.Entry) obj).getKey());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean removeAll(Collection<?> collection) {
|
|
try {
|
|
Preconditions.a(collection);
|
|
return super.removeAll(collection);
|
|
} catch (UnsupportedOperationException unused) {
|
|
return Sets.a((Set<?>) this, collection.iterator());
|
|
}
|
|
}
|
|
|
|
@Override // com.google.common.collect.Sets.ImprovedAbstractSet, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean retainAll(Collection<?> collection) {
|
|
try {
|
|
Preconditions.a(collection);
|
|
return super.retainAll(collection);
|
|
} catch (UnsupportedOperationException unused) {
|
|
HashSet a = Sets.a(collection.size());
|
|
for (Object obj : collection) {
|
|
if (contains(obj)) {
|
|
a.add(((Map.Entry) obj).getKey());
|
|
}
|
|
}
|
|
return c().keySet().retainAll(a);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return c().size();
|
|
}
|
|
}
|
|
|
|
public interface EntryTransformer<K, V1, V2> {
|
|
V2 a(K k, V1 v1);
|
|
}
|
|
|
|
static abstract class IteratorBasedAbstractMap<K, V> extends AbstractMap<K, V> {
|
|
IteratorBasedAbstractMap() {
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public void clear() {
|
|
Iterators.b(entryIterator());
|
|
}
|
|
|
|
abstract Iterator<Map.Entry<K, V>> entryIterator();
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Set<Map.Entry<K, V>> entrySet() {
|
|
return new EntrySet<K, V>() { // from class: com.google.common.collect.Maps.IteratorBasedAbstractMap.1
|
|
@Override // com.google.common.collect.Maps.EntrySet
|
|
Map<K, V> c() {
|
|
return IteratorBasedAbstractMap.this;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
|
public Iterator<Map.Entry<K, V>> iterator() {
|
|
return IteratorBasedAbstractMap.this.entryIterator();
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public abstract int size();
|
|
}
|
|
|
|
static class KeySet<K, V> extends Sets.ImprovedAbstractSet<K> {
|
|
final Map<K, V> a;
|
|
|
|
KeySet(Map<K, V> map) {
|
|
Preconditions.a(map);
|
|
this.a = map;
|
|
}
|
|
|
|
Map<K, V> c() {
|
|
return this.a;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public void clear() {
|
|
c().clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return c().containsKey(obj);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean isEmpty() {
|
|
return c().isEmpty();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
|
public Iterator<K> iterator() {
|
|
return Maps.a(c().entrySet().iterator());
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean remove(Object obj) {
|
|
if (!contains(obj)) {
|
|
return false;
|
|
}
|
|
c().remove(obj);
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return c().size();
|
|
}
|
|
}
|
|
|
|
static class NavigableKeySet<K, V> extends SortedKeySet<K, V> implements NavigableSet<K> {
|
|
NavigableKeySet(NavigableMap<K, V> navigableMap) {
|
|
super(navigableMap);
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public K ceiling(K k) {
|
|
return c().ceilingKey(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public Iterator<K> descendingIterator() {
|
|
return descendingSet().iterator();
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public NavigableSet<K> descendingSet() {
|
|
return c().descendingKeySet();
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public K floor(K k) {
|
|
return c().floorKey(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public NavigableSet<K> headSet(K k, boolean z) {
|
|
return c().headMap(k, z).navigableKeySet();
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public K higher(K k) {
|
|
return c().higherKey(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public K lower(K k) {
|
|
return c().lowerKey(k);
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public K pollFirst() {
|
|
return (K) Maps.a(c().pollFirstEntry());
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public K pollLast() {
|
|
return (K) Maps.a(c().pollLastEntry());
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public NavigableSet<K> subSet(K k, boolean z, K k2, boolean z2) {
|
|
return c().subMap(k, z, k2, z2).navigableKeySet();
|
|
}
|
|
|
|
@Override // java.util.NavigableSet
|
|
public NavigableSet<K> tailSet(K k, boolean z) {
|
|
return c().tailMap(k, z).navigableKeySet();
|
|
}
|
|
|
|
@Override // com.google.common.collect.Maps.SortedKeySet, java.util.SortedSet, java.util.NavigableSet
|
|
public SortedSet<K> headSet(K k) {
|
|
return headSet(k, false);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Maps.SortedKeySet, java.util.SortedSet, java.util.NavigableSet
|
|
public SortedSet<K> subSet(K k, K k2) {
|
|
return subSet(k, true, k2, false);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Maps.SortedKeySet, java.util.SortedSet, java.util.NavigableSet
|
|
public SortedSet<K> tailSet(K k) {
|
|
return tailSet(k, true);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.Maps.SortedKeySet, com.google.common.collect.Maps.KeySet
|
|
public NavigableMap<K, V> c() {
|
|
return (NavigableMap) this.a;
|
|
}
|
|
}
|
|
|
|
static class SortedKeySet<K, V> extends KeySet<K, V> implements SortedSet<K> {
|
|
SortedKeySet(SortedMap<K, V> sortedMap) {
|
|
super(sortedMap);
|
|
}
|
|
|
|
@Override // java.util.SortedSet
|
|
public Comparator<? super K> comparator() {
|
|
return c().comparator();
|
|
}
|
|
|
|
@Override // java.util.SortedSet
|
|
public K first() {
|
|
return c().firstKey();
|
|
}
|
|
|
|
public SortedSet<K> headSet(K k) {
|
|
return new SortedKeySet(c().headMap(k));
|
|
}
|
|
|
|
@Override // java.util.SortedSet
|
|
public K last() {
|
|
return c().lastKey();
|
|
}
|
|
|
|
public SortedSet<K> subSet(K k, K k2) {
|
|
return new SortedKeySet(c().subMap(k, k2));
|
|
}
|
|
|
|
public SortedSet<K> tailSet(K k) {
|
|
return new SortedKeySet(c().tailMap(k));
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.Maps.KeySet
|
|
public SortedMap<K, V> c() {
|
|
return (SortedMap) super.c();
|
|
}
|
|
}
|
|
|
|
static class TransformedEntriesMap<K, V1, V2> extends IteratorBasedAbstractMap<K, V2> {
|
|
final Map<K, V1> a;
|
|
final EntryTransformer<? super K, ? super V1, V2> b;
|
|
|
|
TransformedEntriesMap(Map<K, V1> map, EntryTransformer<? super K, ? super V1, V2> entryTransformer) {
|
|
Preconditions.a(map);
|
|
this.a = map;
|
|
Preconditions.a(entryTransformer);
|
|
this.b = entryTransformer;
|
|
}
|
|
|
|
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
|
|
public void clear() {
|
|
this.a.clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public boolean containsKey(Object obj) {
|
|
return this.a.containsKey(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap
|
|
Iterator<Map.Entry<K, V2>> entryIterator() {
|
|
return Iterators.a((Iterator) this.a.entrySet().iterator(), Maps.a(this.b));
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public V2 get(Object obj) {
|
|
V1 v1 = this.a.get(obj);
|
|
if (v1 != null || this.a.containsKey(obj)) {
|
|
return this.b.a(obj, v1);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Set<K> keySet() {
|
|
return this.a.keySet();
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public V2 remove(Object obj) {
|
|
if (this.a.containsKey(obj)) {
|
|
return this.b.a(obj, this.a.remove(obj));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // com.google.common.collect.Maps.IteratorBasedAbstractMap, java.util.AbstractMap, java.util.Map
|
|
public int size() {
|
|
return this.a.size();
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Collection<V2> values() {
|
|
return new Values(this);
|
|
}
|
|
}
|
|
|
|
static class Values<K, V> extends AbstractCollection<V> {
|
|
final Map<K, V> a;
|
|
|
|
Values(Map<K, V> map) {
|
|
Preconditions.a(map);
|
|
this.a = map;
|
|
}
|
|
|
|
final Map<K, V> a() {
|
|
return this.a;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public void clear() {
|
|
a().clear();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public boolean contains(Object obj) {
|
|
return a().containsValue(obj);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public boolean isEmpty() {
|
|
return a().isEmpty();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
|
|
public Iterator<V> iterator() {
|
|
return Maps.b(a().entrySet().iterator());
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public boolean remove(Object obj) {
|
|
try {
|
|
return super.remove(obj);
|
|
} catch (UnsupportedOperationException unused) {
|
|
for (Map.Entry<K, V> entry : a().entrySet()) {
|
|
if (Objects.a(obj, entry.getValue())) {
|
|
a().remove(entry.getKey());
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public boolean removeAll(Collection<?> collection) {
|
|
try {
|
|
Preconditions.a(collection);
|
|
return super.removeAll(collection);
|
|
} catch (UnsupportedOperationException unused) {
|
|
HashSet a = Sets.a();
|
|
for (Map.Entry<K, V> entry : a().entrySet()) {
|
|
if (collection.contains(entry.getValue())) {
|
|
a.add(entry.getKey());
|
|
}
|
|
}
|
|
return a().keySet().removeAll(a);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public boolean retainAll(Collection<?> collection) {
|
|
try {
|
|
Preconditions.a(collection);
|
|
return super.retainAll(collection);
|
|
} catch (UnsupportedOperationException unused) {
|
|
HashSet a = Sets.a();
|
|
for (Map.Entry<K, V> entry : a().entrySet()) {
|
|
if (collection.contains(entry.getValue())) {
|
|
a.add(entry.getKey());
|
|
}
|
|
}
|
|
return a().keySet().retainAll(a);
|
|
}
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public int size() {
|
|
return a().size();
|
|
}
|
|
}
|
|
|
|
static abstract class ViewCachingAbstractMap<K, V> extends AbstractMap<K, V> {
|
|
private transient Set<Map.Entry<K, V>> a;
|
|
private transient Set<K> b;
|
|
private transient Collection<V> c;
|
|
|
|
ViewCachingAbstractMap() {
|
|
}
|
|
|
|
abstract Set<Map.Entry<K, V>> a();
|
|
|
|
Set<K> b() {
|
|
return new KeySet(this);
|
|
}
|
|
|
|
Collection<V> c() {
|
|
return new Values(this);
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Set<Map.Entry<K, V>> entrySet() {
|
|
Set<Map.Entry<K, V>> set = this.a;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<Map.Entry<K, V>> a = a();
|
|
this.a = a;
|
|
return a;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Set<K> keySet() {
|
|
Set<K> set = this.b;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<K> b = b();
|
|
this.b = b;
|
|
return b;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map
|
|
public Collection<V> values() {
|
|
Collection<V> collection = this.c;
|
|
if (collection != null) {
|
|
return collection;
|
|
}
|
|
Collection<V> c = c();
|
|
this.c = c;
|
|
return c;
|
|
}
|
|
}
|
|
|
|
static <K> Function<Map.Entry<K, ?>, K> a() {
|
|
return EntryFunction.KEY;
|
|
}
|
|
|
|
static <K, V> Iterator<V> b(Iterator<Map.Entry<K, V>> it) {
|
|
return Iterators.a((Iterator) it, d());
|
|
}
|
|
|
|
public static <K, V> LinkedHashMap<K, V> c() {
|
|
return new LinkedHashMap<>();
|
|
}
|
|
|
|
static <V> Function<Map.Entry<?, V>, V> d() {
|
|
return EntryFunction.VALUE;
|
|
}
|
|
|
|
static <V> V e(Map<?, V> map, Object obj) {
|
|
Preconditions.a(map);
|
|
try {
|
|
return map.get(obj);
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static <V> V f(Map<?, V> map, Object obj) {
|
|
Preconditions.a(map);
|
|
try {
|
|
return map.remove(obj);
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static <K, V> Iterator<K> a(Iterator<Map.Entry<K, V>> it) {
|
|
return Iterators.a((Iterator) it, a());
|
|
}
|
|
|
|
public static <K, V> HashMap<K, V> b() {
|
|
return new HashMap<>();
|
|
}
|
|
|
|
public static <K, V> LinkedHashMap<K, V> c(int i) {
|
|
return new LinkedHashMap<>(a(i));
|
|
}
|
|
|
|
static boolean d(Map<?, ?> map, Object obj) {
|
|
Preconditions.a(map);
|
|
try {
|
|
return map.containsKey(obj);
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static int a(int i) {
|
|
if (i < 3) {
|
|
CollectPreconditions.a(i, "expectedSize");
|
|
return i + 1;
|
|
}
|
|
if (i < 1073741824) {
|
|
return (int) ((i / 0.75f) + 1.0f);
|
|
}
|
|
return Integer.MAX_VALUE;
|
|
}
|
|
|
|
public static <K, V> HashMap<K, V> b(int i) {
|
|
return new HashMap<>(a(i));
|
|
}
|
|
|
|
static boolean c(Map<?, ?> map, Object obj) {
|
|
if (map == obj) {
|
|
return true;
|
|
}
|
|
if (obj instanceof Map) {
|
|
return map.entrySet().equals(((Map) obj).entrySet());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static <K, V> Iterator<Map.Entry<K, V>> a(Set<K> set, final Function<? super K, V> function) {
|
|
return new TransformedIterator<K, Map.Entry<K, V>>(set.iterator()) { // from class: com.google.common.collect.Maps.1
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.TransformedIterator
|
|
/* bridge */ /* synthetic */ Object a(Object obj) {
|
|
return a((AnonymousClass1<K, V>) obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.TransformedIterator
|
|
Map.Entry<K, V> a(K k) {
|
|
return Maps.a(k, function.apply(k));
|
|
}
|
|
};
|
|
}
|
|
|
|
static <K, V> Map.Entry<K, V> b(final Map.Entry<? extends K, ? extends V> entry) {
|
|
Preconditions.a(entry);
|
|
return new AbstractMapEntry<K, V>() { // from class: com.google.common.collect.Maps.5
|
|
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
|
|
public K getKey() {
|
|
return (K) entry.getKey();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
|
|
public V getValue() {
|
|
return (V) entry.getValue();
|
|
}
|
|
};
|
|
}
|
|
|
|
public static <K, V> Map.Entry<K, V> a(K k, V v) {
|
|
return new ImmutableEntry(k, v);
|
|
}
|
|
|
|
public static <K, V1, V2> Map<K, V2> a(Map<K, V1> map, Function<? super V1, V2> function) {
|
|
return a((Map) map, a(function));
|
|
}
|
|
|
|
static <V> Predicate<Map.Entry<?, V>> b(Predicate<? super V> predicate) {
|
|
return Predicates.a(predicate, d());
|
|
}
|
|
|
|
static <V> V c(Map.Entry<?, V> entry) {
|
|
if (entry == null) {
|
|
return null;
|
|
}
|
|
return entry.getValue();
|
|
}
|
|
|
|
public static <K, V1, V2> Map<K, V2> a(Map<K, V1> map, EntryTransformer<? super K, ? super V1, V2> entryTransformer) {
|
|
return new TransformedEntriesMap(map, entryTransformer);
|
|
}
|
|
|
|
static boolean b(Map<?, ?> map, Object obj) {
|
|
return Iterators.a((Iterator<?>) b(map.entrySet().iterator()), obj);
|
|
}
|
|
|
|
static <K, V1, V2> EntryTransformer<K, V1, V2> a(final Function<? super V1, V2> function) {
|
|
Preconditions.a(function);
|
|
return new EntryTransformer<K, V1, V2>() { // from class: com.google.common.collect.Maps.7
|
|
@Override // com.google.common.collect.Maps.EntryTransformer
|
|
public V2 a(K k, V1 v1) {
|
|
return (V2) Function.this.apply(v1);
|
|
}
|
|
};
|
|
}
|
|
|
|
static <V2, K, V1> Map.Entry<K, V2> a(final EntryTransformer<? super K, ? super V1, V2> entryTransformer, final Map.Entry<K, V1> entry) {
|
|
Preconditions.a(entryTransformer);
|
|
Preconditions.a(entry);
|
|
return new AbstractMapEntry<K, V2>() { // from class: com.google.common.collect.Maps.10
|
|
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
|
|
public K getKey() {
|
|
return (K) entry.getKey();
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
|
|
public V2 getValue() {
|
|
return (V2) entryTransformer.a(entry.getKey(), entry.getValue());
|
|
}
|
|
};
|
|
}
|
|
|
|
static <K, V1, V2> Function<Map.Entry<K, V1>, Map.Entry<K, V2>> a(final EntryTransformer<? super K, ? super V1, V2> entryTransformer) {
|
|
Preconditions.a(entryTransformer);
|
|
return new Function<Map.Entry<K, V1>, Map.Entry<K, V2>>() { // from class: com.google.common.collect.Maps.11
|
|
@Override // com.google.common.base.Function
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public Map.Entry<K, V2> apply(Map.Entry<K, V1> entry) {
|
|
return Maps.a(EntryTransformer.this, (Map.Entry) entry);
|
|
}
|
|
};
|
|
}
|
|
|
|
static <K> Predicate<Map.Entry<K, ?>> a(Predicate<? super K> predicate) {
|
|
return Predicates.a(predicate, a());
|
|
}
|
|
|
|
static boolean a(Map<?, ?> map, Object obj) {
|
|
return Iterators.a((Iterator<?>) a(map.entrySet().iterator()), obj);
|
|
}
|
|
|
|
static <K, V> boolean a(Collection<Map.Entry<K, V>> collection, Object obj) {
|
|
if (obj instanceof Map.Entry) {
|
|
return collection.contains(b((Map.Entry) obj));
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static String a(Map<?, ?> map) {
|
|
StringBuilder a = Collections2.a(map.size());
|
|
a.append('{');
|
|
boolean z = true;
|
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
|
if (!z) {
|
|
a.append(", ");
|
|
}
|
|
z = false;
|
|
a.append(entry.getKey());
|
|
a.append('=');
|
|
a.append(entry.getValue());
|
|
}
|
|
a.append('}');
|
|
return a.toString();
|
|
}
|
|
|
|
static <K, V> void a(Map<K, V> map, Map<? extends K, ? extends V> map2) {
|
|
for (Map.Entry<? extends K, ? extends V> entry : map2.entrySet()) {
|
|
map.put(entry.getKey(), entry.getValue());
|
|
}
|
|
}
|
|
|
|
static <K> K a(Map.Entry<K, ?> entry) {
|
|
if (entry == null) {
|
|
return null;
|
|
}
|
|
return entry.getKey();
|
|
}
|
|
|
|
static <E> ImmutableMap<E, Integer> a(Collection<E> collection) {
|
|
ImmutableMap.Builder builder = new ImmutableMap.Builder(collection.size());
|
|
Iterator<E> it = collection.iterator();
|
|
int i = 0;
|
|
while (it.hasNext()) {
|
|
builder.a(it.next(), Integer.valueOf(i));
|
|
i++;
|
|
}
|
|
return builder.a();
|
|
}
|
|
}
|