Add bots and packs.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Bot.java
1 /*
2  * XdccDownloader - Bot.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.xdcc.data;
19
20 import java.util.Collection;
21 import java.util.Map;
22
23 import com.beust.jcommander.internal.Maps;
24
25 /**
26  * A bot is a client in a {@link Network} that carries {@link Pack}s which are
27  * available for download.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class Bot {
32
33         /** The network this bot is on. */
34         private final Network network;
35
36         /** The packs this bot carries. */
37         private final Map<String, Pack> packs = Maps.newHashMap();
38
39         /** The current name of the bot. */
40         private String name;
41
42         /**
43          * Creates a new bot.
44          *
45          * @param network
46          *              The network the bot is on
47          */
48         public Bot(Network network) {
49                 this.network = network;
50         }
51
52         //
53         // ACCESSORS
54         //
55
56         /**
57          * Returns the network the bot is on.
58          *
59          * @return The network the bot is on
60          */
61         public Network network() {
62                 return network;
63         }
64
65         /**
66          * Returns the current name of this bot.
67          *
68          * @return The current name of this bot
69          */
70         public String name() {
71                 return name;
72         }
73
74         /**
75          * Returns the packs this bot carries.
76          *
77          * @return The packs this bot carries
78          */
79         public Collection<Pack> packs() {
80                 return packs.values();
81         }
82
83         //
84         // MUTATORS
85         //
86
87         /**
88          * Sets the current name of this bot.
89          *
90          * @param name
91          *              The name of this bot
92          * @return This bot
93          */
94         public Bot name(String name) {
95                 this.name = name;
96                 return this;
97         }
98
99         //
100         // ACTIONS
101         //
102
103         /**
104          * Adds the given pack to this bot.
105          *
106          * @param pack
107          *              The pack to add
108          */
109         public void addPack(Pack pack) {
110                 packs.put(pack.id(), pack);
111         }
112
113         //
114         // OBJECT METHODS
115         //
116
117         @Override
118         public String toString() {
119                 return String.format("%s/%s", name(), network().name());
120         }
121
122 }