Files
rr3-apk/decompiled-community/sources/com/google/common/collect/ImmutableSet.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

264 lines
8.7 KiB
Java

package com.google.common.collect;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableCollection;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
/* loaded from: classes3.dex */
public abstract class ImmutableSet extends ImmutableCollection implements Set {
public transient ImmutableList asList;
public static boolean shouldTrim(int i, int i2) {
return i < (i2 >> 1) + (i2 >> 2);
}
public boolean isHashCodeFast() {
return false;
}
@Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public abstract UnmodifiableIterator iterator();
public static ImmutableSet of() {
return RegularImmutableSet.EMPTY;
}
public static ImmutableSet of(Object obj) {
return new SingletonImmutableSet(obj);
}
public static ImmutableSet of(Object obj, Object obj2, Object obj3) {
return construct(3, obj, obj2, obj3);
}
public static ImmutableSet of(Object obj, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6, Object... objArr) {
Preconditions.checkArgument(objArr.length <= 2147483641, "the total number of elements must fit in an int");
int length = objArr.length + 6;
Object[] objArr2 = new Object[length];
objArr2[0] = obj;
objArr2[1] = obj2;
objArr2[2] = obj3;
objArr2[3] = obj4;
objArr2[4] = obj5;
objArr2[5] = obj6;
System.arraycopy(objArr, 0, objArr2, 6, objArr.length);
return construct(length, objArr2);
}
public static ImmutableSet construct(int i, Object... objArr) {
if (i == 0) {
return of();
}
if (i == 1) {
Object obj = objArr[0];
Objects.requireNonNull(obj);
return of(obj);
}
int chooseTableSize = chooseTableSize(i);
Object[] objArr2 = new Object[chooseTableSize];
int i2 = chooseTableSize - 1;
int i3 = 0;
int i4 = 0;
for (int i5 = 0; i5 < i; i5++) {
Object checkElementNotNull = ObjectArrays.checkElementNotNull(objArr[i5], i5);
int hashCode = checkElementNotNull.hashCode();
int smear = Hashing.smear(hashCode);
while (true) {
int i6 = smear & i2;
Object obj2 = objArr2[i6];
if (obj2 == null) {
objArr[i4] = checkElementNotNull;
objArr2[i6] = checkElementNotNull;
i3 += hashCode;
i4++;
break;
}
if (obj2.equals(checkElementNotNull)) {
break;
}
smear++;
}
}
Arrays.fill(objArr, i4, i, (Object) null);
if (i4 == 1) {
Object obj3 = objArr[0];
Objects.requireNonNull(obj3);
return new SingletonImmutableSet(obj3);
}
if (chooseTableSize(i4) < chooseTableSize / 2) {
return construct(i4, objArr);
}
if (shouldTrim(i4, objArr.length)) {
objArr = Arrays.copyOf(objArr, i4);
}
return new RegularImmutableSet(objArr, i3, objArr2, i2, i4);
}
public static int chooseTableSize(int i) {
int max = Math.max(i, 2);
if (max < 751619276) {
int highestOneBit = Integer.highestOneBit(max - 1) << 1;
while (highestOneBit * 0.7d < max) {
highestOneBit <<= 1;
}
return highestOneBit;
}
Preconditions.checkArgument(max < 1073741824, "collection too large");
return 1073741824;
}
public static ImmutableSet copyOf(Collection collection) {
if ((collection instanceof ImmutableSet) && !(collection instanceof SortedSet)) {
ImmutableSet immutableSet = (ImmutableSet) collection;
if (!immutableSet.isPartialView()) {
return immutableSet;
}
}
Object[] array = collection.toArray();
return construct(array.length, array);
}
public static ImmutableSet copyOf(Object[] objArr) {
int length = objArr.length;
if (length == 0) {
return of();
}
if (length == 1) {
return of(objArr[0]);
}
return construct(objArr.length, (Object[]) objArr.clone());
}
@Override // java.util.Collection, java.util.Set
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if ((obj instanceof ImmutableSet) && isHashCodeFast() && ((ImmutableSet) obj).isHashCodeFast() && hashCode() != obj.hashCode()) {
return false;
}
return Sets.equalsImpl(this, obj);
}
@Override // java.util.Collection, java.util.Set
public int hashCode() {
return Sets.hashCodeImpl(this);
}
@Override // com.google.common.collect.ImmutableCollection
public ImmutableList asList() {
ImmutableList immutableList = this.asList;
if (immutableList != null) {
return immutableList;
}
ImmutableList createAsList = createAsList();
this.asList = createAsList;
return createAsList;
}
public ImmutableList createAsList() {
return ImmutableList.asImmutableList(toArray());
}
public static class SerializedForm implements Serializable {
private static final long serialVersionUID = 0;
public final Object[] elements;
public SerializedForm(Object[] objArr) {
this.elements = objArr;
}
public Object readResolve() {
return ImmutableSet.copyOf(this.elements);
}
}
@Override // com.google.common.collect.ImmutableCollection
public Object writeReplace() {
return new SerializedForm(toArray());
}
public static class Builder extends ImmutableCollection.ArrayBasedBuilder {
public int hashCode;
public Object[] hashTable;
public Builder() {
super(4);
}
@Override // com.google.common.collect.ImmutableCollection.ArrayBasedBuilder
public Builder add(Object obj) {
Preconditions.checkNotNull(obj);
if (this.hashTable != null && ImmutableSet.chooseTableSize(this.size) <= this.hashTable.length) {
addDeduping(obj);
return this;
}
this.hashTable = null;
super.add(obj);
return this;
}
@Override // com.google.common.collect.ImmutableCollection.ArrayBasedBuilder
public Builder add(Object... objArr) {
if (this.hashTable != null) {
for (Object obj : objArr) {
add(obj);
}
} else {
super.add(objArr);
}
return this;
}
public final void addDeduping(Object obj) {
Objects.requireNonNull(this.hashTable);
int length = this.hashTable.length - 1;
int hashCode = obj.hashCode();
int smear = Hashing.smear(hashCode);
while (true) {
int i = smear & length;
Object[] objArr = this.hashTable;
Object obj2 = objArr[i];
if (obj2 == null) {
objArr[i] = obj;
this.hashCode += hashCode;
super.add(obj);
return;
} else if (obj2.equals(obj)) {
return;
} else {
smear = i + 1;
}
}
}
public ImmutableSet build() {
ImmutableSet construct;
int i = this.size;
if (i == 0) {
return ImmutableSet.of();
}
if (i == 1) {
Object obj = this.contents[0];
Objects.requireNonNull(obj);
return ImmutableSet.of(obj);
}
if (this.hashTable == null || ImmutableSet.chooseTableSize(i) != this.hashTable.length) {
construct = ImmutableSet.construct(this.size, this.contents);
this.size = construct.size();
} else {
Object[] copyOf = ImmutableSet.shouldTrim(this.size, this.contents.length) ? Arrays.copyOf(this.contents, this.size) : this.contents;
construct = new RegularImmutableSet(copyOf, this.hashCode, this.hashTable, r5.length - 1, this.size);
}
this.forceCopy = true;
this.hashTable = null;
return construct;
}
}
}