querqy.PriorityComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of querqy-core Show documentation
Show all versions of querqy-core Show documentation
Querqy library for query rewriting: Querqy Core
package querqy;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
public class PriorityComparator implements Comparator {
private final List> comparators;
public PriorityComparator(final List> comparators) {
this.comparators = comparators;
}
@Override
public int compare(final T o1, final T o2) {
for (final Comparator comparator : comparators) {
int c = comparator.compare(o1, o2);
if (c != 0) {
return c;
}
}
return 0;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PriorityComparator)) return false;
PriorityComparator> that = (PriorityComparator>) o;
return Objects.equals(comparators, that.comparators);
}
@Override
public int hashCode() {
return Objects.hash(comparators);
}
}