361 lines
12 KiB
Java
361 lines
12 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.collect.ImmutableCollection;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.google.common.collect.Multiset;
|
|
import java.io.Serializable;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializationDependencies<E> implements Multiset<E> {
|
|
private transient ImmutableList<E> asList;
|
|
private transient ImmutableSet<Multiset.Entry<E>> entrySet;
|
|
|
|
public static class Builder<E> extends ImmutableCollection.Builder<E> {
|
|
AbstractObjectCountMap<E> a;
|
|
boolean b;
|
|
boolean c;
|
|
|
|
public Builder() {
|
|
this(4);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public /* bridge */ /* synthetic */ ImmutableCollection.Builder a(Object obj) {
|
|
return a((Builder<E>) obj);
|
|
}
|
|
|
|
Builder(int i) {
|
|
this.b = false;
|
|
this.c = false;
|
|
this.a = ObjectCountHashMap.h(i);
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public Builder<E> a(E e) {
|
|
return a((Builder<E>) e, 1);
|
|
}
|
|
|
|
public Builder<E> a(E e, int i) {
|
|
if (i == 0) {
|
|
return this;
|
|
}
|
|
if (this.b) {
|
|
this.a = new ObjectCountHashMap(this.a);
|
|
this.c = false;
|
|
}
|
|
this.b = false;
|
|
Preconditions.a(e);
|
|
AbstractObjectCountMap<E> abstractObjectCountMap = this.a;
|
|
abstractObjectCountMap.a(e, i + abstractObjectCountMap.a(e));
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public Builder<E> a(E... eArr) {
|
|
super.a((Object[]) eArr);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public Builder<E> a(Iterable<? extends E> iterable) {
|
|
if (iterable instanceof Multiset) {
|
|
for (Multiset.Entry<E> entry : Multisets.a(iterable).entrySet()) {
|
|
a((Builder<E>) entry.a(), entry.getCount());
|
|
}
|
|
} else {
|
|
super.a((Iterable) iterable);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection.Builder
|
|
public Builder<E> a(Iterator<? extends E> it) {
|
|
super.a((Iterator) it);
|
|
return this;
|
|
}
|
|
|
|
public ImmutableMultiset<E> a() {
|
|
if (this.a.f()) {
|
|
return ImmutableMultiset.of();
|
|
}
|
|
if (this.c) {
|
|
this.a = new ObjectCountHashMap(this.a);
|
|
this.c = false;
|
|
}
|
|
this.b = true;
|
|
return new RegularImmutableMultiset((ObjectCountHashMap) this.a);
|
|
}
|
|
}
|
|
|
|
private final class EntrySet extends ImmutableSet.Indexed<Multiset.Entry<E>> {
|
|
private EntrySet() {
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, 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 && ImmutableMultiset.this.count(entry.a()) == entry.getCount();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableSet, java.util.Collection, java.util.Set
|
|
public int hashCode() {
|
|
return ImmutableMultiset.this.hashCode();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
boolean isPartialView() {
|
|
return ImmutableMultiset.this.isPartialView();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return ImmutableMultiset.this.elementSet().size();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection
|
|
Object writeReplace() {
|
|
return new EntrySetSerializedForm(ImmutableMultiset.this);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.collect.ImmutableSet.Indexed
|
|
public Multiset.Entry<E> get(int i) {
|
|
return ImmutableMultiset.this.getEntry(i);
|
|
}
|
|
}
|
|
|
|
static class EntrySetSerializedForm<E> implements Serializable {
|
|
final ImmutableMultiset<E> a;
|
|
|
|
EntrySetSerializedForm(ImmutableMultiset<E> immutableMultiset) {
|
|
this.a = immutableMultiset;
|
|
}
|
|
|
|
Object readResolve() {
|
|
return this.a.entrySet();
|
|
}
|
|
}
|
|
|
|
private static class SerializedForm implements Serializable {
|
|
final Object[] a;
|
|
final int[] b;
|
|
|
|
SerializedForm(Multiset<?> multiset) {
|
|
int size = multiset.entrySet().size();
|
|
this.a = new Object[size];
|
|
this.b = new int[size];
|
|
int i = 0;
|
|
for (Multiset.Entry<?> entry : multiset.entrySet()) {
|
|
this.a[i] = entry.a();
|
|
this.b[i] = entry.getCount();
|
|
i++;
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
Object readResolve() {
|
|
Builder builder = new Builder(this.a.length);
|
|
int i = 0;
|
|
while (true) {
|
|
Object[] objArr = this.a;
|
|
if (i >= objArr.length) {
|
|
return builder.a();
|
|
}
|
|
builder.a((Builder) objArr[i], this.b[i]);
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
ImmutableMultiset() {
|
|
}
|
|
|
|
public static <E> Builder<E> builder() {
|
|
return new Builder<>();
|
|
}
|
|
|
|
private static <E> ImmutableMultiset<E> copyFromElements(E... eArr) {
|
|
return new Builder().a((Object[]) eArr).a();
|
|
}
|
|
|
|
static <E> ImmutableMultiset<E> copyFromEntries(Collection<? extends Multiset.Entry<? extends E>> collection) {
|
|
Builder builder = new Builder(collection.size());
|
|
for (Multiset.Entry<? extends E> entry : collection) {
|
|
builder.a((Builder) entry.a(), entry.getCount());
|
|
}
|
|
return builder.a();
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> copyOf(E[] eArr) {
|
|
return copyFromElements(eArr);
|
|
}
|
|
|
|
private final ImmutableSet<Multiset.Entry<E>> createEntrySet() {
|
|
return isEmpty() ? ImmutableSet.of() : new EntrySet();
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of() {
|
|
return RegularImmutableMultiset.d;
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
@Deprecated
|
|
public final int add(E e, int i) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
public ImmutableList<E> asList() {
|
|
ImmutableList<E> immutableList = this.asList;
|
|
if (immutableList != null) {
|
|
return immutableList;
|
|
}
|
|
ImmutableList<E> asList = super.asList();
|
|
this.asList = asList;
|
|
return asList;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public boolean contains(Object obj) {
|
|
return count(obj) > 0;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
int copyIntoArray(Object[] objArr, int i) {
|
|
UnmodifiableIterator<Multiset.Entry<E>> it = entrySet().iterator();
|
|
while (it.hasNext()) {
|
|
Multiset.Entry<E> next = it.next();
|
|
Arrays.fill(objArr, i, next.getCount() + i, next.a());
|
|
i += next.getCount();
|
|
}
|
|
return i;
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
public abstract ImmutableSet<E> elementSet();
|
|
|
|
@Override // java.util.Collection, com.google.common.collect.Multiset
|
|
public boolean equals(Object obj) {
|
|
return Multisets.a(this, obj);
|
|
}
|
|
|
|
abstract Multiset.Entry<E> getEntry(int i);
|
|
|
|
@Override // java.util.Collection, com.google.common.collect.Multiset
|
|
public int hashCode() {
|
|
return Sets.a(entrySet());
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
@Deprecated
|
|
public final int remove(Object obj, int i) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
@Deprecated
|
|
public final int setCount(E e, int i) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection
|
|
public String toString() {
|
|
return entrySet().toString();
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection
|
|
Object writeReplace() {
|
|
return new SerializedForm(this);
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> copyOf(Iterable<? extends E> iterable) {
|
|
if (iterable instanceof ImmutableMultiset) {
|
|
ImmutableMultiset<E> immutableMultiset = (ImmutableMultiset) iterable;
|
|
if (!immutableMultiset.isPartialView()) {
|
|
return immutableMultiset;
|
|
}
|
|
}
|
|
Builder builder = new Builder(Multisets.b(iterable));
|
|
builder.a((Iterable) iterable);
|
|
return builder.a();
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of(E e) {
|
|
return copyFromElements(e);
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
public ImmutableSet<Multiset.Entry<E>> entrySet() {
|
|
ImmutableSet<Multiset.Entry<E>> immutableSet = this.entrySet;
|
|
if (immutableSet != null) {
|
|
return immutableSet;
|
|
}
|
|
ImmutableSet<Multiset.Entry<E>> createEntrySet = createEntrySet();
|
|
this.entrySet = createEntrySet;
|
|
return createEntrySet;
|
|
}
|
|
|
|
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet
|
|
public UnmodifiableIterator<E> iterator() {
|
|
final UnmodifiableIterator<Multiset.Entry<E>> it = entrySet().iterator();
|
|
return new UnmodifiableIterator<E>(this) { // from class: com.google.common.collect.ImmutableMultiset.1
|
|
int a;
|
|
E b;
|
|
|
|
@Override // java.util.Iterator
|
|
public boolean hasNext() {
|
|
return this.a > 0 || it.hasNext();
|
|
}
|
|
|
|
@Override // java.util.Iterator
|
|
public E next() {
|
|
if (this.a <= 0) {
|
|
Multiset.Entry entry = (Multiset.Entry) it.next();
|
|
this.b = (E) entry.a();
|
|
this.a = entry.getCount();
|
|
}
|
|
this.a--;
|
|
return this.b;
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.google.common.collect.Multiset
|
|
@Deprecated
|
|
public final boolean setCount(E e, int i, int i2) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of(E e, E e2) {
|
|
return copyFromElements(e, e2);
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of(E e, E e2, E e3) {
|
|
return copyFromElements(e, e2, e3);
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of(E e, E e2, E e3, E e4) {
|
|
return copyFromElements(e, e2, e3, e4);
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of(E e, E e2, E e3, E e4, E e5) {
|
|
return copyFromElements(e, e2, e3, e4, e5);
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> of(E e, E e2, E e3, E e4, E e5, E e6, E... eArr) {
|
|
return new Builder().a((Builder) e).a((Builder<E>) e2).a((Builder<E>) e3).a((Builder<E>) e4).a((Builder<E>) e5).a((Builder<E>) e6).a((Object[]) eArr).a();
|
|
}
|
|
|
|
public static <E> ImmutableMultiset<E> copyOf(Iterator<? extends E> it) {
|
|
return new Builder().a((Iterator) it).a();
|
|
}
|
|
}
|