X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fui%2Fstdin%2FCommandReader.java;h=5feabd7045342b8c7c42cdba401c4a0547af06b9;hb=051375293ec12d97d9615c739cf92ef9725cc7dd;hp=d3821aa44b16e0d2f8fd11136b2eaae3327502ff;hpb=627395d1991e2a172ec851247ceb9ef643cb721b;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java index d3821aa..5feabd7 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java @@ -17,6 +17,9 @@ package net.pterodactylus.xdcc.ui.stdin; +import static net.pterodactylus.xdcc.data.Download.BY_NAME; +import static net.pterodactylus.xdcc.data.Download.BY_RUNNING; + import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; @@ -43,7 +46,10 @@ import net.pterodactylus.xdcc.data.Download; import net.pterodactylus.xdcc.data.Pack; import com.google.common.base.Predicate; +import com.google.common.collect.ComparisonChain; +import com.google.common.collect.FluentIterable; import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.google.common.eventbus.Subscribe; import com.google.common.primitives.Ints; @@ -124,7 +130,7 @@ public class CommandReader extends AbstractExecutionThreadService { writeLine("End of Search."); } else if (words[0].equalsIgnoreCase("dcc")) { int counter = 0; - for (Download download : core.downloads()) { + for (Download download : FluentIterable.from(core.downloads()).toSortedList(Ordering.from(BY_NAME).compound(BY_RUNNING))) { DccReceiver dccReceiver = download.dccReceiver(); if (dccReceiver == null) { /* download has not even started. */ @@ -381,6 +387,17 @@ public class CommandReader extends AbstractExecutionThreadService { } }; + /** + * {@link Comparator} for {@link Result}s that sorts them by the name of the + * {@link Pack}. + */ + private static final Comparator packNameComparator = new Comparator() { + @Override + public int compare(Result leftResult, Result rightResult) { + return leftResult.pack().name().compareToIgnoreCase(rightResult.pack().name()); + } + }; + /** The bot carrying the pack. */ private final Bot bot; @@ -428,14 +445,10 @@ public class CommandReader extends AbstractExecutionThreadService { @Override public int compareTo(Result result) { - if (isArchive.apply(this) && !isArchive.apply(result)) { - return 1; - } - if (!isArchive.apply(this) && isArchive.apply(result)) { - return -1; - } - /* sort by bot name. */ - return botNameComparator.compare(bot().name(), result.bot().name()); + return ComparisonChain.start() + .compare(this, result, packArchiveComparator) + .compare(this, result, botNameComparator) + .compare(this, result, packNameComparator).result(); } }