2 * XdccDownloader - StatsCommand.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.xdcc.ui.stdin;
20 import static java.util.Collections.emptyList;
22 import java.io.IOException;
23 import java.io.Writer;
24 import java.util.Collection;
25 import java.util.List;
28 import net.pterodactylus.xdcc.core.Core;
29 import net.pterodactylus.xdcc.data.Bot;
30 import net.pterodactylus.xdcc.data.Pack;
32 import com.google.common.collect.Sets;
35 * Command that outputs a short statistic of what is going on.
37 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39 public class StatsCommand implements Command {
41 /** The core to operate on. */
42 private final Core core;
45 * Creates a new stats command.
48 * The core to operate on
50 public StatsCommand(Core core) {
59 public String getName() {
64 public Collection<String> getAliases() {
69 public State execute(State state, List<String> parameters, Writer outputWriter) throws IOException {
70 int configuredChannelsCount = core.channels().size();
71 int joinedChannelsCount = core.joinedChannels().size();
72 int extraChannelsCount = core.extraChannels().size();
73 Collection<Bot> bots = core.bots();
74 Set<String> packNames = Sets.newHashSet();
76 for (Bot bot : bots) {
77 packsCount += bot.packs().size();
78 for (Pack pack : bot) {
79 packNames.add(pack.name());
83 outputWriter.write(String.format("%d channels (%d joined, %d extra), %d bots offering %d packs (%d unique).\n", configuredChannelsCount, joinedChannelsCount, extraChannelsCount, bots.size(), packsCount, packNames.size()));