2 * XdccDownloader - Bot.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.data;
20 import java.util.Collection;
21 import java.util.Iterator;
24 import com.google.common.collect.Maps;
27 * A bot is a client in a {@link Network} that carries {@link Pack}s which are
28 * available for download.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class Bot implements Iterable<Pack> {
34 /** The network this bot is on. */
35 private final Network network;
37 /** The packs this bot carries. */
38 private final Map<String, Pack> packs = Maps.newHashMap();
40 /** The current name of the bot. */
47 * The network the bot is on
49 public Bot(Network network) {
50 this.network = network;
58 * Returns the network the bot is on.
60 * @return The network the bot is on
62 public Network network() {
67 * Returns the current name of this bot.
69 * @return The current name of this bot
71 public String name() {
76 * Returns the packs this bot carries.
78 * @return The packs this bot carries
80 public Collection<Pack> packs() {
81 return packs.values();
89 * Sets the current name of this bot.
92 * The name of this bot
95 public Bot name(String name) {
105 * Adds the given pack to this bot.
110 public void addPack(Pack pack) {
111 packs.put(pack.id(), pack);
119 public Iterator<Pack> iterator() {
120 return packs.values().iterator();
128 public String toString() {
129 return String.format("%s/%s", name(), network().name());