439 lines
16 KiB
Java
439 lines
16 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.collect.Multiset;
|
|
import com.google.common.collect.Serialization;
|
|
import java.io.Serializable;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class ImmutableMultimap<K, V> extends AbstractMultimap<K, V> implements Serializable {
|
|
private static final long serialVersionUID = 0;
|
|
final transient ImmutableMap<K, ? extends ImmutableCollection<V>> map;
|
|
final transient int size;
|
|
|
|
public static class Builder<K, V> {
|
|
Multimap<K, V> a;
|
|
Comparator<? super K> b;
|
|
Comparator<? super V> c;
|
|
|
|
public Builder() {
|
|
this(MultimapBuilder.a().a().b());
|
|
}
|
|
|
|
public Builder<K, V> a(K k, V v) {
|
|
CollectPreconditions.a(k, v);
|
|
this.a.put(k, v);
|
|
return this;
|
|
}
|
|
|
|
Builder(Multimap<K, V> multimap) {
|
|
this.a = multimap;
|
|
}
|
|
|
|
public Builder<K, V> a(Map.Entry<? extends K, ? extends V> entry) {
|
|
return a(entry.getKey(), entry.getValue());
|
|
}
|
|
|
|
public Builder<K, V> a(Iterable<? extends Map.Entry<? extends K, ? extends V>> iterable) {
|
|
Iterator<? extends Map.Entry<? extends K, ? extends V>> it = iterable.iterator();
|
|
while (it.hasNext()) {
|
|
a(it.next());
|
|
}
|
|
return this;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public ImmutableMultimap<K, V> a() {
|
|
if (this.c != null) {
|
|
Iterator<Collection<V>> it = this.a.asMap().values().iterator();
|
|
while (it.hasNext()) {
|
|
Collections.sort((List) it.next(), this.c);
|
|
}
|
|
}
|
|
if (this.b != null) {
|
|
AbstractListMultimap b = MultimapBuilder.a().a().b();
|
|
for (Map.Entry entry : Ordering.a(this.b).a().a(this.a.asMap().entrySet())) {
|
|
b.putAll(entry.getKey(), (Iterable) entry.getValue());
|
|
}
|
|
this.a = b;
|
|
}
|
|
return ImmutableMultimap.copyOf(this.a);
|
|
}
|
|
}
|
|
|
|
private static class EntryCollection<K, V> extends ImmutableCollection<Map.Entry<K, V>> {
|
|
final ImmutableMultimap<K, V> a;
|
|
|
|
EntryCollection(ImmutableMultimap<K, V> immutableMultimap) {
|
|
this.a = immutableMultimap;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, 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;
|
|
return this.a.containsEntry(entry.getKey(), entry.getValue());
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return this.a.isPartialView();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public int size() {
|
|
return this.a.size();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet
|
|
public UnmodifiableIterator<Map.Entry<K, V>> iterator() {
|
|
return this.a.entryIterator();
|
|
}
|
|
}
|
|
|
|
static class FieldSettersHolder {
|
|
static final Serialization.FieldSetter<ImmutableMultimap> a = Serialization.a(ImmutableMultimap.class, "map");
|
|
static final Serialization.FieldSetter<ImmutableMultimap> b = Serialization.a(ImmutableMultimap.class, "size");
|
|
static final Serialization.FieldSetter<ImmutableSetMultimap> c = Serialization.a(ImmutableSetMultimap.class, "emptySet");
|
|
}
|
|
|
|
private abstract class Itr<T> extends UnmodifiableIterator<T> {
|
|
final Iterator<Map.Entry<K, Collection<V>>> a;
|
|
K b;
|
|
Iterator<V> c;
|
|
|
|
private Itr() {
|
|
this.a = ImmutableMultimap.this.asMap().entrySet().iterator();
|
|
this.b = null;
|
|
this.c = Iterators.a();
|
|
}
|
|
|
|
abstract T a(K k, V v);
|
|
|
|
@Override // java.util.Iterator
|
|
public boolean hasNext() {
|
|
return this.a.hasNext() || this.c.hasNext();
|
|
}
|
|
|
|
@Override // java.util.Iterator
|
|
public T next() {
|
|
if (!this.c.hasNext()) {
|
|
Map.Entry<K, Collection<V>> next = this.a.next();
|
|
this.b = next.getKey();
|
|
this.c = next.getValue().iterator();
|
|
}
|
|
return a(this.b, this.c.next());
|
|
}
|
|
}
|
|
|
|
class Keys extends ImmutableMultiset<K> {
|
|
Keys() {
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultiset, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return ImmutableMultimap.this.containsKey(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
public int count(Object obj) {
|
|
ImmutableCollection<V> immutableCollection = ImmutableMultimap.this.map.get(obj);
|
|
if (immutableCollection == null) {
|
|
return 0;
|
|
}
|
|
return immutableCollection.size();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultiset
|
|
Multiset.Entry<K> getEntry(int i) {
|
|
Map.Entry<K, ? extends ImmutableCollection<V>> entry = ImmutableMultimap.this.map.entrySet().asList().get(i);
|
|
return Multisets.a(entry.getKey(), entry.getValue().size());
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset
|
|
public int size() {
|
|
return ImmutableMultimap.this.size();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultiset, com.google.common.collect.Multiset
|
|
public ImmutableSet<K> elementSet() {
|
|
return ImmutableMultimap.this.keySet();
|
|
}
|
|
}
|
|
|
|
private static final class Values<K, V> extends ImmutableCollection<V> {
|
|
private final transient ImmutableMultimap<K, V> a;
|
|
|
|
Values(ImmutableMultimap<K, V> immutableMultimap) {
|
|
this.a = immutableMultimap;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return this.a.containsValue(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
int copyIntoArray(Object[] objArr, int i) {
|
|
UnmodifiableIterator<? extends ImmutableCollection<V>> it = this.a.map.values().iterator();
|
|
while (it.hasNext()) {
|
|
i = it.next().copyIntoArray(objArr, i);
|
|
}
|
|
return i;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection
|
|
public int size() {
|
|
return this.a.size();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet
|
|
public UnmodifiableIterator<V> iterator() {
|
|
return this.a.valueIterator();
|
|
}
|
|
}
|
|
|
|
ImmutableMultimap(ImmutableMap<K, ? extends ImmutableCollection<V>> immutableMap, int i) {
|
|
this.map = immutableMap;
|
|
this.size = i;
|
|
}
|
|
|
|
public static <K, V> Builder<K, V> builder() {
|
|
return new Builder<>();
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> copyOf(Multimap<? extends K, ? extends V> multimap) {
|
|
if (multimap instanceof ImmutableMultimap) {
|
|
ImmutableMultimap<K, V> immutableMultimap = (ImmutableMultimap) multimap;
|
|
if (!immutableMultimap.isPartialView()) {
|
|
return immutableMultimap;
|
|
}
|
|
}
|
|
return ImmutableListMultimap.copyOf((Multimap) multimap);
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> of() {
|
|
return ImmutableListMultimap.of();
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public void clear() {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
public /* bridge */ /* synthetic */ boolean containsEntry(Object obj, Object obj2) {
|
|
return super.containsEntry(obj, obj2);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multimap
|
|
public boolean containsKey(Object obj) {
|
|
return this.map.containsKey(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public boolean containsValue(Object obj) {
|
|
return obj != null && super.containsValue(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
Map<K, Collection<V>> createAsMap() {
|
|
throw new AssertionError("should never be called");
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public /* bridge */ /* synthetic */ boolean equals(Object obj) {
|
|
return super.equals(obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multimap
|
|
public abstract ImmutableCollection<V> get(K k);
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.Multimap
|
|
public /* bridge */ /* synthetic */ Collection get(Object obj) {
|
|
return get((ImmutableMultimap<K, V>) obj);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public /* bridge */ /* synthetic */ int hashCode() {
|
|
return super.hashCode();
|
|
}
|
|
|
|
public abstract ImmutableMultimap<V, K> inverse();
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
public /* bridge */ /* synthetic */ boolean isEmpty() {
|
|
return super.isEmpty();
|
|
}
|
|
|
|
boolean isPartialView() {
|
|
return this.map.isPartialView();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public boolean put(K k, V v) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public boolean putAll(K k, Iterable<? extends V> iterable) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public boolean remove(Object obj, Object obj2) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
@Deprecated
|
|
public /* bridge */ /* synthetic */ Collection replaceValues(Object obj, Iterable iterable) {
|
|
return replaceValues((ImmutableMultimap<K, V>) obj, iterable);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multimap
|
|
public int size() {
|
|
return this.size;
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public /* bridge */ /* synthetic */ String toString() {
|
|
return super.toString();
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> of(K k, V v) {
|
|
return ImmutableListMultimap.of((Object) k, (Object) v);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
public ImmutableMap<K, Collection<V>> asMap() {
|
|
return this.map;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public ImmutableCollection<Map.Entry<K, V>> createEntries() {
|
|
return new EntryCollection(this);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public ImmutableMultiset<K> createKeys() {
|
|
return new Keys();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public ImmutableCollection<V> createValues() {
|
|
return new Values(this);
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
public ImmutableCollection<Map.Entry<K, V>> entries() {
|
|
return (ImmutableCollection) super.entries();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public UnmodifiableIterator<Map.Entry<K, V>> entryIterator() {
|
|
return new ImmutableMultimap<K, V>.Itr<Map.Entry<K, V>>(this) { // from class: com.google.common.collect.ImmutableMultimap.1
|
|
@Override // com.google.common.collect.ImmutableMultimap.Itr
|
|
/* bridge */ /* synthetic */ Object a(Object obj, Object obj2) {
|
|
return a((AnonymousClass1) obj, obj2);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Itr
|
|
Map.Entry<K, V> a(K k, V v) {
|
|
return Maps.a(k, v);
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
public ImmutableSet<K> keySet() {
|
|
return this.map.keySet();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public ImmutableMultiset<K> keys() {
|
|
return (ImmutableMultiset) super.keys();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
@Deprecated
|
|
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public ImmutableCollection<V> removeAll(Object obj) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
@Deprecated
|
|
public ImmutableCollection<V> replaceValues(K k, Iterable<? extends V> iterable) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public UnmodifiableIterator<V> valueIterator() {
|
|
return new ImmutableMultimap<K, V>.Itr<V>(this) { // from class: com.google.common.collect.ImmutableMultimap.2
|
|
@Override // com.google.common.collect.ImmutableMultimap.Itr
|
|
V a(K k, V v) {
|
|
return v;
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractMultimap
|
|
public ImmutableCollection<V> values() {
|
|
return (ImmutableCollection) super.values();
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> of(K k, V v, K k2, V v2) {
|
|
return ImmutableListMultimap.of((Object) k, (Object) v, (Object) k2, (Object) v2);
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> of(K k, V v, K k2, V v2, K k3, V v3) {
|
|
return ImmutableListMultimap.of((Object) k, (Object) v, (Object) k2, (Object) v2, (Object) k3, (Object) v3);
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> iterable) {
|
|
return ImmutableListMultimap.copyOf((Iterable) iterable);
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4) {
|
|
return ImmutableListMultimap.of((Object) k, (Object) v, (Object) k2, (Object) v2, (Object) k3, (Object) v3, (Object) k4, (Object) v4);
|
|
}
|
|
|
|
public static <K, V> ImmutableMultimap<K, V> of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
|
|
return ImmutableListMultimap.of((Object) k, (Object) v, (Object) k2, (Object) v2, (Object) k3, (Object) v3, (Object) k4, (Object) v4, (Object) k5, (Object) v5);
|
|
}
|
|
}
|