package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multiset; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; /* loaded from: classes.dex */ public abstract class ImmutableMultiset extends ImmutableMultisetGwtSerializationDependencies implements Multiset { private transient ImmutableList asList; private transient ImmutableSet> entrySet; public static class Builder extends ImmutableCollection.Builder { AbstractObjectCountMap a; boolean b; boolean c; public Builder() { this(4); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableCollection.Builder public /* bridge */ /* synthetic */ ImmutableCollection.Builder a(Object obj) { return a((Builder) obj); } Builder(int i) { this.b = false; this.c = false; this.a = ObjectCountHashMap.h(i); } @Override // com.google.common.collect.ImmutableCollection.Builder public Builder a(E e) { return a((Builder) e, 1); } public Builder a(E e, int i) { if (i == 0) { return this; } if (this.b) { this.a = new ObjectCountHashMap(this.a); this.c = false; } this.b = false; Preconditions.a(e); AbstractObjectCountMap abstractObjectCountMap = this.a; abstractObjectCountMap.a(e, i + abstractObjectCountMap.a(e)); return this; } @Override // com.google.common.collect.ImmutableCollection.Builder public Builder a(E... eArr) { super.a((Object[]) eArr); return this; } @Override // com.google.common.collect.ImmutableCollection.Builder public Builder a(Iterable iterable) { if (iterable instanceof Multiset) { for (Multiset.Entry entry : Multisets.a(iterable).entrySet()) { a((Builder) entry.a(), entry.getCount()); } } else { super.a((Iterable) iterable); } return this; } @Override // com.google.common.collect.ImmutableCollection.Builder public Builder a(Iterator it) { super.a((Iterator) it); return this; } public ImmutableMultiset a() { if (this.a.f()) { return ImmutableMultiset.of(); } if (this.c) { this.a = new ObjectCountHashMap(this.a); this.c = false; } this.b = true; return new RegularImmutableMultiset((ObjectCountHashMap) this.a); } } private final class EntrySet extends ImmutableSet.Indexed> { private EntrySet() { } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (!(obj instanceof Multiset.Entry)) { return false; } Multiset.Entry entry = (Multiset.Entry) obj; return entry.getCount() > 0 && ImmutableMultiset.this.count(entry.a()) == entry.getCount(); } @Override // com.google.common.collect.ImmutableSet, java.util.Collection, java.util.Set public int hashCode() { return ImmutableMultiset.this.hashCode(); } @Override // com.google.common.collect.ImmutableCollection boolean isPartialView() { return ImmutableMultiset.this.isPartialView(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return ImmutableMultiset.this.elementSet().size(); } @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection Object writeReplace() { return new EntrySetSerializedForm(ImmutableMultiset.this); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableSet.Indexed public Multiset.Entry get(int i) { return ImmutableMultiset.this.getEntry(i); } } static class EntrySetSerializedForm implements Serializable { final ImmutableMultiset a; EntrySetSerializedForm(ImmutableMultiset immutableMultiset) { this.a = immutableMultiset; } Object readResolve() { return this.a.entrySet(); } } private static class SerializedForm implements Serializable { final Object[] a; final int[] b; SerializedForm(Multiset multiset) { int size = multiset.entrySet().size(); this.a = new Object[size]; this.b = new int[size]; int i = 0; for (Multiset.Entry entry : multiset.entrySet()) { this.a[i] = entry.a(); this.b[i] = entry.getCount(); i++; } } /* JADX WARN: Multi-variable type inference failed */ Object readResolve() { Builder builder = new Builder(this.a.length); int i = 0; while (true) { Object[] objArr = this.a; if (i >= objArr.length) { return builder.a(); } builder.a((Builder) objArr[i], this.b[i]); i++; } } } ImmutableMultiset() { } public static Builder builder() { return new Builder<>(); } private static ImmutableMultiset copyFromElements(E... eArr) { return new Builder().a((Object[]) eArr).a(); } static ImmutableMultiset copyFromEntries(Collection> collection) { Builder builder = new Builder(collection.size()); for (Multiset.Entry entry : collection) { builder.a((Builder) entry.a(), entry.getCount()); } return builder.a(); } public static ImmutableMultiset copyOf(E[] eArr) { return copyFromElements(eArr); } private final ImmutableSet> createEntrySet() { return isEmpty() ? ImmutableSet.of() : new EntrySet(); } public static ImmutableMultiset of() { return RegularImmutableMultiset.d; } @Override // com.google.common.collect.Multiset @Deprecated public final int add(E e, int i) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ImmutableCollection public ImmutableList asList() { ImmutableList immutableList = this.asList; if (immutableList != null) { return immutableList; } ImmutableList asList = super.asList(); this.asList = asList; return asList; } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return count(obj) > 0; } @Override // com.google.common.collect.ImmutableCollection int copyIntoArray(Object[] objArr, int i) { UnmodifiableIterator> it = entrySet().iterator(); while (it.hasNext()) { Multiset.Entry next = it.next(); Arrays.fill(objArr, i, next.getCount() + i, next.a()); i += next.getCount(); } return i; } @Override // com.google.common.collect.Multiset public abstract ImmutableSet elementSet(); @Override // java.util.Collection, com.google.common.collect.Multiset public boolean equals(Object obj) { return Multisets.a(this, obj); } abstract Multiset.Entry getEntry(int i); @Override // java.util.Collection, com.google.common.collect.Multiset public int hashCode() { return Sets.a(entrySet()); } @Override // com.google.common.collect.Multiset @Deprecated public final int remove(Object obj, int i) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.Multiset @Deprecated public final int setCount(E e, int i) { throw new UnsupportedOperationException(); } @Override // java.util.AbstractCollection public String toString() { return entrySet().toString(); } @Override // com.google.common.collect.ImmutableCollection Object writeReplace() { return new SerializedForm(this); } public static ImmutableMultiset copyOf(Iterable iterable) { if (iterable instanceof ImmutableMultiset) { ImmutableMultiset immutableMultiset = (ImmutableMultiset) iterable; if (!immutableMultiset.isPartialView()) { return immutableMultiset; } } Builder builder = new Builder(Multisets.b(iterable)); builder.a((Iterable) iterable); return builder.a(); } public static ImmutableMultiset of(E e) { return copyFromElements(e); } @Override // com.google.common.collect.Multiset public ImmutableSet> entrySet() { ImmutableSet> immutableSet = this.entrySet; if (immutableSet != null) { return immutableSet; } ImmutableSet> createEntrySet = createEntrySet(); this.entrySet = createEntrySet; return createEntrySet; } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet public UnmodifiableIterator iterator() { final UnmodifiableIterator> it = entrySet().iterator(); return new UnmodifiableIterator(this) { // from class: com.google.common.collect.ImmutableMultiset.1 int a; E b; @Override // java.util.Iterator public boolean hasNext() { return this.a > 0 || it.hasNext(); } @Override // java.util.Iterator public E next() { if (this.a <= 0) { Multiset.Entry entry = (Multiset.Entry) it.next(); this.b = (E) entry.a(); this.a = entry.getCount(); } this.a--; return this.b; } }; } @Override // com.google.common.collect.Multiset @Deprecated public final boolean setCount(E e, int i, int i2) { throw new UnsupportedOperationException(); } public static ImmutableMultiset of(E e, E e2) { return copyFromElements(e, e2); } public static ImmutableMultiset of(E e, E e2, E e3) { return copyFromElements(e, e2, e3); } public static ImmutableMultiset of(E e, E e2, E e3, E e4) { return copyFromElements(e, e2, e3, e4); } public static ImmutableMultiset of(E e, E e2, E e3, E e4, E e5) { return copyFromElements(e, e2, e3, e4, e5); } public static ImmutableMultiset of(E e, E e2, E e3, E e4, E e5, E e6, E... eArr) { return new Builder().a((Builder) e).a((Builder) e2).a((Builder) e3).a((Builder) e4).a((Builder) e5).a((Builder) e6).a((Object[]) eArr).a(); } public static ImmutableMultiset copyOf(Iterator it) { return new Builder().a((Iterator) it).a(); } }