🚧 Parse token from DCC SEND
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Channel.java
1 /*
2  * XdccDownloader - Channel.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 static java.lang.String.format;
21
22 import com.google.common.base.Function;
23
24 /**
25  * Defines a channel in a {@link Network}.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
28  */
29 public class Channel {
30
31         /** The network this channel belongs to. */
32         private final Network network;
33
34         /** The name of the channel. */
35         private final String name;
36
37         /**
38          * Creates a new channel.
39          *
40          * @param network
41          *              The network the channel belongs to
42          * @param name
43          *              The name of the channel
44          */
45         public Channel(Network network, String name) {
46                 this.network = network;
47                 this.name = name;
48         }
49
50         //
51         // ACCESSORS
52         //
53
54         /**
55          * Returns the network this channel belongs to
56          *
57          * @return The network this channel belongs to
58          */
59         public Network network() {
60                 return network;
61         }
62
63         /**
64          * Returns the name of this channel.
65          *
66          * @return The name of this channel
67          */
68         public String name() {
69                 return name;
70         }
71
72         //
73         // OBJECT METHODS
74         //
75
76         @Override
77         public boolean equals(Object object) {
78                 if (!(object instanceof Channel)) {
79                         return false;
80                 }
81                 Channel channel = (Channel) object;
82                 if (!network().equals(channel.network())) {
83                         return false;
84                 }
85                 if (!name().equalsIgnoreCase(channel.name())) {
86                         return false;
87                 }
88                 return true;
89         }
90
91         @Override
92         public int hashCode() {
93                 return network().hashCode() ^ name().hashCode();
94         }
95
96         @Override
97         public String toString() {
98                 return format("%s/%s", name(), network().name());
99         }
100
101 }