1030 lines
36 KiB
Java
1030 lines
36 KiB
Java
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<E> extends AbstractSortedMultiset<E> implements Serializable {
|
|
private static final long serialVersionUID = 1;
|
|
private final transient AvlNode<E> header;
|
|
private final transient GeneralRange<E> range;
|
|
private final transient Reference<AvlNode<E>> 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<E> extends Multisets.AbstractEntry<E> {
|
|
private final E a;
|
|
private int b;
|
|
private int c;
|
|
private long d;
|
|
private int e;
|
|
private AvlNode<E> f;
|
|
private AvlNode<E> g;
|
|
private AvlNode<E> h;
|
|
private AvlNode<E> 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<E> i() {
|
|
Preconditions.b(this.f != null);
|
|
AvlNode<E> 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<E> j(AvlNode<E> avlNode) {
|
|
AvlNode<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
return this.f;
|
|
}
|
|
this.g = avlNode2.j(avlNode);
|
|
this.c--;
|
|
this.d -= avlNode.b;
|
|
return d();
|
|
}
|
|
|
|
private AvlNode<E> k(AvlNode<E> avlNode) {
|
|
AvlNode<E> 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<E> 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<E> h() {
|
|
Preconditions.b(this.g != null);
|
|
AvlNode<E> 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<E> c(Comparator<? super E> comparator, E e, int i, int[] iArr) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare < 0) {
|
|
AvlNode<E> avlNode = this.f;
|
|
if (avlNode == null) {
|
|
iArr[0] = 0;
|
|
if (i > 0) {
|
|
a((AvlNode<E>) 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<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
iArr[0] = 0;
|
|
if (i > 0) {
|
|
b((AvlNode<E>) 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<E> 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<? super E> comparator, E e) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare < 0) {
|
|
AvlNode<E> avlNode = this.f;
|
|
if (avlNode == null) {
|
|
return 0;
|
|
}
|
|
return avlNode.a((Comparator<? super Comparator<? super E>>) comparator, (Comparator<? super E>) e);
|
|
}
|
|
if (compare > 0) {
|
|
AvlNode<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
return 0;
|
|
}
|
|
return avlNode2.a((Comparator<? super Comparator<? super E>>) comparator, (Comparator<? super E>) e);
|
|
}
|
|
return this.b;
|
|
}
|
|
|
|
private AvlNode<E> 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<E> b(Comparator<? super E> comparator, E e, int i, int[] iArr) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare < 0) {
|
|
AvlNode<E> 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<E> 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<E> a(Comparator<? super E> comparator, E e, int i, int[] iArr) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare < 0) {
|
|
AvlNode<E> avlNode = this.f;
|
|
if (avlNode == null) {
|
|
iArr[0] = 0;
|
|
a((AvlNode<E>) 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<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
iArr[0] = 0;
|
|
b((AvlNode<E>) 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<E> c() {
|
|
int i = this.b;
|
|
this.b = 0;
|
|
TreeMultiset.successor(this.h, this.i);
|
|
AvlNode<E> avlNode = this.f;
|
|
if (avlNode == null) {
|
|
return this.g;
|
|
}
|
|
AvlNode<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
return avlNode;
|
|
}
|
|
if (avlNode.e >= avlNode2.e) {
|
|
AvlNode<E> 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<E> 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<E> b(Comparator<? super E> comparator, E e) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare < 0) {
|
|
AvlNode<E> avlNode = this.f;
|
|
return avlNode == null ? this : (AvlNode) MoreObjects.a(avlNode.b((Comparator<? super Comparator<? super E>>) comparator, (Comparator<? super E>) e), this);
|
|
}
|
|
if (compare == 0) {
|
|
return this;
|
|
}
|
|
AvlNode<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
return null;
|
|
}
|
|
return avlNode2.b((Comparator<? super Comparator<? super E>>) comparator, (Comparator<? super E>) e);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
AvlNode<E> a(Comparator<? super E> comparator, E e, int i, int i2, int[] iArr) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare < 0) {
|
|
AvlNode<E> avlNode = this.f;
|
|
if (avlNode == null) {
|
|
iArr[0] = 0;
|
|
if (i == 0 && i2 > 0) {
|
|
a((AvlNode<E>) 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<E> avlNode2 = this.g;
|
|
if (avlNode2 == null) {
|
|
iArr[0] = 0;
|
|
if (i == 0 && i2 > 0) {
|
|
b((AvlNode<E>) 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<E> c(Comparator<? super E> comparator, E e) {
|
|
int compare = comparator.compare(e, this.a);
|
|
if (compare > 0) {
|
|
AvlNode<E> avlNode = this.g;
|
|
return avlNode == null ? this : (AvlNode) MoreObjects.a(avlNode.c(comparator, e), this);
|
|
}
|
|
if (compare == 0) {
|
|
return this;
|
|
}
|
|
AvlNode<E> 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<T> {
|
|
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<AvlNode<E>> reference, GeneralRange<E> generalRange, AvlNode<E> avlNode) {
|
|
super(generalRange.a());
|
|
this.rootReference = reference;
|
|
this.range = generalRange;
|
|
this.header = avlNode;
|
|
}
|
|
|
|
private long aggregateAboveRange(Aggregate aggregate, AvlNode<E> 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<E> 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<E> 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 <E extends Comparable> TreeMultiset<E> create() {
|
|
return new TreeMultiset<>(Ordering.c());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public AvlNode<E> firstNode() {
|
|
AvlNode<E> avlNode;
|
|
if (this.rootReference.a() == null) {
|
|
return null;
|
|
}
|
|
if (this.range.f()) {
|
|
E c = this.range.c();
|
|
AvlNode<E> b = this.rootReference.a().b((Comparator<? super 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<E>) avlNode.a())) {
|
|
return null;
|
|
}
|
|
return avlNode;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public AvlNode<E> lastNode() {
|
|
AvlNode<E> avlNode;
|
|
if (this.rootReference.a() == null) {
|
|
return null;
|
|
}
|
|
if (this.range.g()) {
|
|
E e = this.range.e();
|
|
AvlNode<E> 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<E>) 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 <T> void successor(AvlNode<T> avlNode, AvlNode<T> avlNode2) {
|
|
((AvlNode) avlNode).i = avlNode2;
|
|
((AvlNode) avlNode2).h = avlNode;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public Multiset.Entry<E> wrapEntry(final AvlNode<E> avlNode) {
|
|
return new Multisets.AbstractEntry<E>() { // 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<E> a = this.rootReference.a();
|
|
if (this.range.a((GeneralRange<E>) obj) && a != null) {
|
|
return a.a((Comparator<? super Comparator<? super E>>) comparator(), (Comparator<? super E>) obj);
|
|
}
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractSortedMultiset
|
|
Iterator<Multiset.Entry<E>> descendingEntryIterator() {
|
|
return new Iterator<Multiset.Entry<E>>() { // from class: com.google.common.collect.TreeMultiset.3
|
|
AvlNode<E> a;
|
|
Multiset.Entry<E> 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<E> next() {
|
|
if (!hasNext()) {
|
|
throw new NoSuchElementException();
|
|
}
|
|
Multiset.Entry<E> 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<Multiset.Entry<E>> entryIterator() {
|
|
return new Iterator<Multiset.Entry<E>>() { // from class: com.google.common.collect.TreeMultiset.2
|
|
AvlNode<E> a;
|
|
Multiset.Entry<E> 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<E> next() {
|
|
if (!hasNext()) {
|
|
throw new NoSuchElementException();
|
|
}
|
|
Multiset.Entry<E> 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<E> 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>) e)) {
|
|
Preconditions.a(i == 0);
|
|
return 0;
|
|
}
|
|
AvlNode<E> 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<E> 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 <E> TreeMultiset<E> create(Comparator<? super E> 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>) e));
|
|
AvlNode<E> 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<E> avlNode = new AvlNode<>(e, i);
|
|
AvlNode<E> 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<E> a = this.rootReference.a();
|
|
int[] iArr = new int[1];
|
|
try {
|
|
if (this.range.a((GeneralRange<E>) 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 <T> void successor(AvlNode<T> avlNode, AvlNode<T> avlNode2, AvlNode<T> avlNode3) {
|
|
successor(avlNode, avlNode2);
|
|
successor(avlNode2, avlNode3);
|
|
}
|
|
|
|
public static <E extends Comparable> TreeMultiset<E> create(Iterable<? extends E> iterable) {
|
|
TreeMultiset<E> create = create();
|
|
Iterables.a((Collection) create, (Iterable) iterable);
|
|
return create;
|
|
}
|
|
|
|
TreeMultiset(Comparator<? super E> comparator) {
|
|
super(comparator);
|
|
this.range = GeneralRange.a((Comparator) comparator);
|
|
this.header = new AvlNode<>(null, 1);
|
|
AvlNode<E> 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>) e));
|
|
AvlNode<E> 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;
|
|
}
|
|
}
|