package com.google.common.collect; import android.R; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableSet; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.NavigableSet; import java.util.SortedSet; /* loaded from: classes2.dex */ public abstract class ImmutableSortedSet extends ImmutableSortedSetFauxverideShim implements NavigableSet, SortedIterable { final transient Comparator comparator; transient ImmutableSortedSet descendingSet; abstract ImmutableSortedSet createDescendingSet(); @Override // java.util.NavigableSet public abstract UnmodifiableIterator descendingIterator(); /* JADX INFO: Access modifiers changed from: package-private */ public abstract ImmutableSortedSet headSetImpl(E e, boolean z); /* JADX INFO: Access modifiers changed from: package-private */ public abstract int indexOf(Object obj); @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, com.google.common.collect.SortedIterable public abstract UnmodifiableIterator iterator(); abstract ImmutableSortedSet subSetImpl(E e, boolean z, E e2, boolean z2); abstract ImmutableSortedSet tailSetImpl(E e, boolean z); /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ NavigableSet headSet(Object obj, boolean z) { return headSet((ImmutableSortedSet) obj, z); } /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ SortedSet headSet(Object obj) { return headSet((ImmutableSortedSet) obj); } @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, com.google.common.collect.SortedIterable public /* bridge */ /* synthetic */ Iterator iterator() { return iterator(); } /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ NavigableSet subSet(Object obj, boolean z, Object obj2, boolean z2) { return subSet((boolean) obj, z, (boolean) obj2, z2); } /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ NavigableSet tailSet(Object obj, boolean z) { return tailSet((ImmutableSortedSet) obj, z); } /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ SortedSet tailSet(Object obj) { return tailSet((ImmutableSortedSet) obj); } /* JADX INFO: Access modifiers changed from: package-private */ public static RegularImmutableSortedSet emptySet(Comparator comparator) { if (Ordering.natural().equals(comparator)) { return (RegularImmutableSortedSet) RegularImmutableSortedSet.NATURAL_EMPTY_SET; } return new RegularImmutableSortedSet<>(ImmutableList.of(), comparator); } public static ImmutableSortedSet of() { return RegularImmutableSortedSet.NATURAL_EMPTY_SET; } /* JADX WARN: Incorrect types in method signature: ;>(TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet of(Comparable comparable) { return new RegularImmutableSortedSet(ImmutableList.of(comparable), Ordering.natural()); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet of(Comparable comparable, Comparable comparable2) { return construct(Ordering.natural(), 2, comparable, comparable2); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet of(Comparable comparable, Comparable comparable2, Comparable comparable3) { return construct(Ordering.natural(), 3, comparable, comparable2, comparable3); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet of(Comparable comparable, Comparable comparable2, Comparable comparable3, Comparable comparable4) { return construct(Ordering.natural(), 4, comparable, comparable2, comparable3, comparable4); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;TE;TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet of(Comparable comparable, Comparable comparable2, Comparable comparable3, Comparable comparable4, Comparable comparable5) { return construct(Ordering.natural(), 5, comparable, comparable2, comparable3, comparable4, comparable5); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;TE;TE;TE;[TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet of(Comparable comparable, Comparable comparable2, Comparable comparable3, Comparable comparable4, Comparable comparable5, Comparable comparable6, Comparable... comparableArr) { int length = comparableArr.length + 6; Comparable[] comparableArr2 = new Comparable[length]; comparableArr2[0] = comparable; comparableArr2[1] = comparable2; comparableArr2[2] = comparable3; comparableArr2[3] = comparable4; comparableArr2[4] = comparable5; comparableArr2[5] = comparable6; System.arraycopy(comparableArr, 0, comparableArr2, 6, comparableArr.length); return construct(Ordering.natural(), length, comparableArr2); } /* JADX WARN: Incorrect types in method signature: ;>([TE;)Lcom/google/common/collect/ImmutableSortedSet; */ public static ImmutableSortedSet copyOf(Comparable[] comparableArr) { return construct(Ordering.natural(), comparableArr.length, (Object[]) comparableArr.clone()); } public static ImmutableSortedSet copyOf(Iterable iterable) { return copyOf(Ordering.natural(), iterable); } public static ImmutableSortedSet copyOf(Collection collection) { return copyOf((Comparator) Ordering.natural(), (Collection) collection); } public static ImmutableSortedSet copyOf(Iterator it) { return copyOf(Ordering.natural(), it); } public static ImmutableSortedSet copyOf(Comparator comparator, Iterator it) { return new Builder(comparator).addAll((Iterator) it).build(); } public static ImmutableSortedSet copyOf(Comparator comparator, Iterable iterable) { Preconditions.checkNotNull(comparator); if (SortedIterables.hasSameComparator(comparator, iterable) && (iterable instanceof ImmutableSortedSet)) { ImmutableSortedSet immutableSortedSet = (ImmutableSortedSet) iterable; if (!immutableSortedSet.isPartialView()) { return immutableSortedSet; } } Object[] array = Iterables.toArray(iterable); return construct(comparator, array.length, array); } public static ImmutableSortedSet copyOf(Comparator comparator, Collection collection) { return copyOf((Comparator) comparator, (Iterable) collection); } public static ImmutableSortedSet copyOfSorted(SortedSet sortedSet) { Comparator comparator = SortedIterables.comparator(sortedSet); ImmutableList copyOf = ImmutableList.copyOf((Collection) sortedSet); if (copyOf.isEmpty()) { return emptySet(comparator); } return new RegularImmutableSortedSet(copyOf, comparator); } /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Multi-variable type inference failed */ public static ImmutableSortedSet construct(Comparator comparator, int i, E... eArr) { if (i == 0) { return emptySet(comparator); } ObjectArrays.checkElementsNotNull(eArr, i); Arrays.sort(eArr, 0, i, comparator); int i2 = 1; for (int i3 = 1; i3 < i; i3++) { R.color colorVar = (Object) eArr[i3]; if (comparator.compare(colorVar, (Object) eArr[i2 - 1]) != 0) { eArr[i2] = colorVar; i2++; } } Arrays.fill(eArr, i2, i, (Object) null); if (i2 < eArr.length / 2) { eArr = (E[]) Arrays.copyOf(eArr, i2); } return new RegularImmutableSortedSet(ImmutableList.asImmutableList(eArr, i2), comparator); } public static Builder orderedBy(Comparator comparator) { return new Builder<>(comparator); } public static > Builder reverseOrder() { return new Builder<>(Collections.reverseOrder()); } public static > Builder naturalOrder() { return new Builder<>(Ordering.natural()); } /* loaded from: classes2.dex */ public static final class Builder extends ImmutableSet.Builder { private final Comparator comparator; /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public final /* bridge */ /* synthetic */ ImmutableCollection.ArrayBasedBuilder add(Object obj) { return add((Builder) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public final /* bridge */ /* synthetic */ ImmutableCollection.Builder add(Object obj) { return add((Builder) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public final /* bridge */ /* synthetic */ ImmutableSet.Builder add(Object obj) { return add((Builder) obj); } public Builder(Comparator comparator) { this.comparator = (Comparator) Preconditions.checkNotNull(comparator); } @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public final Builder add(E e) { super.add((Builder) e); return this; } @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public final Builder add(E... eArr) { super.add((Object[]) eArr); return this; } @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.ArrayBasedBuilder, com.google.common.collect.ImmutableCollection.Builder public final Builder addAll(Iterable iterable) { super.addAll((Iterable) iterable); return this; } @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.Builder public final Builder addAll(Iterator it) { super.addAll((Iterator) it); return this; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.ImmutableSet.Builder public final Builder combine(ImmutableSet.Builder builder) { super.combine((ImmutableSet.Builder) builder); return this; } @Override // com.google.common.collect.ImmutableSet.Builder, com.google.common.collect.ImmutableCollection.Builder public final ImmutableSortedSet build() { ImmutableSortedSet construct = ImmutableSortedSet.construct(this.comparator, this.size, this.contents); this.size = construct.size(); this.forceCopy = true; return construct; } } /* JADX INFO: Access modifiers changed from: package-private */ public int unsafeCompare(Object obj, Object obj2) { return unsafeCompare(this.comparator, obj, obj2); } static int unsafeCompare(Comparator comparator, Object obj, Object obj2) { return comparator.compare(obj, obj2); } /* JADX INFO: Access modifiers changed from: package-private */ public ImmutableSortedSet(Comparator comparator) { this.comparator = comparator; } public ImmutableSortedSet headSet(E e) { return headSet((ImmutableSortedSet) e, false); } /* JADX WARN: Multi-variable type inference failed */ public ImmutableSortedSet headSet(E e, boolean z) { return headSetImpl(Preconditions.checkNotNull(e), z); } @Override // java.util.NavigableSet, java.util.SortedSet public ImmutableSortedSet subSet(E e, E e2) { return subSet((boolean) e, true, (boolean) e2, false); } public ImmutableSortedSet subSet(E e, boolean z, E e2, boolean z2) { Preconditions.checkNotNull(e); Preconditions.checkNotNull(e2); Preconditions.checkArgument(this.comparator.compare(e, e2) <= 0); return subSetImpl(e, z, e2, z2); } public ImmutableSortedSet tailSet(E e) { return tailSet((ImmutableSortedSet) e, true); } /* JADX WARN: Multi-variable type inference failed */ public ImmutableSortedSet tailSet(E e, boolean z) { return tailSetImpl(Preconditions.checkNotNull(e), z); } public E lower(E e) { return (E) Iterators.getNext(headSet((ImmutableSortedSet) e, false).descendingIterator(), null); } public E floor(E e) { return (E) Iterators.getNext(headSet((ImmutableSortedSet) e, true).descendingIterator(), null); } public E ceiling(E e) { return (E) Iterables.getFirst(tailSet((ImmutableSortedSet) e, true), null); } public E higher(E e) { return (E) Iterables.getFirst(tailSet((ImmutableSortedSet) e, false), null); } public E first() { return iterator().next(); } public E last() { return descendingIterator().next(); } @Override // java.util.NavigableSet @Deprecated public final E pollFirst() { throw new UnsupportedOperationException(); } @Override // java.util.NavigableSet @Deprecated public final E pollLast() { throw new UnsupportedOperationException(); } @Override // java.util.NavigableSet public ImmutableSortedSet descendingSet() { ImmutableSortedSet immutableSortedSet = this.descendingSet; if (immutableSortedSet != null) { return immutableSortedSet; } ImmutableSortedSet createDescendingSet = createDescendingSet(); this.descendingSet = createDescendingSet; createDescendingSet.descendingSet = this; return createDescendingSet; } /* loaded from: classes2.dex */ static class SerializedForm implements Serializable { private static final long serialVersionUID = 0; final Comparator comparator; final Object[] elements; public SerializedForm(Comparator comparator, Object[] objArr) { this.comparator = comparator; this.elements = objArr; } /* JADX WARN: Multi-variable type inference failed */ Object readResolve() { return new Builder(this.comparator).add(this.elements).build(); } } private void readObject(ObjectInputStream objectInputStream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } @Override // com.google.common.collect.ImmutableSet, com.google.common.collect.ImmutableCollection Object writeReplace() { return new SerializedForm(this.comparator, toArray()); } @Override // java.util.SortedSet, com.google.common.collect.SortedIterable public Comparator comparator() { return this.comparator; } }