};
/**
+ * {@link Comparator} for {@link Result}s that sorts archives (as per {@link
+ * #isArchive} to the back of the list.
+ */
+ private static final Comparator<Result> packArchiveComparator = new Comparator<Result>() {
+ @Override
+ public int compare(Result leftResult, Result rightResult) {
+ if (isArchive.apply(leftResult) && !isArchive.apply(rightResult)) {
+ return 1;
+ }
+ if (!isArchive.apply(leftResult) && isArchive.apply(rightResult)) {
+ return -1;
+ }
+ return 0;
+ }
+ };
+
+ /**
* {@link Comparator} for bot nicknames. It comprises different strategies:
* one name pattern is preferred (and thus listed first), one pattern is
* disliked (and thus listed last), the rest is sorted alphabetically.
*/
- private static final Comparator<String> botNameComparator = new Comparator<String>() {
+ private static final Comparator<Result> botNameComparator = new Comparator<Result>() {
/** Regular expression pattern for preferred names. */
private final Pattern preferredNames = Pattern.compile("(?i)[^\\w]EUR?[^\\w]");
private final Pattern dislikedNames = Pattern.compile("(?i)[^\\w]USA?[^\\w]");
@Override
- public int compare(String leftBotName, String rightBotName) {
+ public int compare(Result leftResult, Result rightResult) {
+ String leftBotName = leftResult.bot().name();
+ String rightBotName = rightResult.bot().name();
/* preferred names to the front! */
if (preferredNames.matcher(leftBotName).find() && !preferredNames.matcher(rightBotName).find()) {
return -1;
if (dislikedNames.matcher(rightBotName).find() && !dislikedNames.matcher(leftBotName).find()) {
return -1;
}
- /* rest is sorted by name. */
- return leftBotName.compareToIgnoreCase(rightBotName);
+ return 0;
+ }
+ };
+
+ /**
+ * {@link Comparator} for {@link Result}s that sorts them by the name of the
+ * {@link Pack}.
+ */
+ private static final Comparator<Result> packNameComparator = new Comparator<Result>() {
+ @Override
+ public int compare(Result leftResult, Result rightResult) {
+ return leftResult.pack().name().compareToIgnoreCase(rightResult.pack().name());
}
};