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.Iterator; import java.util.Set; import java.util.SortedSet; /* loaded from: classes.dex */ public abstract class ImmutableSet extends ImmutableCollection implements Set { private static final int CUTOFF = 751619276; private static final double DESIRED_LOAD_FACTOR = 0.7d; static final int MAX_TABLE_SIZE = 1073741824; private transient ImmutableList asList; public static class Builder extends ImmutableCollection.ArrayBasedBuilder { 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) obj); } Builder(int i) { super(i); } @Override // com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public Builder a(E e) { super.a((Builder) e); return this; } @Override // com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public Builder a(E... eArr) { super.a((Object[]) eArr); return this; } @Override // com.google.common.collect.ImmutableCollection.Builder public Builder a(Iterator it) { super.a((Iterator) it); return this; } public ImmutableSet a() { ImmutableSet construct = ImmutableSet.construct(this.b, this.a); this.b = construct.size(); this.c = true; return construct; } } static abstract class Indexed extends ImmutableSet { Indexed() { } @Override // com.google.common.collect.ImmutableSet ImmutableList createAsList() { return new ImmutableList() { // from class: com.google.common.collect.ImmutableSet.Indexed.1 @Override // java.util.List public E get(int i) { return (E) Indexed.this.get(i); } @Override // com.google.common.collect.ImmutableCollection boolean isPartialView() { return Indexed.this.isPartialView(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.List public int size() { return Indexed.this.size(); } }; } abstract E get(int i); @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet public UnmodifiableIterator iterator() { return asList().iterator(); } } private static class SerializedForm implements Serializable { final Object[] a; SerializedForm(Object[] objArr) { this.a = objArr; } Object readResolve() { return ImmutableSet.copyOf(this.a); } } ImmutableSet() { } public static Builder builder() { return new Builder<>(); } static int chooseTableSize(int i) { if (i >= CUTOFF) { Preconditions.a(i < MAX_TABLE_SIZE, "collection too large"); return MAX_TABLE_SIZE; } int highestOneBit = Integer.highestOneBit(i - 1) << 1; while (highestOneBit * DESIRED_LOAD_FACTOR < i) { highestOneBit <<= 1; } return highestOneBit; } /* JADX INFO: Access modifiers changed from: private */ public static ImmutableSet construct(int i, Object... objArr) { if (i == 0) { return of(); } if (i == 1) { return of(objArr[0]); } 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 obj = objArr[i5]; ObjectArrays.a(obj, i5); int hashCode = obj.hashCode(); int a = Hashing.a(hashCode); while (true) { int i6 = a & i2; Object obj2 = objArr2[i6]; if (obj2 == null) { objArr[i4] = obj; objArr2[i6] = obj; i3 += hashCode; i4++; break; } if (obj2.equals(obj)) { break; } a++; } } Arrays.fill(objArr, i4, i, (Object) null); if (i4 == 1) { return new SingletonImmutableSet(objArr[0], i3); } if (chooseTableSize(i4) < chooseTableSize / 2) { return construct(i4, objArr); } if (i4 < objArr.length / 2) { objArr = Arrays.copyOf(objArr, i4); } return new RegularImmutableSet(objArr, i3, objArr2, i2, i4); } 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 of() { return RegularImmutableSet.f; } @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; } ImmutableList createAsList() { return ImmutableList.asImmutableList(toArray()); } @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.a(this, obj); } @Override // java.util.Collection, java.util.Set public int hashCode() { return Sets.a(this); } boolean isHashCodeFast() { return false; } @Override // com.google.common.collect.ImmutableCollection, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set, java.util.NavigableSet public abstract UnmodifiableIterator iterator(); @Override // com.google.common.collect.ImmutableCollection Object writeReplace() { return new SerializedForm(toArray()); } public static ImmutableSet of(E e) { return new SingletonImmutableSet(e); } public static ImmutableSet of(E e, E e2) { return construct(2, e, e2); } public static ImmutableSet of(E e, E e2, E e3) { return construct(3, e, e2, e3); } public static ImmutableSet of(E e, E e2, E e3, E e4) { return construct(4, e, e2, e3, e4); } public static ImmutableSet copyOf(Iterable iterable) { if (iterable instanceof Collection) { return copyOf((Collection) iterable); } return copyOf(iterable.iterator()); } public static ImmutableSet of(E e, E e2, E e3, E e4, E e5) { return construct(5, e, e2, e3, e4, e5); } @SafeVarargs public static ImmutableSet of(E e, E e2, E e3, E e4, E e5, E e6, E... eArr) { Object[] objArr = new Object[eArr.length + 6]; objArr[0] = e; objArr[1] = e2; objArr[2] = e3; objArr[3] = e4; objArr[4] = e5; objArr[5] = e6; System.arraycopy(eArr, 0, objArr, 6, eArr.length); return construct(objArr.length, objArr); } public static ImmutableSet copyOf(Iterator it) { if (!it.hasNext()) { return of(); } E next = it.next(); if (!it.hasNext()) { return of((Object) next); } return new Builder().a((Builder) next).a((Iterator) it).a(); } public static ImmutableSet copyOf(E[] eArr) { int length = eArr.length; if (length == 0) { return of(); } if (length != 1) { return construct(eArr.length, (Object[]) eArr.clone()); } return of((Object) eArr[0]); } }