what-the-bank/sources/com/google/common/collect/AbstractMultimap.java

234 lines
7.3 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Preconditions;
import com.google.common.collect.Multimaps;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public abstract class AbstractMultimap<K, V> implements Multimap<K, V> {
private transient Map<K, Collection<V>> asMap;
private transient Collection<Map.Entry<K, V>> entries;
private transient Set<K> keySet;
private transient Multiset<K> keys;
private transient Collection<V> values;
abstract Map<K, Collection<V>> createAsMap();
abstract Collection<Map.Entry<K, V>> createEntries();
abstract Set<K> createKeySet();
abstract Multiset<K> createKeys();
abstract Collection<V> createValues();
abstract Iterator<Map.Entry<K, V>> entryIterator();
@Override // com.google.common.collect.Multimap
public boolean isEmpty() {
return size() == 0;
}
@Override // com.google.common.collect.Multimap
public boolean containsValue(Object obj) {
Iterator<Collection<V>> it = asMap().values().iterator();
while (it.hasNext()) {
if (it.next().contains(obj)) {
return true;
}
}
return false;
}
@Override // com.google.common.collect.Multimap
public boolean containsEntry(Object obj, Object obj2) {
Collection<V> collection = asMap().get(obj);
return collection != null && collection.contains(obj2);
}
@Override // com.google.common.collect.Multimap
public boolean remove(Object obj, Object obj2) {
Collection<V> collection = asMap().get(obj);
return collection != null && collection.remove(obj2);
}
@Override // com.google.common.collect.Multimap
public boolean put(K k, V v) {
return get(k).add(v);
}
@Override // com.google.common.collect.Multimap
public boolean putAll(K k, Iterable<? extends V> iterable) {
Preconditions.checkNotNull(iterable);
if (iterable instanceof Collection) {
Collection<? extends V> collection = (Collection) iterable;
return !collection.isEmpty() && get(k).addAll(collection);
}
Iterator<? extends V> it = iterable.iterator();
return it.hasNext() && Iterators.addAll(get(k), it);
}
@Override // com.google.common.collect.Multimap
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
boolean z = false;
for (Map.Entry<? extends K, ? extends V> entry : multimap.entries()) {
z |= put(entry.getKey(), entry.getValue());
}
return z;
}
@Override // com.google.common.collect.Multimap
public Collection<V> replaceValues(K k, Iterable<? extends V> iterable) {
Preconditions.checkNotNull(iterable);
Collection<V> removeAll = removeAll(k);
putAll(k, iterable);
return removeAll;
}
@Override // com.google.common.collect.Multimap
public Collection<Map.Entry<K, V>> entries() {
Collection<Map.Entry<K, V>> collection = this.entries;
if (collection != null) {
return collection;
}
Collection<Map.Entry<K, V>> createEntries = createEntries();
this.entries = createEntries;
return createEntries;
}
/* loaded from: classes2.dex */
class Entries extends Multimaps.Entries<K, V> {
final AbstractMultimap this$0;
/* JADX INFO: Access modifiers changed from: package-private */
public Entries(AbstractMultimap abstractMultimap) {
this.this$0 = abstractMultimap;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator<Map.Entry<K, V>> iterator() {
return this.this$0.entryIterator();
}
@Override // com.google.common.collect.Multimaps.Entries
Multimap<K, V> multimap() {
return this.this$0;
}
}
/* loaded from: classes2.dex */
class EntrySet extends Entries implements Set {
/* JADX INFO: Access modifiers changed from: package-private */
public EntrySet(AbstractMultimap abstractMultimap) {
super(abstractMultimap);
}
@Override // java.util.Collection, java.util.Set
public int hashCode() {
return Sets.hashCodeImpl(this);
}
@Override // java.util.Collection, java.util.Set
public boolean equals(Object obj) {
return Sets.equalsImpl(this, obj);
}
}
@Override // com.google.common.collect.Multimap
public Set<K> keySet() {
Set<K> set = this.keySet;
if (set != null) {
return set;
}
Set<K> createKeySet = createKeySet();
this.keySet = createKeySet;
return createKeySet;
}
@Override // com.google.common.collect.Multimap
public Multiset<K> keys() {
Multiset<K> multiset = this.keys;
if (multiset != null) {
return multiset;
}
Multiset<K> createKeys = createKeys();
this.keys = createKeys;
return createKeys;
}
@Override // com.google.common.collect.Multimap
public Collection<V> values() {
Collection<V> collection = this.values;
if (collection != null) {
return collection;
}
Collection<V> createValues = createValues();
this.values = createValues;
return createValues;
}
/* loaded from: classes2.dex */
class Values extends AbstractCollection<V> {
final AbstractMultimap this$0;
/* JADX INFO: Access modifiers changed from: package-private */
public Values(AbstractMultimap abstractMultimap) {
this.this$0 = abstractMultimap;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator<V> iterator() {
return this.this$0.valueIterator();
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
return this.this$0.size();
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean contains(Object obj) {
return this.this$0.containsValue(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection
public void clear() {
this.this$0.clear();
}
}
Iterator<V> valueIterator() {
return Maps.valueIterator(entries().iterator());
}
@Override // com.google.common.collect.Multimap, com.google.common.collect.ListMultimap
public Map<K, Collection<V>> asMap() {
Map<K, Collection<V>> map = this.asMap;
if (map != null) {
return map;
}
Map<K, Collection<V>> createAsMap = createAsMap();
this.asMap = createAsMap;
return createAsMap;
}
@Override // com.google.common.collect.Multimap, com.google.common.collect.ListMultimap
public boolean equals(Object obj) {
return Multimaps.equalsImpl(this, obj);
}
@Override // com.google.common.collect.Multimap
public int hashCode() {
return asMap().hashCode();
}
public String toString() {
return asMap().toString();
}
}