Fix output of stats command for missing joined or forced channels.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / ui / stdin / StatsCommand.java
index 07f2288..d40cc82 100644 (file)
@@ -65,16 +65,35 @@ public class StatsCommand implements Command {
                return null;
        }
 
-       private void dumpNetworkStats(Writer outputWriter, ConnectedNetwork network) throws IOException {
-               outputWriter.write(format("Connected to %s via %s:%d.\n", network.getNetwork().name(), network.getHostname(), network.getPort(), network.getNickname()));
+       private void dumpNetworkStats(Writer outputWriter,
+                       ConnectedNetwork network) throws IOException {
+               outputWriter.write(format("Connected to %s via %s:%d.\n",
+                               network.getNetwork().name(), network.getHostname(),
+                               network.getPort(), network.getNickname()));
+               String joinedChannels = joinChannelNames(network.getChannels());
+               String forcedChannels = joinChannelNames(network.getForcedChannels());
+               if (forcedChannels.isEmpty()) {
+                       if (!joinedChannels.isEmpty()) {
+                               outputWriter.write(format("  Joined %s.\n", joinedChannels));
+                       }
+               } else {
+                       if (joinedChannels.isEmpty()) {
+                               outputWriter.write(
+                                               format("  Force-joined %s.\n", forcedChannels));
+                       } else {
+                               outputWriter.write(format("  Joined %s, force-joined %s.\n",
+                                               joinedChannels, forcedChannels));
+                       }
+               }
+               outputWriter.write(
+                               format("  %d bots serving %d packs.\n", network.getBotCount(),
+                                               network.getPackCount()));
+       }
+
+       private String joinChannelNames(Collection<String> channels) {
                StringJoiner joinedChannels = new StringJoiner(", ");
-               network.getChannels().stream().forEach(
-                               (channel) -> joinedChannels.add(channel));
-               StringJoiner forceJoinedChannels = new StringJoiner(", ");
-               network.getForcedChannels().stream().forEach((channel) -> forceJoinedChannels.add(channel));
-               outputWriter.write(format("  Joined %s, force-joined %s.\n",
-                               joinedChannels, forceJoinedChannels));
-               outputWriter.write(format("  %d bots serving %d packs.\n", network.getBotCount(), network.getPackCount()));
+               channels.stream().forEach((channel) -> joinedChannels.add(channel));
+               return joinedChannels.toString();
        }
 
 }