258 lines
6.9 KiB
Java
258 lines
6.9 KiB
Java
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.Multisets;
|
|
import com.google.common.collect.Sets;
|
|
import java.util.ConcurrentModificationException;
|
|
import java.util.Iterator;
|
|
import java.util.NoSuchElementException;
|
|
import java.util.Set;
|
|
|
|
/* loaded from: classes.dex */
|
|
abstract class AbstractObjectCountMap<K> {
|
|
transient Object[] a;
|
|
transient int[] b;
|
|
transient int c;
|
|
transient int d;
|
|
private transient Set<K> e;
|
|
private transient Set<Multiset.Entry<K>> f;
|
|
|
|
abstract class EntrySetView extends Sets.ImprovedAbstractSet<Multiset.Entry<K>> {
|
|
EntrySetView() {
|
|
}
|
|
|
|
@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;
|
|
int b = AbstractObjectCountMap.this.b(entry.a());
|
|
return b != -1 && AbstractObjectCountMap.this.b[b] == entry.getCount();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean remove(Object obj) {
|
|
if (!(obj instanceof Multiset.Entry)) {
|
|
return false;
|
|
}
|
|
Multiset.Entry entry = (Multiset.Entry) obj;
|
|
int b = AbstractObjectCountMap.this.b(entry.a());
|
|
if (b == -1 || AbstractObjectCountMap.this.b[b] != entry.getCount()) {
|
|
return false;
|
|
}
|
|
AbstractObjectCountMap.this.e(b);
|
|
return true;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return AbstractObjectCountMap.this.c;
|
|
}
|
|
}
|
|
|
|
abstract class Itr<T> implements Iterator<T> {
|
|
int a;
|
|
boolean b = false;
|
|
int c = 0;
|
|
|
|
Itr() {
|
|
this.a = AbstractObjectCountMap.this.d;
|
|
}
|
|
|
|
abstract T a(int i);
|
|
|
|
void a() {
|
|
if (AbstractObjectCountMap.this.d != this.a) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
}
|
|
|
|
@Override // java.util.Iterator
|
|
public boolean hasNext() {
|
|
return this.c < AbstractObjectCountMap.this.c;
|
|
}
|
|
|
|
@Override // java.util.Iterator
|
|
public T next() {
|
|
a();
|
|
if (!hasNext()) {
|
|
throw new NoSuchElementException();
|
|
}
|
|
this.b = true;
|
|
int i = this.c;
|
|
this.c = i + 1;
|
|
return a(i);
|
|
}
|
|
|
|
@Override // java.util.Iterator
|
|
public void remove() {
|
|
a();
|
|
CollectPreconditions.a(this.b);
|
|
this.a++;
|
|
this.c--;
|
|
AbstractObjectCountMap.this.e(this.c);
|
|
this.b = false;
|
|
}
|
|
}
|
|
|
|
class KeySetView extends Sets.ImprovedAbstractSet<K> {
|
|
KeySetView() {
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
|
public Iterator<K> iterator() {
|
|
return new AbstractObjectCountMap<K>.Itr<K>() { // from class: com.google.common.collect.AbstractObjectCountMap.KeySetView.1
|
|
{
|
|
AbstractObjectCountMap abstractObjectCountMap = AbstractObjectCountMap.this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.AbstractObjectCountMap.Itr
|
|
K a(int i) {
|
|
return (K) AbstractObjectCountMap.this.a[i];
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return AbstractObjectCountMap.this.c;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public Object[] toArray() {
|
|
AbstractObjectCountMap abstractObjectCountMap = AbstractObjectCountMap.this;
|
|
return ObjectArrays.a(abstractObjectCountMap.a, 0, abstractObjectCountMap.c);
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public <T> T[] toArray(T[] tArr) {
|
|
AbstractObjectCountMap abstractObjectCountMap = AbstractObjectCountMap.this;
|
|
return (T[]) ObjectArrays.a(abstractObjectCountMap.a, 0, abstractObjectCountMap.c, tArr);
|
|
}
|
|
}
|
|
|
|
class MapEntry extends Multisets.AbstractEntry<K> {
|
|
final K a;
|
|
int b;
|
|
|
|
MapEntry(int i) {
|
|
this.a = (K) AbstractObjectCountMap.this.a[i];
|
|
this.b = i;
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset.Entry
|
|
public K a() {
|
|
return this.a;
|
|
}
|
|
|
|
void b() {
|
|
int i = this.b;
|
|
if (i == -1 || i >= AbstractObjectCountMap.this.h() || !Objects.a(this.a, AbstractObjectCountMap.this.a[this.b])) {
|
|
this.b = AbstractObjectCountMap.this.b(this.a);
|
|
}
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset.Entry
|
|
public int getCount() {
|
|
b();
|
|
int i = this.b;
|
|
if (i == -1) {
|
|
return 0;
|
|
}
|
|
return AbstractObjectCountMap.this.b[i];
|
|
}
|
|
|
|
public int a(int i) {
|
|
b();
|
|
int i2 = this.b;
|
|
if (i2 == -1) {
|
|
AbstractObjectCountMap.this.a(this.a, i);
|
|
return 0;
|
|
}
|
|
int[] iArr = AbstractObjectCountMap.this.b;
|
|
int i3 = iArr[i2];
|
|
iArr[i2] = i;
|
|
return i3;
|
|
}
|
|
}
|
|
|
|
AbstractObjectCountMap() {
|
|
}
|
|
|
|
abstract int a(Object obj);
|
|
|
|
abstract int a(K k, int i);
|
|
|
|
Multiset.Entry<K> a(int i) {
|
|
Preconditions.a(i, this.c);
|
|
return new MapEntry(i);
|
|
}
|
|
|
|
abstract void a();
|
|
|
|
abstract int b(Object obj);
|
|
|
|
K b(int i) {
|
|
Preconditions.a(i, this.c);
|
|
return (K) this.a[i];
|
|
}
|
|
|
|
abstract Set<Multiset.Entry<K>> b();
|
|
|
|
abstract int c(Object obj);
|
|
|
|
Set<K> c() {
|
|
return new KeySetView();
|
|
}
|
|
|
|
int d(int i) {
|
|
int i2 = i + 1;
|
|
if (i2 < this.c) {
|
|
return i2;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int e() {
|
|
return 0;
|
|
}
|
|
|
|
abstract int e(int i);
|
|
|
|
boolean f() {
|
|
return this.c == 0;
|
|
}
|
|
|
|
Set<K> g() {
|
|
Set<K> set = this.e;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<K> c = c();
|
|
this.e = c;
|
|
return c;
|
|
}
|
|
|
|
int h() {
|
|
return this.c;
|
|
}
|
|
|
|
int c(int i) {
|
|
Preconditions.a(i, this.c);
|
|
return this.b[i];
|
|
}
|
|
|
|
Set<Multiset.Entry<K>> d() {
|
|
Set<Multiset.Entry<K>> set = this.f;
|
|
if (set != null) {
|
|
return set;
|
|
}
|
|
Set<Multiset.Entry<K>> b = b();
|
|
this.f = b;
|
|
return b;
|
|
}
|
|
}
|