package com.google.common.collect; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; 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.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.Map; import java.util.Set; /* loaded from: classes2.dex */ public class ImmutableSetMultimap extends ImmutableMultimap implements SetMultimap { private static final long serialVersionUID = 0; private final transient ImmutableSet emptySet; private transient ImmutableSet> entries; private transient ImmutableSetMultimap 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((ImmutableSetMultimap) 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((ImmutableSetMultimap) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap public /* bridge */ /* synthetic */ Set get(Object obj) { return get((ImmutableSetMultimap) 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((ImmutableSetMultimap) 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((ImmutableSetMultimap) 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 */ Set replaceValues(Object obj, Iterable iterable) { return replaceValues((ImmutableSetMultimap) obj, iterable); } public static ImmutableSetMultimap of() { return EmptyImmutableSetMultimap.INSTANCE; } public static ImmutableSetMultimap of(K k, V v) { Builder builder = builder(); builder.put((Builder) k, (K) v); return builder.build(); } public static ImmutableSetMultimap 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 ImmutableSetMultimap 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 ImmutableSetMultimap 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 ImmutableSetMultimap 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 Builder builder() { return new Builder<>(); } /* loaded from: classes2.dex */ public static final class Builder extends ImmutableMultimap.Builder { /* 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) 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) 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) obj, objArr); } @Override // com.google.common.collect.ImmutableMultimap.Builder final Collection newMutableValueCollection() { return Platform.preservesInsertionOrderOnAddsSet(); } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder put(K k, V v) { super.put((Builder) k, (K) v); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder put(Map.Entry entry) { super.put((Map.Entry) entry); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder putAll(Iterable> iterable) { super.putAll((Iterable) iterable); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder putAll(K k, Iterable iterable) { super.putAll((Builder) k, (Iterable) iterable); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder putAll(K k, V... vArr) { return putAll((Builder) k, (Iterable) Arrays.asList(vArr)); } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder putAll(Multimap multimap) { for (Map.Entry> entry : multimap.asMap().entrySet()) { putAll((Builder) entry.getKey(), (Iterable) entry.getValue()); } return this; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder combine(ImmutableMultimap.Builder builder) { super.combine((ImmutableMultimap.Builder) builder); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder orderKeysBy(Comparator comparator) { super.orderKeysBy((Comparator) comparator); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final Builder orderValuesBy(Comparator comparator) { super.orderValuesBy((Comparator) comparator); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public final ImmutableSetMultimap build() { Collection entrySet = this.builderMap.entrySet(); if (this.keyComparator != null) { entrySet = Ordering.from(this.keyComparator).onKeys().immutableSortedCopy(entrySet); } return ImmutableSetMultimap.fromMapEntries(entrySet, this.valueComparator); } } public static ImmutableSetMultimap copyOf(Multimap multimap) { return copyOf(multimap, null); } private static ImmutableSetMultimap copyOf(Multimap multimap, Comparator comparator) { Preconditions.checkNotNull(multimap); if (multimap.isEmpty() && comparator == null) { return of(); } if (multimap instanceof ImmutableSetMultimap) { ImmutableSetMultimap immutableSetMultimap = (ImmutableSetMultimap) multimap; if (!immutableSetMultimap.isPartialView()) { return immutableSetMultimap; } } return fromMapEntries(multimap.asMap().entrySet(), comparator); } public static ImmutableSetMultimap copyOf(Iterable> iterable) { return new Builder().putAll((Iterable) iterable).build(); } static ImmutableSetMultimap fromMapEntries(Collection>> collection, Comparator comparator) { if (collection.isEmpty()) { return of(); } ImmutableMap.Builder builder = new ImmutableMap.Builder(collection.size()); int i = 0; for (Map.Entry> entry : collection) { K key = entry.getKey(); ImmutableSet valueSet = valueSet(comparator, entry.getValue()); if (!valueSet.isEmpty()) { builder.put(key, valueSet); i += valueSet.size(); } } return new ImmutableSetMultimap<>(builder.build(), i, comparator); } /* JADX INFO: Access modifiers changed from: package-private */ public ImmutableSetMultimap(ImmutableMap> immutableMap, int i, Comparator comparator) { super(immutableMap, i); this.emptySet = emptySet(comparator); } @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap public ImmutableSet get(K k) { return (ImmutableSet) MoreObjects.firstNonNull((ImmutableSet) this.map.get(k), this.emptySet); } @Override // com.google.common.collect.ImmutableMultimap public ImmutableSetMultimap inverse() { ImmutableSetMultimap immutableSetMultimap = this.inverse; if (immutableSetMultimap != null) { return immutableSetMultimap; } ImmutableSetMultimap invert = invert(); this.inverse = invert; return invert; } /* JADX WARN: Multi-variable type inference failed */ private ImmutableSetMultimap invert() { Builder builder = builder(); Iterator it = entries().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); builder.put((Builder) entry.getValue(), entry.getKey()); } ImmutableSetMultimap build = builder.build(); build.inverse = this; return build; } @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap @Deprecated public final ImmutableSet 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 ImmutableSet replaceValues(K k, Iterable iterable) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public ImmutableSet> entries() { ImmutableSet> immutableSet = this.entries; if (immutableSet != null) { return immutableSet; } EntrySet entrySet = new EntrySet(this); this.entries = entrySet; return entrySet; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class EntrySet extends ImmutableSet> { private final transient ImmutableSetMultimap multimap; /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableCollection public final boolean isPartialView() { return false; } @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet, com.google.common.collect.SortedIterable public final /* bridge */ /* synthetic */ Iterator iterator() { return iterator(); } EntrySet(ImmutableSetMultimap immutableSetMultimap) { this.multimap = immutableSetMultimap; } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return this.multimap.containsEntry(entry.getKey(), entry.getValue()); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final int size() { return this.multimap.size(); } @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet, com.google.common.collect.SortedIterable public final UnmodifiableIterator> iterator() { return this.multimap.entryIterator(); } } private static ImmutableSet valueSet(Comparator comparator, Collection collection) { if (comparator == null) { return ImmutableSet.copyOf((Collection) collection); } return ImmutableSortedSet.copyOf((Comparator) comparator, (Collection) collection); } private static ImmutableSet emptySet(Comparator comparator) { if (comparator == null) { return ImmutableSet.of(); } return ImmutableSortedSet.emptySet(comparator); } private static ImmutableSet.Builder valuesBuilder(Comparator comparator) { if (comparator == null) { return new ImmutableSet.Builder<>(); } return new ImmutableSortedSet.Builder(comparator); } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); objectOutputStream.writeObject(valueComparator()); Serialization.writeMultimap(this, objectOutputStream); } Comparator valueComparator() { ImmutableSet immutableSet = this.emptySet; if (immutableSet instanceof ImmutableSortedSet) { return ((ImmutableSortedSet) immutableSet).comparator(); } return null; } /* loaded from: classes2.dex */ static final class SetFieldSettersHolder { static final Serialization.FieldSetter EMPTY_SET_FIELD_SETTER = Serialization.getFieldSetter(ImmutableSetMultimap.class, "emptySet"); private SetFieldSettersHolder() { } } /* JADX WARN: Multi-variable type inference failed */ private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); Comparator comparator = (Comparator) objectInputStream.readObject(); 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()); } ImmutableSet.Builder valuesBuilder = valuesBuilder(comparator); for (int i3 = 0; i3 < readInt2; i3++) { valuesBuilder.add((ImmutableSet.Builder) objectInputStream.readObject()); } ImmutableSet build = valuesBuilder.build(); if (build.size() != readInt2) { String valueOf = String.valueOf(readObject); StringBuilder sb3 = new StringBuilder(String.valueOf(valueOf).length() + 40); sb3.append("Duplicate key-value pairs exist for key "); sb3.append(valueOf); throw new InvalidObjectException(sb3.toString()); } builder.put(readObject, build); i += readInt2; } try { ImmutableMultimap.FieldSettersHolder.MAP_FIELD_SETTER.set((Serialization.FieldSetter) this, (Object) builder.build()); ImmutableMultimap.FieldSettersHolder.SIZE_FIELD_SETTER.set((Serialization.FieldSetter) this, i); SetFieldSettersHolder.EMPTY_SET_FIELD_SETTER.set((Serialization.FieldSetter) this, (Object) emptySet(comparator)); } catch (IllegalArgumentException e) { throw ((InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e)); } } }