package com.google.common.collect; import com.google.common.base.Function; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; /* loaded from: classes2.dex */ public abstract class Ordering implements Comparator { static final int LEFT_IS_GREATER = 1; static final int RIGHT_IS_GREATER = -1; @Override // java.util.Comparator public abstract int compare(T t, T t2); public static Ordering natural() { return NaturalOrdering.INSTANCE; } public static Ordering from(Comparator comparator) { if (comparator instanceof Ordering) { return (Ordering) comparator; } return new ComparatorOrdering(comparator); } @Deprecated public static Ordering from(Ordering ordering) { return (Ordering) Preconditions.checkNotNull(ordering); } public static Ordering explicit(List list) { return new ExplicitOrdering(list); } public static Ordering explicit(T t, T... tArr) { return explicit(Lists.asList(t, tArr)); } public static Ordering allEqual() { return AllEqualOrdering.INSTANCE; } public static Ordering usingToString() { return UsingToStringOrdering.INSTANCE; } public static Ordering arbitrary() { return ArbitraryOrderingHolder.ARBITRARY_ORDERING; } /* loaded from: classes2.dex */ static class ArbitraryOrderingHolder { static final Ordering ARBITRARY_ORDERING = new ArbitraryOrdering(); private ArbitraryOrderingHolder() { } } /* loaded from: classes2.dex */ static class ArbitraryOrdering extends Ordering { private final AtomicInteger counter = new AtomicInteger(0); private final ConcurrentMap uids = Platform.tryWeakKeys(new MapMaker()).makeMap(); ArbitraryOrdering() { } private Integer getUid(Object obj) { Integer num = this.uids.get(obj); if (num != null) { return num; } Integer valueOf = Integer.valueOf(this.counter.getAndIncrement()); Integer putIfAbsent = this.uids.putIfAbsent(obj, valueOf); return putIfAbsent != null ? putIfAbsent : valueOf; } @Override // com.google.common.collect.Ordering, java.util.Comparator public int compare(Object obj, Object obj2) { if (obj == obj2) { return 0; } if (obj == null) { return -1; } if (obj2 == null) { return 1; } int identityHashCode = identityHashCode(obj); int identityHashCode2 = identityHashCode(obj2); if (identityHashCode != identityHashCode2) { return identityHashCode >= identityHashCode2 ? 1 : -1; } int compareTo = getUid(obj).compareTo(getUid(obj2)); if (compareTo != 0) { return compareTo; } throw new AssertionError(); } int identityHashCode(Object obj) { return System.identityHashCode(obj); } public String toString() { return "Ordering.arbitrary()"; } } public Ordering reverse() { return new ReverseOrdering(this); } public Ordering nullsFirst() { return new NullsFirstOrdering(this); } public Ordering nullsLast() { return new NullsLastOrdering(this); } public Ordering onResultOf(Function function) { return new ByFunctionOrdering(function, this); } /* JADX INFO: Access modifiers changed from: package-private */ public Ordering> onKeys() { return (Ordering>) onResultOf(Maps.keyFunction()); } public Ordering compound(Comparator comparator) { return new CompoundOrdering(this, (Comparator) Preconditions.checkNotNull(comparator)); } public static Ordering compound(Iterable> iterable) { return new CompoundOrdering(iterable); } public Ordering> lexicographical() { return new LexicographicalOrdering(this); } public E min(Iterator it) { E next = it.next(); while (it.hasNext()) { next = (E) min(next, it.next()); } return next; } public E min(Iterable iterable) { return (E) min(iterable.iterator()); } /* JADX WARN: Multi-variable type inference failed */ public E min(E e, E e2) { return compare(e, e2) > 0 ? e2 : e; } public E min(E e, E e2, E e3, E... eArr) { E e4 = (E) min(min(e, e2), e3); for (E e5 : eArr) { e4 = (E) min(e4, e5); } return e4; } public E max(Iterator it) { E next = it.next(); while (it.hasNext()) { next = (E) max(next, it.next()); } return next; } public E max(Iterable iterable) { return (E) max(iterable.iterator()); } /* JADX WARN: Multi-variable type inference failed */ public E max(E e, E e2) { return compare(e, e2) < 0 ? e2 : e; } public E max(E e, E e2, E e3, E... eArr) { E e4 = (E) max(max(e, e2), e3); for (E e5 : eArr) { e4 = (E) max(e4, e5); } return e4; } public List leastOf(Iterable iterable, int i) { if (iterable instanceof Collection) { Collection collection = (Collection) iterable; if (collection.size() <= (i << 1)) { Object[] array = collection.toArray(); Arrays.sort(array, this); if (array.length > i) { array = Arrays.copyOf(array, i); } return Collections.unmodifiableList(Arrays.asList(array)); } } return leastOf(iterable.iterator(), i); } public List leastOf(Iterator it, int i) { Preconditions.checkNotNull(it); CollectPreconditions.checkNonnegative(i, "k"); if (i == 0 || !it.hasNext()) { return Collections.emptyList(); } if (i >= 1073741823) { ArrayList newArrayList = Lists.newArrayList(it); Collections.sort(newArrayList, this); if (newArrayList.size() > i) { newArrayList.subList(i, newArrayList.size()).clear(); } newArrayList.trimToSize(); return Collections.unmodifiableList(newArrayList); } TopKSelector least = TopKSelector.least(i, this); least.offerAll(it); return least.topK(); } public List greatestOf(Iterable iterable, int i) { return reverse().leastOf(iterable, i); } public List greatestOf(Iterator it, int i) { return reverse().leastOf(it, i); } public List sortedCopy(Iterable iterable) { Object[] array = Iterables.toArray(iterable); Arrays.sort(array, this); return Lists.newArrayList(Arrays.asList(array)); } public ImmutableList immutableSortedCopy(Iterable iterable) { return ImmutableList.sortedCopyOf(this, iterable); } public boolean isOrdered(Iterable iterable) { Iterator it = iterable.iterator(); if (!it.hasNext()) { return true; } T next = it.next(); while (it.hasNext()) { T next2 = it.next(); if (compare(next, next2) > 0) { return false; } next = next2; } return true; } public boolean isStrictlyOrdered(Iterable iterable) { Iterator it = iterable.iterator(); if (!it.hasNext()) { return true; } T next = it.next(); while (it.hasNext()) { T next2 = it.next(); if (compare(next, next2) >= 0) { return false; } next = next2; } return true; } @Deprecated public int binarySearch(List list, T t) { return Collections.binarySearch(list, t, this); } /* loaded from: classes2.dex */ static class IncomparableValueException extends ClassCastException { private static final long serialVersionUID = 0; final Object value; /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: Illegal instructions before constructor call */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public IncomparableValueException(java.lang.Object r4) { /* r3 = this; java.lang.String r0 = java.lang.String.valueOf(r4) java.lang.StringBuilder r1 = new java.lang.StringBuilder java.lang.String r2 = java.lang.String.valueOf(r0) int r2 = r2.length() int r2 = r2 + 22 r1.(r2) java.lang.String r2 = "Cannot compare value: " r1.append(r2) r1.append(r0) java.lang.String r0 = r1.toString() r3.(r0) r3.value = r4 return */ throw new UnsupportedOperationException("Method not decompiled: com.google.common.collect.Ordering.IncomparableValueException.(java.lang.Object):void"); } } }