what-the-bank/sources/com/google/common/collect/Comparators.java

66 lines
2.0 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Preconditions;
import java.util.Comparator;
import java.util.Iterator;
/* loaded from: classes2.dex */
public final class Comparators {
private Comparators() {
}
public static <T, S extends T> Comparator<Iterable<S>> lexicographical(Comparator<T> comparator) {
return new LexicographicalOrdering((Comparator) Preconditions.checkNotNull(comparator));
}
public static <T> boolean isInOrder(Iterable<? extends T> iterable, Comparator<T> comparator) {
Preconditions.checkNotNull(comparator);
Iterator<? extends T> it = iterable.iterator();
if (!it.hasNext()) {
return true;
}
T next = it.next();
while (it.hasNext()) {
T next2 = it.next();
if (comparator.compare(next, next2) > 0) {
return false;
}
next = next2;
}
return true;
}
public static <T> boolean isInStrictOrder(Iterable<? extends T> iterable, Comparator<T> comparator) {
Preconditions.checkNotNull(comparator);
Iterator<? extends T> it = iterable.iterator();
if (!it.hasNext()) {
return true;
}
T next = it.next();
while (it.hasNext()) {
T next2 = it.next();
if (comparator.compare(next, next2) >= 0) {
return false;
}
next = next2;
}
return true;
}
public static <T extends Comparable<? super T>> T min(T t, T t2) {
return t.compareTo(t2) > 0 ? t2 : t;
}
public static <T> T min(T t, T t2, Comparator<T> comparator) {
return comparator.compare(t, t2) > 0 ? t2 : t;
}
public static <T extends Comparable<? super T>> T max(T t, T t2) {
return t.compareTo(t2) < 0 ? t2 : t;
}
public static <T> T max(T t, T t2, Comparator<T> comparator) {
return comparator.compare(t, t2) < 0 ? t2 : t;
}
}