package com.google.common.collect; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.Multiset; import com.google.common.collect.Multisets; import com.google.common.collect.Serialization; import com.google.common.primitives.Ints; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.NavigableSet; import java.util.NoSuchElementException; import java.util.Set; /* loaded from: classes.dex */ public final class TreeMultiset extends AbstractSortedMultiset implements Serializable { private static final long serialVersionUID = 1; private final transient AvlNode header; private final transient GeneralRange range; private final transient Reference> rootReference; /* renamed from: com.google.common.collect.TreeMultiset$4, reason: invalid class name */ static /* synthetic */ class AnonymousClass4 { static final /* synthetic */ int[] a = new int[BoundType.values().length]; static { try { a[BoundType.OPEN.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { a[BoundType.CLOSED.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } private enum Aggregate { SIZE { // from class: com.google.common.collect.TreeMultiset.Aggregate.1 @Override // com.google.common.collect.TreeMultiset.Aggregate int a(AvlNode avlNode) { return ((AvlNode) avlNode).b; } @Override // com.google.common.collect.TreeMultiset.Aggregate long b(AvlNode avlNode) { if (avlNode == null) { return 0L; } return ((AvlNode) avlNode).d; } }, DISTINCT { // from class: com.google.common.collect.TreeMultiset.Aggregate.2 @Override // com.google.common.collect.TreeMultiset.Aggregate int a(AvlNode avlNode) { return 1; } @Override // com.google.common.collect.TreeMultiset.Aggregate long b(AvlNode avlNode) { if (avlNode == null) { return 0L; } return ((AvlNode) avlNode).c; } }; abstract int a(AvlNode avlNode); abstract long b(AvlNode avlNode); } private static final class AvlNode extends Multisets.AbstractEntry { private final E a; private int b; private int c; private long d; private int e; private AvlNode f; private AvlNode g; private AvlNode h; private AvlNode i; AvlNode(E e, int i) { Preconditions.a(i > 0); this.a = e; this.b = i; this.d = i; this.c = 1; this.e = 1; this.f = null; this.g = null; } private AvlNode i() { Preconditions.b(this.f != null); AvlNode avlNode = this.f; this.f = avlNode.g; avlNode.g = this; avlNode.d = this.d; avlNode.c = this.c; e(); avlNode.f(); return avlNode; } private AvlNode j(AvlNode avlNode) { AvlNode avlNode2 = this.g; if (avlNode2 == null) { return this.f; } this.g = avlNode2.j(avlNode); this.c--; this.d -= avlNode.b; return d(); } private AvlNode k(AvlNode avlNode) { AvlNode avlNode2 = this.f; if (avlNode2 == null) { return this.g; } this.f = avlNode2.k(avlNode); this.c--; this.d -= avlNode.b; return d(); } private static long l(AvlNode avlNode) { if (avlNode == null) { return 0L; } return ((AvlNode) avlNode).d; } @Override // com.google.common.collect.Multiset.Entry public int getCount() { return this.b; } @Override // com.google.common.collect.Multisets.AbstractEntry, com.google.common.collect.Multiset.Entry public String toString() { return Multisets.a(a(), getCount()).toString(); } private AvlNode d() { int b = b(); if (b == -2) { if (this.g.b() > 0) { this.g = this.g.i(); } return h(); } if (b != 2) { f(); return this; } if (this.f.b() < 0) { this.f = this.f.h(); } return i(); } private void e() { g(); f(); } private void f() { this.e = Math.max(i(this.f), i(this.g)) + 1; } private void g() { this.c = TreeMultiset.distinctElements(this.f) + 1 + TreeMultiset.distinctElements(this.g); this.d = this.b + l(this.f) + l(this.g); } private AvlNode h() { Preconditions.b(this.g != null); AvlNode avlNode = this.g; this.g = avlNode.f; avlNode.f = this; avlNode.d = this.d; avlNode.c = this.c; e(); avlNode.f(); return avlNode; } /* JADX WARN: Multi-variable type inference failed */ AvlNode c(Comparator comparator, E e, int i, int[] iArr) { int compare = comparator.compare(e, this.a); if (compare < 0) { AvlNode avlNode = this.f; if (avlNode == null) { iArr[0] = 0; if (i > 0) { a((AvlNode) e, i); } return this; } this.f = avlNode.c(comparator, e, i, iArr); if (i == 0 && iArr[0] != 0) { this.c--; } else if (i > 0 && iArr[0] == 0) { this.c++; } this.d += i - iArr[0]; return d(); } if (compare <= 0) { iArr[0] = this.b; if (i == 0) { return c(); } this.d += i - r3; this.b = i; return this; } AvlNode avlNode2 = this.g; if (avlNode2 == null) { iArr[0] = 0; if (i > 0) { b((AvlNode) e, i); } return this; } this.g = avlNode2.c(comparator, e, i, iArr); if (i == 0 && iArr[0] != 0) { this.c--; } else if (i > 0 && iArr[0] == 0) { this.c++; } this.d += i - iArr[0]; return d(); } private AvlNode b(E e, int i) { this.g = new AvlNode<>(e, i); TreeMultiset.successor(this, this.g, this.i); this.e = Math.max(2, this.e); this.c++; this.d += i; return this; } /* JADX WARN: Multi-variable type inference failed */ public int a(Comparator comparator, E e) { int compare = comparator.compare(e, this.a); if (compare < 0) { AvlNode avlNode = this.f; if (avlNode == null) { return 0; } return avlNode.a((Comparator>) comparator, (Comparator) e); } if (compare > 0) { AvlNode avlNode2 = this.g; if (avlNode2 == null) { return 0; } return avlNode2.a((Comparator>) comparator, (Comparator) e); } return this.b; } private AvlNode a(E e, int i) { this.f = new AvlNode<>(e, i); TreeMultiset.successor(this.h, this.f, this); this.e = Math.max(2, this.e); this.c++; this.d += i; return this; } private static int i(AvlNode avlNode) { if (avlNode == null) { return 0; } return ((AvlNode) avlNode).e; } /* JADX WARN: Multi-variable type inference failed */ AvlNode b(Comparator comparator, E e, int i, int[] iArr) { int compare = comparator.compare(e, this.a); if (compare < 0) { AvlNode avlNode = this.f; if (avlNode == null) { iArr[0] = 0; return this; } this.f = avlNode.b(comparator, e, i, iArr); if (iArr[0] > 0) { if (i >= iArr[0]) { this.c--; this.d -= iArr[0]; } else { this.d -= i; } } return iArr[0] == 0 ? this : d(); } if (compare > 0) { AvlNode avlNode2 = this.g; if (avlNode2 == null) { iArr[0] = 0; return this; } this.g = avlNode2.b(comparator, e, i, iArr); if (iArr[0] > 0) { if (i >= iArr[0]) { this.c--; this.d -= iArr[0]; } else { this.d -= i; } } return d(); } int i2 = this.b; iArr[0] = i2; if (i >= i2) { return c(); } this.b = i2 - i; this.d -= i; return this; } /* JADX WARN: Multi-variable type inference failed */ AvlNode a(Comparator comparator, E e, int i, int[] iArr) { int compare = comparator.compare(e, this.a); if (compare < 0) { AvlNode avlNode = this.f; if (avlNode == null) { iArr[0] = 0; a((AvlNode) e, i); return this; } int i2 = avlNode.e; this.f = avlNode.a(comparator, e, i, iArr); if (iArr[0] == 0) { this.c++; } this.d += i; return this.f.e == i2 ? this : d(); } if (compare > 0) { AvlNode avlNode2 = this.g; if (avlNode2 == null) { iArr[0] = 0; b((AvlNode) e, i); return this; } int i3 = avlNode2.e; this.g = avlNode2.a(comparator, e, i, iArr); if (iArr[0] == 0) { this.c++; } this.d += i; return this.g.e == i3 ? this : d(); } int i4 = this.b; iArr[0] = i4; long j = i; Preconditions.a(((long) i4) + j <= 2147483647L); this.b += i; this.d += j; return this; } private AvlNode c() { int i = this.b; this.b = 0; TreeMultiset.successor(this.h, this.i); AvlNode avlNode = this.f; if (avlNode == null) { return this.g; } AvlNode avlNode2 = this.g; if (avlNode2 == null) { return avlNode; } if (avlNode.e >= avlNode2.e) { AvlNode avlNode3 = this.h; avlNode3.f = avlNode.j(avlNode3); avlNode3.g = this.g; avlNode3.c = this.c - 1; avlNode3.d = this.d - i; return avlNode3.d(); } AvlNode avlNode4 = this.i; avlNode4.g = avlNode2.k(avlNode4); avlNode4.f = this.f; avlNode4.c = this.c - 1; avlNode4.d = this.d - i; return avlNode4.d(); } private int b() { return i(this.f) - i(this.g); } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Multi-variable type inference failed */ public AvlNode b(Comparator comparator, E e) { int compare = comparator.compare(e, this.a); if (compare < 0) { AvlNode avlNode = this.f; return avlNode == null ? this : (AvlNode) MoreObjects.a(avlNode.b((Comparator>) comparator, (Comparator) e), this); } if (compare == 0) { return this; } AvlNode avlNode2 = this.g; if (avlNode2 == null) { return null; } return avlNode2.b((Comparator>) comparator, (Comparator) e); } /* JADX WARN: Multi-variable type inference failed */ AvlNode a(Comparator comparator, E e, int i, int i2, int[] iArr) { int compare = comparator.compare(e, this.a); if (compare < 0) { AvlNode avlNode = this.f; if (avlNode == null) { iArr[0] = 0; if (i == 0 && i2 > 0) { a((AvlNode) e, i2); } return this; } this.f = avlNode.a(comparator, e, i, i2, iArr); if (iArr[0] == i) { if (i2 == 0 && iArr[0] != 0) { this.c--; } else if (i2 > 0 && iArr[0] == 0) { this.c++; } this.d += i2 - iArr[0]; } return d(); } if (compare > 0) { AvlNode avlNode2 = this.g; if (avlNode2 == null) { iArr[0] = 0; if (i == 0 && i2 > 0) { b((AvlNode) e, i2); } return this; } this.g = avlNode2.a(comparator, e, i, i2, iArr); if (iArr[0] == i) { if (i2 == 0 && iArr[0] != 0) { this.c--; } else if (i2 > 0 && iArr[0] == 0) { this.c++; } this.d += i2 - iArr[0]; } return d(); } int i3 = this.b; iArr[0] = i3; if (i == i3) { if (i2 == 0) { return c(); } this.d += i2 - i3; this.b = i2; } return this; } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Multi-variable type inference failed */ public AvlNode c(Comparator comparator, E e) { int compare = comparator.compare(e, this.a); if (compare > 0) { AvlNode avlNode = this.g; return avlNode == null ? this : (AvlNode) MoreObjects.a(avlNode.c(comparator, e), this); } if (compare == 0) { return this; } AvlNode avlNode2 = this.f; if (avlNode2 == null) { return null; } return avlNode2.c(comparator, e); } @Override // com.google.common.collect.Multiset.Entry public E a() { return this.a; } } private static final class Reference { private T a; private Reference() { } public T a() { return this.a; } public void a(T t, T t2) { if (this.a != t) { throw new ConcurrentModificationException(); } this.a = t2; } } TreeMultiset(Reference> reference, GeneralRange generalRange, AvlNode avlNode) { super(generalRange.a()); this.rootReference = reference; this.range = generalRange; this.header = avlNode; } private long aggregateAboveRange(Aggregate aggregate, AvlNode avlNode) { long b; long aggregateAboveRange; if (avlNode == null) { return 0L; } int compare = comparator().compare(this.range.e(), ((AvlNode) avlNode).a); if (compare > 0) { return aggregateAboveRange(aggregate, ((AvlNode) avlNode).g); } if (compare == 0) { int i = AnonymousClass4.a[this.range.d().ordinal()]; if (i != 1) { if (i == 2) { return aggregate.b(((AvlNode) avlNode).g); } throw new AssertionError(); } b = aggregate.a(avlNode); aggregateAboveRange = aggregate.b(((AvlNode) avlNode).g); } else { b = aggregate.b(((AvlNode) avlNode).g) + aggregate.a(avlNode); aggregateAboveRange = aggregateAboveRange(aggregate, ((AvlNode) avlNode).f); } return b + aggregateAboveRange; } private long aggregateBelowRange(Aggregate aggregate, AvlNode avlNode) { long b; long aggregateBelowRange; if (avlNode == null) { return 0L; } int compare = comparator().compare(this.range.c(), ((AvlNode) avlNode).a); if (compare < 0) { return aggregateBelowRange(aggregate, ((AvlNode) avlNode).f); } if (compare == 0) { int i = AnonymousClass4.a[this.range.b().ordinal()]; if (i != 1) { if (i == 2) { return aggregate.b(((AvlNode) avlNode).f); } throw new AssertionError(); } b = aggregate.a(avlNode); aggregateBelowRange = aggregate.b(((AvlNode) avlNode).f); } else { b = aggregate.b(((AvlNode) avlNode).f) + aggregate.a(avlNode); aggregateBelowRange = aggregateBelowRange(aggregate, ((AvlNode) avlNode).g); } return b + aggregateBelowRange; } private long aggregateForEntries(Aggregate aggregate) { AvlNode a = this.rootReference.a(); long b = aggregate.b(a); if (this.range.f()) { b -= aggregateBelowRange(aggregate, a); } return this.range.g() ? b - aggregateAboveRange(aggregate, a) : b; } public static TreeMultiset create() { return new TreeMultiset<>(Ordering.c()); } /* JADX INFO: Access modifiers changed from: private */ public AvlNode firstNode() { AvlNode avlNode; if (this.rootReference.a() == null) { return null; } if (this.range.f()) { E c = this.range.c(); AvlNode b = this.rootReference.a().b((Comparator) comparator(), (Comparator) c); if (b == null) { return null; } if (this.range.b() == BoundType.OPEN && comparator().compare(c, b.a()) == 0) { b = ((AvlNode) b).i; } avlNode = b; } else { avlNode = ((AvlNode) this.header).i; } if (avlNode == this.header || !this.range.a((GeneralRange) avlNode.a())) { return null; } return avlNode; } /* JADX INFO: Access modifiers changed from: private */ public AvlNode lastNode() { AvlNode avlNode; if (this.rootReference.a() == null) { return null; } if (this.range.g()) { E e = this.range.e(); AvlNode c = this.rootReference.a().c(comparator(), e); if (c == null) { return null; } if (this.range.d() == BoundType.OPEN && comparator().compare(e, c.a()) == 0) { c = ((AvlNode) c).h; } avlNode = c; } else { avlNode = ((AvlNode) this.header).h; } if (avlNode == this.header || !this.range.a((GeneralRange) avlNode.a())) { return null; } return avlNode; } private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); Comparator comparator = (Comparator) objectInputStream.readObject(); Serialization.a(AbstractSortedMultiset.class, "comparator").a((Serialization.FieldSetter) this, (Object) comparator); Serialization.a(TreeMultiset.class, "range").a((Serialization.FieldSetter) this, (Object) GeneralRange.a(comparator)); Serialization.a(TreeMultiset.class, "rootReference").a((Serialization.FieldSetter) this, (Object) new Reference()); AvlNode avlNode = new AvlNode(null, 1); Serialization.a(TreeMultiset.class, "header").a((Serialization.FieldSetter) this, (Object) avlNode); successor(avlNode, avlNode); Serialization.a(this, objectInputStream); } /* JADX INFO: Access modifiers changed from: private */ public static void successor(AvlNode avlNode, AvlNode avlNode2) { ((AvlNode) avlNode).i = avlNode2; ((AvlNode) avlNode2).h = avlNode; } /* JADX INFO: Access modifiers changed from: private */ public Multiset.Entry wrapEntry(final AvlNode avlNode) { return new Multisets.AbstractEntry() { // from class: com.google.common.collect.TreeMultiset.1 @Override // com.google.common.collect.Multiset.Entry public E a() { return (E) avlNode.a(); } @Override // com.google.common.collect.Multiset.Entry public int getCount() { int count = avlNode.getCount(); return count == 0 ? TreeMultiset.this.count(a()) : count; } }; } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); objectOutputStream.writeObject(elementSet().comparator()); Serialization.a(this, objectOutputStream); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ boolean add(Object obj) { return super.add(obj); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public /* bridge */ /* synthetic */ boolean addAll(Collection collection) { return super.addAll(collection); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public /* bridge */ /* synthetic */ void clear() { super.clear(); } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset, com.google.common.collect.SortedIterable public /* bridge */ /* synthetic */ Comparator comparator() { return super.comparator(); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ boolean contains(Object obj) { return super.contains(obj); } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public int count(Object obj) { try { AvlNode a = this.rootReference.a(); if (this.range.a((GeneralRange) obj) && a != null) { return a.a((Comparator>) comparator(), (Comparator) obj); } } catch (ClassCastException | NullPointerException unused) { } return 0; } @Override // com.google.common.collect.AbstractSortedMultiset Iterator> descendingEntryIterator() { return new Iterator>() { // from class: com.google.common.collect.TreeMultiset.3 AvlNode a; Multiset.Entry b = null; { this.a = TreeMultiset.this.lastNode(); } @Override // java.util.Iterator public boolean hasNext() { if (this.a == null) { return false; } if (!TreeMultiset.this.range.c(this.a.a())) { return true; } this.a = null; return false; } @Override // java.util.Iterator public void remove() { CollectPreconditions.a(this.b != null); TreeMultiset.this.setCount(this.b.a(), 0); this.b = null; } @Override // java.util.Iterator public Multiset.Entry next() { if (!hasNext()) { throw new NoSuchElementException(); } Multiset.Entry wrapEntry = TreeMultiset.this.wrapEntry(this.a); this.b = wrapEntry; if (((AvlNode) this.a).h == TreeMultiset.this.header) { this.a = null; } else { this.a = ((AvlNode) this.a).h; } return wrapEntry; } }; } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ SortedMultiset descendingMultiset() { return super.descendingMultiset(); } @Override // com.google.common.collect.AbstractMultiset int distinctElements() { return Ints.b(aggregateForEntries(Aggregate.DISTINCT)); } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ NavigableSet elementSet() { return super.elementSet(); } @Override // com.google.common.collect.AbstractMultiset Iterator> entryIterator() { return new Iterator>() { // from class: com.google.common.collect.TreeMultiset.2 AvlNode a; Multiset.Entry b; { this.a = TreeMultiset.this.firstNode(); } @Override // java.util.Iterator public boolean hasNext() { if (this.a == null) { return false; } if (!TreeMultiset.this.range.b(this.a.a())) { return true; } this.a = null; return false; } @Override // java.util.Iterator public void remove() { CollectPreconditions.a(this.b != null); TreeMultiset.this.setCount(this.b.a(), 0); this.b = null; } @Override // java.util.Iterator public Multiset.Entry next() { if (!hasNext()) { throw new NoSuchElementException(); } Multiset.Entry wrapEntry = TreeMultiset.this.wrapEntry(this.a); this.b = wrapEntry; if (((AvlNode) this.a).i == TreeMultiset.this.header) { this.a = null; } else { this.a = ((AvlNode) this.a).i; } return wrapEntry; } }; } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ Set entrySet() { return super.entrySet(); } @Override // com.google.common.collect.AbstractMultiset, java.util.Collection, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ boolean equals(Object obj) { return super.equals(obj); } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ Multiset.Entry firstEntry() { return super.firstEntry(); } @Override // com.google.common.collect.AbstractMultiset, java.util.Collection, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ int hashCode() { return super.hashCode(); } @Override // com.google.common.collect.SortedMultiset public SortedMultiset headMultiset(E e, BoundType boundType) { return new TreeMultiset(this.rootReference, this.range.a(GeneralRange.b(comparator(), e, boundType)), this.header); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public /* bridge */ /* synthetic */ boolean isEmpty() { return super.isEmpty(); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable public /* bridge */ /* synthetic */ Iterator iterator() { return super.iterator(); } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ Multiset.Entry lastEntry() { return super.lastEntry(); } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ Multiset.Entry pollFirstEntry() { return super.pollFirstEntry(); } @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ Multiset.Entry pollLastEntry() { return super.pollLastEntry(); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public /* bridge */ /* synthetic */ boolean remove(Object obj) { return super.remove(obj); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public /* bridge */ /* synthetic */ boolean removeAll(Collection collection) { return super.removeAll(collection); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection public /* bridge */ /* synthetic */ boolean retainAll(Collection collection) { return super.retainAll(collection); } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public int setCount(E e, int i) { CollectPreconditions.a(i, "count"); if (!this.range.a((GeneralRange) e)) { Preconditions.a(i == 0); return 0; } AvlNode a = this.rootReference.a(); if (a == null) { if (i > 0) { add(e, i); } return 0; } int[] iArr = new int[1]; this.rootReference.a(a, a.c(comparator(), e, i, iArr)); return iArr[0]; } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset public int size() { return Ints.b(aggregateForEntries(Aggregate.SIZE)); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.AbstractSortedMultiset, com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ SortedMultiset subMultiset(Object obj, BoundType boundType, Object obj2, BoundType boundType2) { return super.subMultiset(obj, boundType, obj2, boundType2); } @Override // com.google.common.collect.SortedMultiset public SortedMultiset tailMultiset(E e, BoundType boundType) { return new TreeMultiset(this.rootReference, this.range.a(GeneralRange.a(comparator(), e, boundType)), this.header); } @Override // com.google.common.collect.AbstractMultiset, java.util.AbstractCollection public /* bridge */ /* synthetic */ String toString() { return super.toString(); } public static TreeMultiset create(Comparator comparator) { return comparator == null ? new TreeMultiset<>(Ordering.c()) : new TreeMultiset<>(comparator); } static int distinctElements(AvlNode avlNode) { if (avlNode == null) { return 0; } return ((AvlNode) avlNode).c; } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public int add(E e, int i) { CollectPreconditions.a(i, "occurrences"); if (i == 0) { return count(e); } Preconditions.a(this.range.a((GeneralRange) e)); AvlNode a = this.rootReference.a(); if (a != null) { int[] iArr = new int[1]; this.rootReference.a(a, a.a(comparator(), e, i, iArr)); return iArr[0]; } comparator().compare(e, e); AvlNode avlNode = new AvlNode<>(e, i); AvlNode avlNode2 = this.header; successor(avlNode2, avlNode, avlNode2); this.rootReference.a(a, avlNode); return 0; } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public int remove(Object obj, int i) { CollectPreconditions.a(i, "occurrences"); if (i == 0) { return count(obj); } AvlNode a = this.rootReference.a(); int[] iArr = new int[1]; try { if (this.range.a((GeneralRange) obj) && a != null) { this.rootReference.a(a, a.b(comparator(), obj, i, iArr)); return iArr[0]; } } catch (ClassCastException | NullPointerException unused) { } return 0; } /* JADX INFO: Access modifiers changed from: private */ public static void successor(AvlNode avlNode, AvlNode avlNode2, AvlNode avlNode3) { successor(avlNode, avlNode2); successor(avlNode2, avlNode3); } public static TreeMultiset create(Iterable iterable) { TreeMultiset create = create(); Iterables.a((Collection) create, (Iterable) iterable); return create; } TreeMultiset(Comparator comparator) { super(comparator); this.range = GeneralRange.a((Comparator) comparator); this.header = new AvlNode<>(null, 1); AvlNode avlNode = this.header; successor(avlNode, avlNode); this.rootReference = new Reference<>(); } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public boolean setCount(E e, int i, int i2) { CollectPreconditions.a(i2, "newCount"); CollectPreconditions.a(i, "oldCount"); Preconditions.a(this.range.a((GeneralRange) e)); AvlNode a = this.rootReference.a(); if (a != null) { int[] iArr = new int[1]; this.rootReference.a(a, a.a(comparator(), e, i, i2, iArr)); return iArr[0] == i; } if (i != 0) { return false; } if (i2 > 0) { add(e, i2); } return true; } }