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 com.google.errorprone.annotations.concurrent.LazyInit; 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.Map; import java.util.Set; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ public class ImmutableSetMultimap extends ImmutableMultimap implements SetMultimap { private static final long serialVersionUID = 0; private final transient ImmutableSet emptySet; @CheckForNull @LazyInit private transient ImmutableSet> entries; @CheckForNull @LazyInit private transient ImmutableSetMultimap inverse; /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap, com.google.common.collect.ListMultimap 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, com.google.common.collect.ListMultimap 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, com.google.common.collect.ListMultimap 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, com.google.common.collect.ListMultimap @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, com.google.common.collect.ListMultimap @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, com.google.common.collect.ListMultimap @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: classes3.dex */ public static final class Builder extends ImmutableMultimap.Builder { /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultimap.Builder public /* 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 /* 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 /* bridge */ /* synthetic */ ImmutableMultimap.Builder putAll(Object obj, Object[] objArr) { return putAll((Builder) obj, objArr); } @Override // com.google.common.collect.ImmutableMultimap.Builder Collection newMutableValueCollection() { return Platform.preservesInsertionOrderOnAddsSet(); } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder put(K k, V v) { super.put((Builder) k, (K) v); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder put(Map.Entry entry) { super.put((Map.Entry) entry); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder putAll(Iterable> iterable) { super.putAll((Iterable) iterable); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder putAll(K k, Iterable iterable) { super.putAll((Builder) k, (Iterable) iterable); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder putAll(K k, V... vArr) { return putAll((Builder) k, (Iterable) Arrays.asList(vArr)); } @Override // com.google.common.collect.ImmutableMultimap.Builder public 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 Builder combine(ImmutableMultimap.Builder builder) { super.combine((ImmutableMultimap.Builder) builder); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder orderKeysBy(Comparator comparator) { super.orderKeysBy((Comparator) comparator); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public Builder orderValuesBy(Comparator comparator) { super.orderValuesBy((Comparator) comparator); return this; } @Override // com.google.common.collect.ImmutableMultimap.Builder public 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, @CheckForNull 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, @CheckForNull 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.buildOrThrow(), i, comparator); } /* JADX INFO: Access modifiers changed from: package-private */ public ImmutableSetMultimap(ImmutableMap> immutableMap, int i, @CheckForNull Comparator comparator) { super(immutableMap, i); this.emptySet = emptySet(comparator); } @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.Multimap, com.google.common.collect.ListMultimap 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(); UnmodifiableIterator 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, com.google.common.collect.ListMultimap @Deprecated public final ImmutableSet removeAll(@CheckForNull Object obj) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ImmutableMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap, com.google.common.collect.ListMultimap @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: private */ /* loaded from: classes3.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 boolean isPartialView() { return false; } EntrySet(ImmutableSetMultimap immutableSetMultimap) { this.multimap = immutableSetMultimap; } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(@CheckForNull 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 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 UnmodifiableIterator> iterator() { return this.multimap.entryIterator(); } } private static ImmutableSet valueSet(@CheckForNull Comparator comparator, Collection collection) { if (comparator == null) { return ImmutableSet.copyOf((Collection) collection); } return ImmutableSortedSet.copyOf((Comparator) comparator, (Collection) collection); } private static ImmutableSet emptySet(@CheckForNull Comparator comparator) { if (comparator == null) { return ImmutableSet.of(); } return ImmutableSortedSet.emptySet(comparator); } private static ImmutableSet.Builder valuesBuilder(@CheckForNull 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); } @CheckForNull Comparator valueComparator() { ImmutableSet immutableSet = this.emptySet; if (immutableSet instanceof ImmutableSortedSet) { return ((ImmutableSortedSet) immutableSet).comparator(); } return null; } /* loaded from: classes3.dex */ private 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) { throw new InvalidObjectException(new StringBuilder(29).append("Invalid key count ").append(readInt).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) { throw new InvalidObjectException(new StringBuilder(31).append("Invalid value count ").append(readInt2).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); throw new InvalidObjectException(new StringBuilder(String.valueOf(valueOf).length() + 40).append("Duplicate key-value pairs exist for key ").append(valueOf).toString()); } builder.put(readObject, build); i += readInt2; } try { ImmutableMultimap.FieldSettersHolder.MAP_FIELD_SETTER.set((Serialization.FieldSetter) this, (Object) builder.buildOrThrow()); 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)); } } }