package com.google.common.collect; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import com.google.common.math.IntMath; import com.google.common.primitives.Ints; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; /* loaded from: classes2.dex */ public final class Multisets { private Multisets() { } /* JADX WARN: Multi-variable type inference failed */ public static Multiset unmodifiableMultiset(Multiset multiset) { return ((multiset instanceof UnmodifiableMultiset) || (multiset instanceof ImmutableMultiset)) ? multiset : new UnmodifiableMultiset((Multiset) Preconditions.checkNotNull(multiset)); } @Deprecated public static Multiset unmodifiableMultiset(ImmutableMultiset immutableMultiset) { return (Multiset) Preconditions.checkNotNull(immutableMultiset); } /* loaded from: classes2.dex */ static class UnmodifiableMultiset extends ForwardingMultiset implements Serializable { private static final long serialVersionUID = 0; final Multiset delegate; transient Set elementSet; transient Set> entrySet; /* JADX INFO: Access modifiers changed from: package-private */ public UnmodifiableMultiset(Multiset multiset) { this.delegate = multiset; } Set createElementSet() { return Collections.unmodifiableSet(this.delegate.elementSet()); } @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.Multiset public Set elementSet() { Set set = this.elementSet; if (set != null) { return set; } Set createElementSet = createElementSet(); this.elementSet = createElementSet; return createElementSet; } @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.Multiset public Set> entrySet() { Set> set = this.entrySet; if (set != null) { return set; } Set> unmodifiableSet = Collections.unmodifiableSet(this.delegate.entrySet()); this.entrySet = unmodifiableSet; return unmodifiableSet; } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Iterators.unmodifiableIterator(this.delegate.iterator()); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Queue public boolean add(E e) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.Multiset public int add(E e, int i) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection public boolean addAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.Multiset public int remove(Object obj, int i) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean removeAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public boolean retainAll(Collection collection) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set public void clear() { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.Multiset public int setCount(E e, int i) { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.Multiset public boolean setCount(E e, int i, int i2) { throw new UnsupportedOperationException(); } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.ForwardingMultiset, com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingObject public Multiset delegate() { return this.delegate; } } public static SortedMultiset unmodifiableSortedMultiset(SortedMultiset sortedMultiset) { return new UnmodifiableSortedMultiset((SortedMultiset) Preconditions.checkNotNull(sortedMultiset)); } public static Multiset.Entry immutableEntry(E e, int i) { return new ImmutableEntry(e, i); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class ImmutableEntry extends AbstractEntry implements Serializable { private static final long serialVersionUID = 0; private final int count; private final E element; public ImmutableEntry nextInBucket() { return null; } ImmutableEntry(E e, int i) { this.element = e; this.count = i; CollectPreconditions.checkNonnegative(i, "count"); } @Override // com.google.common.collect.Multiset.Entry public final E getElement() { return this.element; } @Override // com.google.common.collect.Multiset.Entry public final int getCount() { return this.count; } } public static Multiset filter(Multiset multiset, Predicate predicate) { if (multiset instanceof FilteredMultiset) { FilteredMultiset filteredMultiset = (FilteredMultiset) multiset; return new FilteredMultiset(filteredMultiset.unfiltered, Predicates.and(filteredMultiset.predicate, predicate)); } return new FilteredMultiset(multiset, predicate); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class FilteredMultiset extends ViewMultiset { final Predicate predicate; final Multiset unfiltered; FilteredMultiset(Multiset multiset, Predicate predicate) { super(null); this.unfiltered = (Multiset) Preconditions.checkNotNull(multiset); this.predicate = (Predicate) Preconditions.checkNotNull(predicate); } @Override // com.google.common.collect.Multisets.ViewMultiset, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, com.google.common.collect.Multiset public final UnmodifiableIterator iterator() { return Iterators.filter(this.unfiltered.iterator(), this.predicate); } @Override // com.google.common.collect.AbstractMultiset final Set createElementSet() { return Sets.filter(this.unfiltered.elementSet(), this.predicate); } @Override // com.google.common.collect.AbstractMultiset final Iterator elementIterator() { throw new AssertionError("should never be called"); } @Override // com.google.common.collect.AbstractMultiset final Set> createEntrySet() { return Sets.filter(this.unfiltered.entrySet(), new Predicate>(this) { // from class: com.google.common.collect.Multisets.FilteredMultiset.1 final FilteredMultiset this$0; { this.this$0 = this; } @Override // com.google.common.base.Predicate public boolean apply(Multiset.Entry entry) { return this.this$0.predicate.apply(entry.getElement()); } }); } @Override // com.google.common.collect.AbstractMultiset final Iterator> entryIterator() { throw new AssertionError("should never be called"); } @Override // com.google.common.collect.Multiset public final int count(Object obj) { int count = this.unfiltered.count(obj); if (count <= 0 || !this.predicate.apply(obj)) { return 0; } return count; } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public final int add(E e, int i) { Preconditions.checkArgument(this.predicate.apply(e), "Element %s does not match predicate %s", e, this.predicate); return this.unfiltered.add(e, i); } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public final int remove(Object obj, int i) { CollectPreconditions.checkNonnegative(i, "occurrences"); if (i == 0) { return count(obj); } if (contains(obj)) { return this.unfiltered.remove(obj, i); } return 0; } } /* JADX INFO: Access modifiers changed from: package-private */ public static int inferDistinctElements(Iterable iterable) { if (iterable instanceof Multiset) { return ((Multiset) iterable).elementSet().size(); } return 11; } public static Multiset union(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); return new AnonymousClass1(multiset, multiset2); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX INFO: Add missing generic type declarations: [E] */ /* renamed from: com.google.common.collect.Multisets$1, reason: invalid class name */ /* loaded from: classes2.dex */ public class AnonymousClass1 extends ViewMultiset { final Multiset val$multiset1; final Multiset val$multiset2; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ AnonymousClass1(Multiset multiset, Multiset multiset2) { super(null); this.val$multiset1 = multiset; this.val$multiset2 = multiset2; } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public boolean contains(Object obj) { return this.val$multiset1.contains(obj) || this.val$multiset2.contains(obj); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public boolean isEmpty() { return this.val$multiset1.isEmpty() && this.val$multiset2.isEmpty(); } @Override // com.google.common.collect.Multiset public int count(Object obj) { return Math.max(this.val$multiset1.count(obj), this.val$multiset2.count(obj)); } @Override // com.google.common.collect.AbstractMultiset Set createElementSet() { return Sets.union(this.val$multiset1.elementSet(), this.val$multiset2.elementSet()); } @Override // com.google.common.collect.AbstractMultiset Iterator elementIterator() { throw new AssertionError("should never be called"); } @Override // com.google.common.collect.AbstractMultiset Iterator> entryIterator() { return new AbstractIterator>(this, this.val$multiset1.entrySet().iterator(), this.val$multiset2.entrySet().iterator()) { // from class: com.google.common.collect.Multisets.1.1 final AnonymousClass1 this$0; final Iterator val$iterator1; final Iterator val$iterator2; { this.this$0 = this; this.val$iterator1 = r2; this.val$iterator2 = r3; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIterator public Multiset.Entry computeNext() { if (this.val$iterator1.hasNext()) { Multiset.Entry entry = (Multiset.Entry) this.val$iterator1.next(); Object element = entry.getElement(); return Multisets.immutableEntry(element, Math.max(entry.getCount(), this.this$0.val$multiset2.count(element))); } while (this.val$iterator2.hasNext()) { Multiset.Entry entry2 = (Multiset.Entry) this.val$iterator2.next(); Object element2 = entry2.getElement(); if (!this.this$0.val$multiset1.contains(element2)) { return Multisets.immutableEntry(element2, entry2.getCount()); } } return endOfData(); } }; } } public static Multiset intersection(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); return new AnonymousClass2(multiset, multiset2); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX INFO: Add missing generic type declarations: [E] */ /* renamed from: com.google.common.collect.Multisets$2, reason: invalid class name */ /* loaded from: classes2.dex */ public class AnonymousClass2 extends ViewMultiset { final Multiset val$multiset1; final Multiset val$multiset2; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ AnonymousClass2(Multiset multiset, Multiset multiset2) { super(null); this.val$multiset1 = multiset; this.val$multiset2 = multiset2; } @Override // com.google.common.collect.Multiset public int count(Object obj) { int count = this.val$multiset1.count(obj); if (count == 0) { return 0; } return Math.min(count, this.val$multiset2.count(obj)); } @Override // com.google.common.collect.AbstractMultiset Set createElementSet() { return Sets.intersection(this.val$multiset1.elementSet(), this.val$multiset2.elementSet()); } @Override // com.google.common.collect.AbstractMultiset Iterator elementIterator() { throw new AssertionError("should never be called"); } @Override // com.google.common.collect.AbstractMultiset Iterator> entryIterator() { return new AbstractIterator>(this, this.val$multiset1.entrySet().iterator()) { // from class: com.google.common.collect.Multisets.2.1 final AnonymousClass2 this$0; final Iterator val$iterator1; { this.this$0 = this; this.val$iterator1 = r2; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIterator public Multiset.Entry computeNext() { while (this.val$iterator1.hasNext()) { Multiset.Entry entry = (Multiset.Entry) this.val$iterator1.next(); Object element = entry.getElement(); int min = Math.min(entry.getCount(), this.this$0.val$multiset2.count(element)); if (min > 0) { return Multisets.immutableEntry(element, min); } } return endOfData(); } }; } } public static Multiset sum(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); return new AnonymousClass3(multiset, multiset2); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX INFO: Add missing generic type declarations: [E] */ /* renamed from: com.google.common.collect.Multisets$3, reason: invalid class name */ /* loaded from: classes2.dex */ public class AnonymousClass3 extends ViewMultiset { final Multiset val$multiset1; final Multiset val$multiset2; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ AnonymousClass3(Multiset multiset, Multiset multiset2) { super(null); this.val$multiset1 = multiset; this.val$multiset2 = multiset2; } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public boolean contains(Object obj) { return this.val$multiset1.contains(obj) || this.val$multiset2.contains(obj); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public boolean isEmpty() { return this.val$multiset1.isEmpty() && this.val$multiset2.isEmpty(); } @Override // com.google.common.collect.Multisets.ViewMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public int size() { return IntMath.saturatedAdd(this.val$multiset1.size(), this.val$multiset2.size()); } @Override // com.google.common.collect.Multiset public int count(Object obj) { return this.val$multiset1.count(obj) + this.val$multiset2.count(obj); } @Override // com.google.common.collect.AbstractMultiset Set createElementSet() { return Sets.union(this.val$multiset1.elementSet(), this.val$multiset2.elementSet()); } @Override // com.google.common.collect.AbstractMultiset Iterator elementIterator() { throw new AssertionError("should never be called"); } @Override // com.google.common.collect.AbstractMultiset Iterator> entryIterator() { return new AbstractIterator>(this, this.val$multiset1.entrySet().iterator(), this.val$multiset2.entrySet().iterator()) { // from class: com.google.common.collect.Multisets.3.1 final AnonymousClass3 this$0; final Iterator val$iterator1; final Iterator val$iterator2; { this.this$0 = this; this.val$iterator1 = r2; this.val$iterator2 = r3; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIterator public Multiset.Entry computeNext() { if (this.val$iterator1.hasNext()) { Multiset.Entry entry = (Multiset.Entry) this.val$iterator1.next(); Object element = entry.getElement(); return Multisets.immutableEntry(element, entry.getCount() + this.this$0.val$multiset2.count(element)); } while (this.val$iterator2.hasNext()) { Multiset.Entry entry2 = (Multiset.Entry) this.val$iterator2.next(); Object element2 = entry2.getElement(); if (!this.this$0.val$multiset1.contains(element2)) { return Multisets.immutableEntry(element2, entry2.getCount()); } } return endOfData(); } }; } } public static Multiset difference(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); return new AnonymousClass4(multiset, multiset2); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX INFO: Add missing generic type declarations: [E] */ /* renamed from: com.google.common.collect.Multisets$4, reason: invalid class name */ /* loaded from: classes2.dex */ public class AnonymousClass4 extends ViewMultiset { final Multiset val$multiset1; final Multiset val$multiset2; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ AnonymousClass4(Multiset multiset, Multiset multiset2) { super(null); this.val$multiset1 = multiset; this.val$multiset2 = multiset2; } @Override // com.google.common.collect.Multiset public int count(Object obj) { int count = this.val$multiset1.count(obj); if (count != 0) { return Math.max(0, count - this.val$multiset2.count(obj)); } return 0; } @Override // com.google.common.collect.Multisets.ViewMultiset, com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public void clear() { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.AbstractMultiset Iterator elementIterator() { return new AbstractIterator(this, this.val$multiset1.entrySet().iterator()) { // from class: com.google.common.collect.Multisets.4.1 final AnonymousClass4 this$0; final Iterator val$iterator1; { this.this$0 = this; this.val$iterator1 = r2; } @Override // com.google.common.collect.AbstractIterator protected E computeNext() { while (this.val$iterator1.hasNext()) { Multiset.Entry entry = (Multiset.Entry) this.val$iterator1.next(); E e = (E) entry.getElement(); if (entry.getCount() > this.this$0.val$multiset2.count(e)) { return e; } } return endOfData(); } }; } @Override // com.google.common.collect.AbstractMultiset Iterator> entryIterator() { return new AbstractIterator>(this, this.val$multiset1.entrySet().iterator()) { // from class: com.google.common.collect.Multisets.4.2 final AnonymousClass4 this$0; final Iterator val$iterator1; { this.this$0 = this; this.val$iterator1 = r2; } /* JADX INFO: Access modifiers changed from: protected */ @Override // com.google.common.collect.AbstractIterator public Multiset.Entry computeNext() { while (this.val$iterator1.hasNext()) { Multiset.Entry entry = (Multiset.Entry) this.val$iterator1.next(); Object element = entry.getElement(); int count = entry.getCount() - this.this$0.val$multiset2.count(element); if (count > 0) { return Multisets.immutableEntry(element, count); } } return endOfData(); } }; } @Override // com.google.common.collect.Multisets.ViewMultiset, com.google.common.collect.AbstractMultiset int distinctElements() { return Iterators.size(entryIterator()); } } public static boolean containsOccurrences(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); for (Multiset.Entry entry : multiset2.entrySet()) { if (multiset.count(entry.getElement()) < entry.getCount()) { return false; } } return true; } public static boolean retainOccurrences(Multiset multiset, Multiset multiset2) { return retainOccurrencesImpl(multiset, multiset2); } private static boolean retainOccurrencesImpl(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); Iterator> it = multiset.entrySet().iterator(); boolean z = false; while (it.hasNext()) { Multiset.Entry next = it.next(); int count = multiset2.count(next.getElement()); if (count == 0) { it.remove(); } else if (count < next.getCount()) { multiset.setCount(next.getElement(), count); } z = true; } return z; } public static boolean removeOccurrences(Multiset multiset, Iterable iterable) { if (iterable instanceof Multiset) { return removeOccurrences(multiset, (Multiset) iterable); } Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(iterable); Iterator it = iterable.iterator(); boolean z = false; while (it.hasNext()) { z |= multiset.remove(it.next()); } return z; } public static boolean removeOccurrences(Multiset multiset, Multiset multiset2) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(multiset2); Iterator> it = multiset.entrySet().iterator(); boolean z = false; while (it.hasNext()) { Multiset.Entry next = it.next(); int count = multiset2.count(next.getElement()); if (count >= next.getCount()) { it.remove(); } else if (count > 0) { multiset.remove(next.getElement(), count); } z = true; } return z; } /* loaded from: classes2.dex */ static abstract class AbstractEntry implements Multiset.Entry { @Override // com.google.common.collect.Multiset.Entry public boolean equals(Object obj) { if (!(obj instanceof Multiset.Entry)) { return false; } Multiset.Entry entry = (Multiset.Entry) obj; return getCount() == entry.getCount() && Objects.equal(getElement(), entry.getElement()); } @Override // com.google.common.collect.Multiset.Entry public int hashCode() { E element = getElement(); return (element == null ? 0 : element.hashCode()) ^ getCount(); } @Override // com.google.common.collect.Multiset.Entry public String toString() { String valueOf = String.valueOf(getElement()); int count = getCount(); if (count == 1) { return valueOf; } StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 14); sb.append(valueOf); sb.append(" x "); sb.append(count); return sb.toString(); } } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean equalsImpl(Multiset multiset, Object obj) { if (obj == multiset) { return true; } if (obj instanceof Multiset) { Multiset multiset2 = (Multiset) obj; if (multiset.size() == multiset2.size() && multiset.entrySet().size() == multiset2.entrySet().size()) { for (Multiset.Entry entry : multiset2.entrySet()) { if (multiset.count(entry.getElement()) != entry.getCount()) { return false; } } return true; } } return false; } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean addAllImpl(Multiset multiset, Collection collection) { Preconditions.checkNotNull(multiset); Preconditions.checkNotNull(collection); if (collection instanceof Multiset) { return addAllImpl((Multiset) multiset, cast(collection)); } if (collection.isEmpty()) { return false; } return Iterators.addAll(multiset, collection.iterator()); } private static boolean addAllImpl(Multiset multiset, Multiset multiset2) { if (multiset2 instanceof AbstractMapBasedMultiset) { return addAllImpl((Multiset) multiset, (AbstractMapBasedMultiset) multiset2); } if (multiset2.isEmpty()) { return false; } for (Multiset.Entry entry : multiset2.entrySet()) { multiset.add(entry.getElement(), entry.getCount()); } return true; } private static boolean addAllImpl(Multiset multiset, AbstractMapBasedMultiset abstractMapBasedMultiset) { if (abstractMapBasedMultiset.isEmpty()) { return false; } abstractMapBasedMultiset.addTo(multiset); return true; } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean removeAllImpl(Multiset multiset, Collection collection) { if (collection instanceof Multiset) { collection = ((Multiset) collection).elementSet(); } return multiset.elementSet().removeAll(collection); } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean retainAllImpl(Multiset multiset, Collection collection) { Preconditions.checkNotNull(collection); if (collection instanceof Multiset) { collection = ((Multiset) collection).elementSet(); } return multiset.elementSet().retainAll(collection); } /* JADX INFO: Access modifiers changed from: package-private */ public static int setCountImpl(Multiset multiset, E e, int i) { CollectPreconditions.checkNonnegative(i, "count"); int count = multiset.count(e); int i2 = i - count; if (i2 > 0) { multiset.add(e, i2); } else if (i2 < 0) { multiset.remove(e, -i2); } return count; } /* JADX INFO: Access modifiers changed from: package-private */ public static boolean setCountImpl(Multiset multiset, E e, int i, int i2) { CollectPreconditions.checkNonnegative(i, "oldCount"); CollectPreconditions.checkNonnegative(i2, "newCount"); if (multiset.count(e) != i) { return false; } multiset.setCount(e, i2); return true; } /* JADX INFO: Access modifiers changed from: package-private */ public static Iterator elementIterator(Iterator> it) { return new TransformedIterator, E>(it) { // from class: com.google.common.collect.Multisets.5 /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.TransformedIterator public E transform(Multiset.Entry entry) { return entry.getElement(); } }; } /* loaded from: classes2.dex */ static abstract class ElementSet extends Sets.ImprovedAbstractSet { @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public abstract Iterator iterator(); abstract Multiset multiset(); @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { multiset().clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return multiset().contains(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean containsAll(Collection collection) { return multiset().containsAll(collection); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean isEmpty() { return multiset().isEmpty(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { return multiset().remove(obj, Integer.MAX_VALUE) > 0; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return multiset().entrySet().size(); } } /* loaded from: classes2.dex */ static abstract class EntrySet extends Sets.ImprovedAbstractSet> { abstract Multiset multiset(); @Override // 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 && multiset().count(entry.getElement()) == entry.getCount(); } /* JADX WARN: Multi-variable type inference failed */ @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (obj instanceof Multiset.Entry) { Multiset.Entry entry = (Multiset.Entry) obj; Object element = entry.getElement(); int count = entry.getCount(); if (count != 0) { return multiset().setCount(element, count, 0); } } return false; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { multiset().clear(); } } /* JADX INFO: Access modifiers changed from: package-private */ public static Iterator iteratorImpl(Multiset multiset) { return new MultisetIteratorImpl(multiset, multiset.entrySet().iterator()); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class MultisetIteratorImpl implements Iterator { private boolean canRemove; private Multiset.Entry currentEntry; private final Iterator> entryIterator; private int laterCount; private final Multiset multiset; private int totalCount; MultisetIteratorImpl(Multiset multiset, Iterator> it) { this.multiset = multiset; this.entryIterator = it; } @Override // java.util.Iterator public final boolean hasNext() { return this.laterCount > 0 || this.entryIterator.hasNext(); } @Override // java.util.Iterator public final E next() { if (!hasNext()) { throw new NoSuchElementException(); } if (this.laterCount == 0) { Multiset.Entry next = this.entryIterator.next(); this.currentEntry = next; int count = next.getCount(); this.laterCount = count; this.totalCount = count; } this.laterCount--; this.canRemove = true; return this.currentEntry.getElement(); } @Override // java.util.Iterator public final void remove() { CollectPreconditions.checkRemove(this.canRemove); if (this.totalCount == 1) { this.entryIterator.remove(); } else { this.multiset.remove(this.currentEntry.getElement()); } this.totalCount--; this.canRemove = false; } } /* JADX INFO: Access modifiers changed from: package-private */ public static int linearTimeSizeImpl(Multiset multiset) { long j = 0; while (multiset.entrySet().iterator().hasNext()) { j += r4.next().getCount(); } return Ints.saturatedCast(j); } /* JADX INFO: Access modifiers changed from: package-private */ public static Multiset cast(Iterable iterable) { return (Multiset) iterable; } public static ImmutableMultiset copyHighestCountFirst(Multiset multiset) { Multiset.Entry[] entryArr = (Multiset.Entry[]) multiset.entrySet().toArray(new Multiset.Entry[0]); Arrays.sort(entryArr, DecreasingCount.INSTANCE); return ImmutableMultiset.copyFromEntries(Arrays.asList(entryArr)); } /* loaded from: classes2.dex */ static final class DecreasingCount implements Comparator> { static final DecreasingCount INSTANCE = new DecreasingCount(); private DecreasingCount() { } @Override // java.util.Comparator public final int compare(Multiset.Entry entry, Multiset.Entry entry2) { return entry2.getCount() - entry.getCount(); } } /* loaded from: classes2.dex */ static abstract class ViewMultiset extends AbstractMultiset { private ViewMultiset() { } /* synthetic */ ViewMultiset(AnonymousClass1 anonymousClass1) { this(); } @Override // java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public int size() { return Multisets.linearTimeSizeImpl(this); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public void clear() { elementSet().clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, com.google.common.collect.Multiset public Iterator iterator() { return Multisets.iteratorImpl(this); } @Override // com.google.common.collect.AbstractMultiset int distinctElements() { return elementSet().size(); } } }