mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
68 lines
2.1 KiB
Java
68 lines
2.1 KiB
Java
package com.google.common.collect;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import java.util.Comparator;
|
|
import java.util.Iterator;
|
|
|
|
@ElementTypesAreNonnullByDefault
|
|
/* loaded from: classes3.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 ? t : t2;
|
|
}
|
|
|
|
@ParametricNullness
|
|
public static <T> T min(@ParametricNullness T t, @ParametricNullness T t2, Comparator<T> comparator) {
|
|
return comparator.compare(t, t2) <= 0 ? t : t2;
|
|
}
|
|
|
|
public static <T extends Comparable<? super T>> T max(T t, T t2) {
|
|
return t.compareTo(t2) >= 0 ? t : t2;
|
|
}
|
|
|
|
@ParametricNullness
|
|
public static <T> T max(@ParametricNullness T t, @ParametricNullness T t2, Comparator<T> comparator) {
|
|
return comparator.compare(t, t2) >= 0 ? t : t2;
|
|
}
|
|
}
|