318 lines
13 KiB
Java
318 lines
13 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.ImmutableMultimap;
|
|
import com.google.common.collect.Serialization;
|
|
import java.io.IOException;
|
|
import java.io.InvalidObjectException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.util.Collection;
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class ImmutableListMultimap<K, V> extends ImmutableMultimap<K, V> implements ListMultimap<K, V> {
|
|
private static final long serialVersionUID = 0;
|
|
private transient ImmutableListMultimap<V, K> inverse;
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap
|
|
public /* bridge */ /* synthetic */ ImmutableCollection get(Object obj) {
|
|
return get((ImmutableListMultimap<K, V>) obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap
|
|
public /* bridge */ /* synthetic */ Collection get(Object obj) {
|
|
return get((ImmutableListMultimap<K, V>) obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap
|
|
public /* bridge */ /* synthetic */ List get(Object obj) {
|
|
return get((ImmutableListMultimap<K, V>) obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public /* bridge */ /* synthetic */ ImmutableCollection replaceValues(Object obj, Iterable iterable) {
|
|
return replaceValues((ImmutableListMultimap<K, V>) obj, iterable);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public /* bridge */ /* synthetic */ Collection replaceValues(Object obj, Iterable iterable) {
|
|
return replaceValues((ImmutableListMultimap<K, V>) obj, iterable);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public /* bridge */ /* synthetic */ List replaceValues(Object obj, Iterable iterable) {
|
|
return replaceValues((ImmutableListMultimap<K, V>) obj, iterable);
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> of() {
|
|
return EmptyImmutableListMultimap.INSTANCE;
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> of(K k, V v) {
|
|
Builder builder = builder();
|
|
builder.put((Builder) k, (K) v);
|
|
return builder.build();
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> of(K k, V v, K k2, V v2) {
|
|
Builder builder = builder();
|
|
builder.put((Builder) k, (K) v);
|
|
builder.put((Builder) k2, (K) v2);
|
|
return builder.build();
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> of(K k, V v, K k2, V v2, K k3, V v3) {
|
|
Builder builder = builder();
|
|
builder.put((Builder) k, (K) v);
|
|
builder.put((Builder) k2, (K) v2);
|
|
builder.put((Builder) k3, (K) v3);
|
|
return builder.build();
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4) {
|
|
Builder builder = builder();
|
|
builder.put((Builder) k, (K) v);
|
|
builder.put((Builder) k2, (K) v2);
|
|
builder.put((Builder) k3, (K) v3);
|
|
builder.put((Builder) k4, (K) v4);
|
|
return builder.build();
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> of(K k, V v, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
|
|
Builder builder = builder();
|
|
builder.put((Builder) k, (K) v);
|
|
builder.put((Builder) k2, (K) v2);
|
|
builder.put((Builder) k3, (K) v3);
|
|
builder.put((Builder) k4, (K) v4);
|
|
builder.put((Builder) k5, (K) v5);
|
|
return builder.build();
|
|
}
|
|
|
|
public static <K, V> Builder<K, V> builder() {
|
|
return new Builder<>();
|
|
}
|
|
|
|
/* loaded from: classes2.dex */
|
|
public static final class Builder<K, V> extends ImmutableMultimap.Builder<K, V> {
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final /* bridge */ /* synthetic */ ImmutableMultimap.Builder put(Object obj, Object obj2) {
|
|
return put((Builder<K, V>) obj, obj2);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final /* bridge */ /* synthetic */ ImmutableMultimap.Builder putAll(Object obj, Iterable iterable) {
|
|
return putAll((Builder<K, V>) obj, iterable);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final /* bridge */ /* synthetic */ ImmutableMultimap.Builder putAll(Object obj, Object[] objArr) {
|
|
return putAll((Builder<K, V>) obj, objArr);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> put(K k, V v) {
|
|
super.put((Builder<K, V>) k, (K) v);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> put(Map.Entry<? extends K, ? extends V> entry) {
|
|
super.put((Map.Entry) entry);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> putAll(Iterable<? extends Map.Entry<? extends K, ? extends V>> iterable) {
|
|
super.putAll((Iterable) iterable);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> putAll(K k, Iterable<? extends V> iterable) {
|
|
super.putAll((Builder<K, V>) k, (Iterable) iterable);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> putAll(K k, V... vArr) {
|
|
super.putAll((Builder<K, V>) k, (Object[]) vArr);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> putAll(Multimap<? extends K, ? extends V> multimap) {
|
|
super.putAll((Multimap) multimap);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> orderKeysBy(Comparator<? super K> comparator) {
|
|
super.orderKeysBy((Comparator) comparator);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> orderValuesBy(Comparator<? super V> comparator) {
|
|
super.orderValuesBy((Comparator) comparator);
|
|
return this;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final Builder<K, V> combine(ImmutableMultimap.Builder<K, V> builder) {
|
|
super.combine((ImmutableMultimap.Builder) builder);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap.Builder
|
|
public final ImmutableListMultimap<K, V> build() {
|
|
return (ImmutableListMultimap) super.build();
|
|
}
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> copyOf(Multimap<? extends K, ? extends V> multimap) {
|
|
if (multimap.isEmpty()) {
|
|
return of();
|
|
}
|
|
if (multimap instanceof ImmutableListMultimap) {
|
|
ImmutableListMultimap<K, V> immutableListMultimap = (ImmutableListMultimap) multimap;
|
|
if (!immutableListMultimap.isPartialView()) {
|
|
return immutableListMultimap;
|
|
}
|
|
}
|
|
return fromMapEntries(multimap.asMap().entrySet(), null);
|
|
}
|
|
|
|
public static <K, V> ImmutableListMultimap<K, V> copyOf(Iterable<? extends Map.Entry<? extends K, ? extends V>> iterable) {
|
|
return new Builder().putAll((Iterable) iterable).build();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static <K, V> ImmutableListMultimap<K, V> fromMapEntries(Collection<? extends Map.Entry<? extends K, ? extends Collection<? extends V>>> collection, Comparator<? super V> comparator) {
|
|
ImmutableList sortedCopyOf;
|
|
if (collection.isEmpty()) {
|
|
return of();
|
|
}
|
|
ImmutableMap.Builder builder = new ImmutableMap.Builder(collection.size());
|
|
int i = 0;
|
|
for (Map.Entry<? extends K, ? extends Collection<? extends V>> entry : collection) {
|
|
K key = entry.getKey();
|
|
Collection<? extends V> value = entry.getValue();
|
|
if (comparator == null) {
|
|
sortedCopyOf = ImmutableList.copyOf((Collection) value);
|
|
} else {
|
|
sortedCopyOf = ImmutableList.sortedCopyOf(comparator, value);
|
|
}
|
|
if (!sortedCopyOf.isEmpty()) {
|
|
builder.put(key, sortedCopyOf);
|
|
i += sortedCopyOf.size();
|
|
}
|
|
}
|
|
return new ImmutableListMultimap<>(builder.build(), i);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public ImmutableListMultimap(ImmutableMap<K, ImmutableList<V>> immutableMap, int i) {
|
|
super(immutableMap, i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap
|
|
public ImmutableList<V> get(K k) {
|
|
ImmutableList<V> immutableList = (ImmutableList) this.map.get(k);
|
|
return immutableList == null ? ImmutableList.of() : immutableList;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap
|
|
public ImmutableListMultimap<V, K> inverse() {
|
|
ImmutableListMultimap<V, K> immutableListMultimap = this.inverse;
|
|
if (immutableListMultimap != null) {
|
|
return immutableListMultimap;
|
|
}
|
|
ImmutableListMultimap<V, K> invert = invert();
|
|
this.inverse = invert;
|
|
return invert;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private ImmutableListMultimap<V, K> invert() {
|
|
Builder builder = builder();
|
|
UnmodifiableIterator it = entries().iterator();
|
|
while (it.hasNext()) {
|
|
Map.Entry entry = (Map.Entry) it.next();
|
|
builder.put((Builder) entry.getValue(), entry.getKey());
|
|
}
|
|
ImmutableListMultimap<V, K> build = builder.build();
|
|
build.inverse = this;
|
|
return build;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public final ImmutableList<V> removeAll(Object obj) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap
|
|
@Deprecated
|
|
public final ImmutableList<V> replaceValues(K k, Iterable<? extends V> iterable) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
|
|
objectOutputStream.defaultWriteObject();
|
|
Serialization.writeMultimap(this, objectOutputStream);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
objectInputStream.defaultReadObject();
|
|
int readInt = objectInputStream.readInt();
|
|
if (readInt < 0) {
|
|
StringBuilder sb = new StringBuilder(29);
|
|
sb.append("Invalid key count ");
|
|
sb.append(readInt);
|
|
throw new InvalidObjectException(sb.toString());
|
|
}
|
|
ImmutableMap.Builder builder = ImmutableMap.builder();
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < readInt; i2++) {
|
|
Object readObject = objectInputStream.readObject();
|
|
int readInt2 = objectInputStream.readInt();
|
|
if (readInt2 <= 0) {
|
|
StringBuilder sb2 = new StringBuilder(31);
|
|
sb2.append("Invalid value count ");
|
|
sb2.append(readInt2);
|
|
throw new InvalidObjectException(sb2.toString());
|
|
}
|
|
ImmutableList.Builder builder2 = ImmutableList.builder();
|
|
for (int i3 = 0; i3 < readInt2; i3++) {
|
|
builder2.add((ImmutableList.Builder) objectInputStream.readObject());
|
|
}
|
|
builder.put(readObject, builder2.build());
|
|
i += readInt2;
|
|
}
|
|
try {
|
|
ImmutableMultimap.FieldSettersHolder.MAP_FIELD_SETTER.set((Serialization.FieldSetter<ImmutableMultimap>) this, (Object) builder.build());
|
|
ImmutableMultimap.FieldSettersHolder.SIZE_FIELD_SETTER.set((Serialization.FieldSetter<ImmutableMultimap>) this, i);
|
|
} catch (IllegalArgumentException e) {
|
|
throw ((InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e));
|
|
}
|
|
}
|
|
}
|