Rabbit-R1/switch port/java/sources/com/google/common/collect/RegularImmutableMultiset.java
2024-05-21 17:08:36 -04:00

130 lines
4.6 KiB
Java

package com.google.common.collect;
import com.google.common.collect.ImmutableMultiset;
import com.google.common.collect.Multiset;
import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.concurrent.LazyInit;
import java.io.Serializable;
import javax.annotation.CheckForNull;
/* JADX INFO: Access modifiers changed from: package-private */
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
public class RegularImmutableMultiset<E> extends ImmutableMultiset<E> {
static final RegularImmutableMultiset<Object> EMPTY = new RegularImmutableMultiset<>(ObjectCountHashMap.create());
final transient ObjectCountHashMap<E> contents;
@CheckForNull
@LazyInit
private transient ImmutableSet<E> elementSet;
private final transient int size;
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableCollection
public boolean isPartialView() {
return false;
}
@Override // java.util.AbstractCollection, java.util.Collection, com.google.common.collect.Multiset
public int size() {
return this.size;
}
/* JADX INFO: Access modifiers changed from: package-private */
public RegularImmutableMultiset(ObjectCountHashMap<E> objectCountHashMap) {
this.contents = objectCountHashMap;
long j = 0;
for (int i = 0; i < objectCountHashMap.size(); i++) {
j += objectCountHashMap.getValue(i);
}
this.size = Ints.saturatedCast(j);
}
@Override // com.google.common.collect.Multiset
public int count(@CheckForNull Object obj) {
return this.contents.get(obj);
}
@Override // com.google.common.collect.ImmutableMultiset, com.google.common.collect.Multiset
public ImmutableSet<E> elementSet() {
ImmutableSet<E> immutableSet = this.elementSet;
if (immutableSet != null) {
return immutableSet;
}
ElementSet elementSet = new ElementSet();
this.elementSet = elementSet;
return elementSet;
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes3.dex */
public final class ElementSet extends IndexedImmutableSet<E> {
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.ImmutableCollection
public boolean isPartialView() {
return true;
}
private ElementSet() {
}
@Override // com.google.common.collect.IndexedImmutableSet
E get(int i) {
return RegularImmutableMultiset.this.contents.getKey(i);
}
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(@CheckForNull Object obj) {
return RegularImmutableMultiset.this.contains(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return RegularImmutableMultiset.this.contents.size();
}
}
@Override // com.google.common.collect.ImmutableMultiset
Multiset.Entry<E> getEntry(int i) {
return this.contents.getEntry(i);
}
/* loaded from: classes3.dex */
private static class SerializedForm implements Serializable {
private static final long serialVersionUID = 0;
final int[] counts;
final Object[] elements;
SerializedForm(Multiset<? extends Object> multiset) {
int size = multiset.entrySet().size();
this.elements = new Object[size];
this.counts = new int[size];
int i = 0;
for (Multiset.Entry<? extends Object> entry : multiset.entrySet()) {
this.elements[i] = entry.getElement();
this.counts[i] = entry.getCount();
i++;
}
}
/* JADX WARN: Multi-variable type inference failed */
Object readResolve() {
ImmutableMultiset.Builder builder = new ImmutableMultiset.Builder(this.elements.length);
int i = 0;
while (true) {
Object[] objArr = this.elements;
if (i < objArr.length) {
builder.addCopies(objArr[i], this.counts[i]);
i++;
} else {
return builder.build();
}
}
}
}
@Override // com.google.common.collect.ImmutableMultiset, com.google.common.collect.ImmutableCollection
Object writeReplace() {
return new SerializedForm(this);
}
}