package net.pterodactylus.xdcc.ui.stdin;
+import static com.google.common.collect.FluentIterable.from;
+
import java.util.Arrays;
+import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;
+import net.pterodactylus.xdcc.core.Core;
import net.pterodactylus.xdcc.data.Bot;
+import net.pterodactylus.xdcc.data.Download;
import net.pterodactylus.xdcc.data.Pack;
+import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ComparisonChain;
}
};
+ /** Comparator that sorts bots with running downloads to the back of the list. */
+ private final Comparator<Result> botsWithRunningTransfersComparator = new Comparator<Result>() {
+ @Override
+ public int compare(Result leftResult, Result rightResult) {
+ Collection<Bot> botsWithTransfers = from(core.downloads()).transform(new Function<Download, Bot>() {
+ @Override
+ public Bot apply(Download download) {
+ return download.bot();
+ }
+ }).toSet();
+ boolean leftDownloading = botsWithTransfers.contains(leftResult.bot());
+ boolean rightDownloading = botsWithTransfers.contains(rightResult.bot());
+ if (leftDownloading && !rightDownloading) {
+ return 1;
+ }
+ if (!leftDownloading && rightDownloading) {
+ return -1;
+ }
+ return 0;
+ }
+ };
+
+ /** The core. */
+ private final Core core;
+
/** The bot carrying the pack. */
private final Bot bot;
/**
* Creates a new result.
*
+ * @param core
+ * The core
* @param bot
* The bot carrying the pack
* @param pack
- * The pack
+ * The pack of the result
*/
- Result(Bot bot, Pack pack) {
+ Result(Core core, Bot bot, Pack pack) {
+ this.core = core;
this.bot = bot;
this.pack = pack;
}
return ComparisonChain.start()
.compare(this, result, packArchiveComparator)
.compare(this, result, botNameComparator)
+ .compare(this, result, botsWithRunningTransfersComparator)
.compare(this, result, packNameComparator).result();
}