package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultiset; import com.google.common.collect.Multiset; import com.google.common.math.IntMath; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; /* loaded from: classes2.dex */ public abstract class ImmutableSortedMultiset extends ImmutableSortedMultisetFauxverideShim implements SortedMultiset { transient ImmutableSortedMultiset descendingMultiset; @Override // com.google.common.collect.ImmutableMultiset, com.google.common.collect.Multiset public abstract ImmutableSortedSet elementSet(); public abstract ImmutableSortedMultiset headMultiset(E e, BoundType boundType); public abstract ImmutableSortedMultiset tailMultiset(E e, BoundType boundType); /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ SortedMultiset headMultiset(Object obj, BoundType boundType) { return headMultiset((ImmutableSortedMultiset) obj, boundType); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.SortedMultiset public /* bridge */ /* synthetic */ SortedMultiset subMultiset(Object obj, BoundType boundType, Object obj2, BoundType boundType2) { return subMultiset((BoundType) obj, boundType, (BoundType) obj2, boundType2); } /* JADX WARN: Multi-variable type inference failed */ public /* bridge */ /* synthetic */ SortedMultiset tailMultiset(Object obj, BoundType boundType) { return tailMultiset((ImmutableSortedMultiset) obj, boundType); } public static ImmutableSortedMultiset of() { return (ImmutableSortedMultiset) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET; } /* JADX WARN: Incorrect types in method signature: ;>(TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset of(Comparable comparable) { return new RegularImmutableSortedMultiset((RegularImmutableSortedSet) ImmutableSortedSet.of(comparable), new long[]{0, 1}, 0, 1); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset of(Comparable comparable, Comparable comparable2) { return copyOf(Ordering.natural(), Arrays.asList(comparable, comparable2)); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset of(Comparable comparable, Comparable comparable2, Comparable comparable3) { return copyOf(Ordering.natural(), Arrays.asList(comparable, comparable2, comparable3)); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset of(Comparable comparable, Comparable comparable2, Comparable comparable3, Comparable comparable4) { return copyOf(Ordering.natural(), Arrays.asList(comparable, comparable2, comparable3, comparable4)); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;TE;TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset of(Comparable comparable, Comparable comparable2, Comparable comparable3, Comparable comparable4, Comparable comparable5) { return copyOf(Ordering.natural(), Arrays.asList(comparable, comparable2, comparable3, comparable4, comparable5)); } /* JADX WARN: Incorrect types in method signature: ;>(TE;TE;TE;TE;TE;TE;[TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset of(Comparable comparable, Comparable comparable2, Comparable comparable3, Comparable comparable4, Comparable comparable5, Comparable comparable6, Comparable... comparableArr) { ArrayList newArrayListWithCapacity = Lists.newArrayListWithCapacity(comparableArr.length + 6); Collections.addAll(newArrayListWithCapacity, comparable, comparable2, comparable3, comparable4, comparable5, comparable6); Collections.addAll(newArrayListWithCapacity, comparableArr); return copyOf(Ordering.natural(), newArrayListWithCapacity); } /* JADX WARN: Incorrect types in method signature: ;>([TE;)Lcom/google/common/collect/ImmutableSortedMultiset; */ public static ImmutableSortedMultiset copyOf(Comparable[] comparableArr) { return copyOf(Ordering.natural(), Arrays.asList(comparableArr)); } public static ImmutableSortedMultiset copyOf(Iterable iterable) { return copyOf(Ordering.natural(), iterable); } public static ImmutableSortedMultiset copyOf(Iterator it) { return copyOf(Ordering.natural(), it); } public static ImmutableSortedMultiset copyOf(Comparator comparator, Iterator it) { Preconditions.checkNotNull(comparator); return new Builder(comparator).addAll((Iterator) it).build(); } public static ImmutableSortedMultiset copyOf(Comparator comparator, Iterable iterable) { if (iterable instanceof ImmutableSortedMultiset) { ImmutableSortedMultiset immutableSortedMultiset = (ImmutableSortedMultiset) iterable; if (comparator.equals(immutableSortedMultiset.comparator())) { return immutableSortedMultiset.isPartialView() ? copyOfSortedEntries(comparator, immutableSortedMultiset.entrySet().asList()) : immutableSortedMultiset; } } return new Builder(comparator).addAll((Iterable) iterable).build(); } public static ImmutableSortedMultiset copyOfSorted(SortedMultiset sortedMultiset) { return copyOfSortedEntries(sortedMultiset.comparator(), Lists.newArrayList(sortedMultiset.entrySet())); } private static ImmutableSortedMultiset copyOfSortedEntries(Comparator comparator, Collection> collection) { if (collection.isEmpty()) { return emptyMultiset(comparator); } ImmutableList.Builder builder = new ImmutableList.Builder(collection.size()); long[] jArr = new long[collection.size() + 1]; Iterator> it = collection.iterator(); int i = 0; while (it.hasNext()) { builder.add((ImmutableList.Builder) it.next().getElement()); int i2 = i + 1; jArr[i2] = jArr[i] + r5.getCount(); i = i2; } return new RegularImmutableSortedMultiset(new RegularImmutableSortedSet(builder.build(), comparator), jArr, 0, collection.size()); } /* JADX INFO: Access modifiers changed from: package-private */ public static ImmutableSortedMultiset emptyMultiset(Comparator comparator) { if (Ordering.natural().equals(comparator)) { return (ImmutableSortedMultiset) RegularImmutableSortedMultiset.NATURAL_EMPTY_MULTISET; } return new RegularImmutableSortedMultiset(comparator); } @Override // com.google.common.collect.SortedMultiset, com.google.common.collect.SortedIterable public final Comparator comparator() { return elementSet().comparator(); } @Override // com.google.common.collect.SortedMultiset public ImmutableSortedMultiset descendingMultiset() { ImmutableSortedMultiset immutableSortedMultiset = this.descendingMultiset; if (immutableSortedMultiset == null) { if (isEmpty()) { immutableSortedMultiset = emptyMultiset(Ordering.from(comparator()).reverse()); } else { immutableSortedMultiset = new DescendingImmutableSortedMultiset<>(this); } this.descendingMultiset = immutableSortedMultiset; } return immutableSortedMultiset; } @Override // com.google.common.collect.SortedMultiset @Deprecated public final Multiset.Entry pollFirstEntry() { throw new UnsupportedOperationException(); } @Override // com.google.common.collect.SortedMultiset @Deprecated public final Multiset.Entry pollLastEntry() { throw new UnsupportedOperationException(); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.SortedMultiset public ImmutableSortedMultiset subMultiset(E e, BoundType boundType, E e2, BoundType boundType2) { Preconditions.checkArgument(comparator().compare(e, e2) <= 0, "Expected lowerBound <= upperBound but %s > %s", e, e2); return tailMultiset((ImmutableSortedMultiset) e, boundType).headMultiset((ImmutableSortedMultiset) e2, boundType2); } public static Builder orderedBy(Comparator comparator) { return new Builder<>(comparator); } public static > Builder reverseOrder() { return new Builder<>(Ordering.natural().reverse()); } public static > Builder naturalOrder() { return new Builder<>(Ordering.natural()); } /* loaded from: classes2.dex */ public static class Builder extends ImmutableMultiset.Builder { private final Comparator comparator; private int[] counts; E[] elements; private boolean forceCopyElements; private int length; /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public /* bridge */ /* synthetic */ ImmutableCollection.Builder add(Object obj) { return add((Builder) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public /* bridge */ /* synthetic */ ImmutableMultiset.Builder add(Object obj) { return add((Builder) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultiset.Builder public /* bridge */ /* synthetic */ ImmutableMultiset.Builder addCopies(Object obj, int i) { return addCopies((Builder) obj, i); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.ImmutableMultiset.Builder public /* bridge */ /* synthetic */ ImmutableMultiset.Builder setCount(Object obj, int i) { return setCount((Builder) obj, i); } public Builder(Comparator comparator) { super(true); this.comparator = (Comparator) Preconditions.checkNotNull(comparator); this.elements = (E[]) new Object[4]; this.counts = new int[4]; } private void maintenance() { int i = this.length; E[] eArr = this.elements; if (i == eArr.length) { dedupAndCoalesce(true); } else if (this.forceCopyElements) { this.elements = (E[]) Arrays.copyOf(eArr, eArr.length); } this.forceCopyElements = false; } private void dedupAndCoalesce(boolean z) { int i = this.length; if (i == 0) { return; } Object[] objArr = (E[]) Arrays.copyOf(this.elements, i); Arrays.sort(objArr, this.comparator); int i2 = 1; for (int i3 = 1; i3 < objArr.length; i3++) { if (this.comparator.compare((Object) objArr[i2 - 1], (Object) objArr[i3]) < 0) { objArr[i2] = objArr[i3]; i2++; } } Arrays.fill(objArr, i2, this.length, (Object) null); if (z) { int i4 = this.length; if ((i2 << 2) > i4 * 3) { objArr = (E[]) Arrays.copyOf(objArr, IntMath.saturatedAdd(i4, (i4 / 2) + 1)); } } int[] iArr = new int[objArr.length]; for (int i5 = 0; i5 < this.length; i5++) { int binarySearch = Arrays.binarySearch(objArr, 0, i2, this.elements[i5], this.comparator); int i6 = this.counts[i5]; if (i6 >= 0) { iArr[binarySearch] = iArr[binarySearch] + i6; } else { iArr[binarySearch] = ~i6; } } this.elements = (E[]) objArr; this.counts = iArr; this.length = i2; } @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public Builder add(E e) { return addCopies((Builder) e, 1); } @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public Builder add(E... eArr) { for (E e : eArr) { add((Builder) e); } return this; } @Override // com.google.common.collect.ImmutableMultiset.Builder public Builder addCopies(E e, int i) { Preconditions.checkNotNull(e); CollectPreconditions.checkNonnegative(i, "occurrences"); if (i == 0) { return this; } maintenance(); E[] eArr = this.elements; int i2 = this.length; eArr[i2] = e; this.counts[i2] = i; this.length = i2 + 1; return this; } @Override // com.google.common.collect.ImmutableMultiset.Builder public Builder setCount(E e, int i) { Preconditions.checkNotNull(e); CollectPreconditions.checkNonnegative(i, "count"); maintenance(); E[] eArr = this.elements; int i2 = this.length; eArr[i2] = e; this.counts[i2] = ~i; this.length = i2 + 1; return this; } @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public Builder addAll(Iterable iterable) { if (iterable instanceof Multiset) { for (Multiset.Entry entry : ((Multiset) iterable).entrySet()) { addCopies((Builder) entry.getElement(), entry.getCount()); } } else { Iterator it = iterable.iterator(); while (it.hasNext()) { add((Builder) it.next()); } } return this; } @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public Builder addAll(Iterator it) { while (it.hasNext()) { add((Builder) it.next()); } return this; } private void dedupAndCoalesceAndDeleteEmpty() { dedupAndCoalesce(false); int i = 0; int i2 = 0; while (true) { int i3 = this.length; if (i < i3) { int[] iArr = this.counts; int i4 = iArr[i]; if (i4 > 0) { E[] eArr = this.elements; eArr[i2] = eArr[i]; iArr[i2] = i4; i2++; } i++; } else { Arrays.fill(this.elements, i2, i3, (Object) null); Arrays.fill(this.counts, i2, this.length, 0); this.length = i2; return; } } } @Override // com.google.common.collect.ImmutableMultiset.Builder, com.google.common.collect.ImmutableCollection.Builder public ImmutableSortedMultiset build() { dedupAndCoalesceAndDeleteEmpty(); int i = this.length; if (i == 0) { return ImmutableSortedMultiset.emptyMultiset(this.comparator); } RegularImmutableSortedSet regularImmutableSortedSet = (RegularImmutableSortedSet) ImmutableSortedSet.construct(this.comparator, i, this.elements); long[] jArr = new long[this.length + 1]; int i2 = 0; while (i2 < this.length) { int i3 = i2 + 1; jArr[i3] = jArr[i2] + this.counts[i2]; i2 = i3; } this.forceCopyElements = true; return new RegularImmutableSortedMultiset(regularImmutableSortedSet, jArr, 0, this.length); } } /* loaded from: classes2.dex */ static final class SerializedForm implements Serializable { final Comparator comparator; final int[] counts; final E[] elements; SerializedForm(SortedMultiset sortedMultiset) { this.comparator = sortedMultiset.comparator(); int size = sortedMultiset.entrySet().size(); this.elements = (E[]) new Object[size]; this.counts = new int[size]; int i = 0; for (Multiset.Entry entry : sortedMultiset.entrySet()) { this.elements[i] = entry.getElement(); this.counts[i] = entry.getCount(); i++; } } final Object readResolve() { int length = this.elements.length; Builder builder = new Builder(this.comparator); for (int i = 0; i < length; i++) { builder.addCopies((Builder) this.elements[i], this.counts[i]); } return builder.build(); } } @Override // com.google.common.collect.ImmutableMultiset, com.google.common.collect.ImmutableCollection Object writeReplace() { return new SerializedForm(this); } }