Rabbit-R1/switch port/java/sources/com/google/common/collect/CompoundOrdering.java
2024-05-21 17:08:36 -04:00

59 lines
2 KiB
Java

package com.google.common.collect;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Comparator;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
final class CompoundOrdering<T> extends Ordering<T> implements Serializable {
private static final long serialVersionUID = 0;
final Comparator<? super T>[] comparators;
/* JADX INFO: Access modifiers changed from: package-private */
public CompoundOrdering(Comparator<? super T> comparator, Comparator<? super T> comparator2) {
this.comparators = new Comparator[]{comparator, comparator2};
}
/* JADX INFO: Access modifiers changed from: package-private */
public CompoundOrdering(Iterable<? extends Comparator<? super T>> iterable) {
this.comparators = (Comparator[]) Iterables.toArray(iterable, new Comparator[0]);
}
@Override // com.google.common.collect.Ordering, java.util.Comparator
public int compare(@ParametricNullness T t, @ParametricNullness T t2) {
int i = 0;
while (true) {
Comparator<? super T>[] comparatorArr = this.comparators;
if (i >= comparatorArr.length) {
return 0;
}
int compare = comparatorArr[i].compare(t, t2);
if (compare != 0) {
return compare;
}
i++;
}
}
@Override // java.util.Comparator
public boolean equals(@CheckForNull Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof CompoundOrdering) {
return Arrays.equals(this.comparators, ((CompoundOrdering) obj).comparators);
}
return false;
}
public int hashCode() {
return Arrays.hashCode(this.comparators);
}
public String toString() {
String arrays = Arrays.toString(this.comparators);
return new StringBuilder(String.valueOf(arrays).length() + 19).append("Ordering.compound(").append(arrays).append(")").toString();
}
}