package com.google.common.collect; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import com.google.common.primitives.Ints; import java.io.Serializable; import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; /* loaded from: classes.dex */ public final class Multisets { static abstract class AbstractEntry implements Multiset.Entry { AbstractEntry() { } public boolean equals(Object obj) { if (!(obj instanceof Multiset.Entry)) { return false; } Multiset.Entry entry = (Multiset.Entry) obj; return getCount() == entry.getCount() && Objects.a(a(), entry.a()); } public int hashCode() { E a = a(); return (a == null ? 0 : a.hashCode()) ^ getCount(); } @Override // com.google.common.collect.Multiset.Entry public String toString() { String valueOf = String.valueOf(a()); int count = getCount(); if (count == 1) { return valueOf; } return valueOf + " x " + count; } } static abstract class ElementSet extends Sets.ImprovedAbstractSet { ElementSet() { } abstract Multiset c(); @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { c().clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return c().contains(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean containsAll(Collection collection) { return c().containsAll(collection); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean isEmpty() { return c().isEmpty(); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return new TransformedIterator, E>(this, c().entrySet().iterator()) { // from class: com.google.common.collect.Multisets.ElementSet.1 /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.TransformedIterator public E a(Multiset.Entry entry) { return entry.a(); } }; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { return c().remove(obj, Integer.MAX_VALUE) > 0; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return c().entrySet().size(); } } static abstract class EntrySet extends Sets.ImprovedAbstractSet> { EntrySet() { } abstract Multiset c(); @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { c().clear(); } @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 && c().count(entry.a()) == 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 a = entry.a(); int count = entry.getCount(); if (count != 0) { return c().setCount(a, count, 0); } } return false; } } static class ImmutableEntry extends AbstractEntry implements Serializable { private final E a; private final int b; ImmutableEntry(E e, int i) { this.a = e; this.b = i; CollectPreconditions.a(i, "count"); } @Override // com.google.common.collect.Multiset.Entry public final E a() { return this.a; } @Override // com.google.common.collect.Multiset.Entry public final int getCount() { return this.b; } } static final class MultisetIteratorImpl implements Iterator { private final Multiset a; private final Iterator> b; private Multiset.Entry c; private int d; private int e; private boolean f; MultisetIteratorImpl(Multiset multiset, Iterator> it) { this.a = multiset; this.b = it; } @Override // java.util.Iterator public boolean hasNext() { return this.d > 0 || this.b.hasNext(); } @Override // java.util.Iterator public E next() { if (!hasNext()) { throw new NoSuchElementException(); } if (this.d == 0) { this.c = this.b.next(); int count = this.c.getCount(); this.d = count; this.e = count; } this.d--; this.f = true; return this.c.a(); } @Override // java.util.Iterator public void remove() { CollectPreconditions.a(this.f); if (this.e == 1) { this.b.remove(); } else { this.a.remove(this.c.a()); } this.e--; this.f = false; } } public static Multiset.Entry a(E e, int i) { return new ImmutableEntry(e, i); } static int b(Iterable iterable) { if (iterable instanceof Multiset) { return ((Multiset) iterable).elementSet().size(); } return 11; } static boolean c(Multiset multiset, Collection collection) { Preconditions.a(collection); if (collection instanceof Multiset) { collection = ((Multiset) collection).elementSet(); } return multiset.elementSet().retainAll(collection); } static boolean a(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.a()) != entry.getCount()) { return false; } } return true; } } return false; } static boolean b(Multiset multiset, Collection collection) { if (collection instanceof Multiset) { collection = ((Multiset) collection).elementSet(); } return multiset.elementSet().removeAll(collection); } static int b(Multiset multiset) { long j = 0; while (multiset.entrySet().iterator().hasNext()) { j += r4.next().getCount(); } return Ints.b(j); } static boolean a(Multiset multiset, Collection collection) { if (collection.isEmpty()) { return false; } if (collection instanceof Multiset) { for (Multiset.Entry entry : a(collection).entrySet()) { multiset.add(entry.a(), entry.getCount()); } return true; } Iterators.a(multiset, collection.iterator()); return true; } static int a(Multiset multiset, E e, int i) { CollectPreconditions.a(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; } static boolean a(Multiset multiset, E e, int i, int i2) { CollectPreconditions.a(i, "oldCount"); CollectPreconditions.a(i2, "newCount"); if (multiset.count(e) != i) { return false; } multiset.setCount(e, i2); return true; } static Iterator a(Multiset multiset) { return new MultisetIteratorImpl(multiset, multiset.entrySet().iterator()); } static Multiset a(Iterable iterable) { return (Multiset) iterable; } }