Make channels work correctly in maps and sets.
[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 /**
21  * Defines a channel in a {@link Network}.
22  *
23  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
24  */
25 public class Channel {
26
27         /** The network this channel belongs to. */
28         private final Network network;
29
30         /** The name of the channel. */
31         private final String name;
32
33         /**
34          * Creates a new channel.
35          *
36          * @param network
37          *              The network the channel belongs to
38          * @param name
39          *              The name of the channel
40          */
41         public Channel(Network network, String name) {
42                 this.network = network;
43                 this.name = name;
44         }
45
46         //
47         // ACCESSORS
48         //
49
50         /**
51          * Returns the network this channel belongs to
52          *
53          * @return The network this channel belongs to
54          */
55         public Network network() {
56                 return network;
57         }
58
59         /**
60          * Returns the name of this channel.
61          *
62          * @return The name of this channel
63          */
64         public String name() {
65                 return name;
66         }
67
68         //
69         // OBJECT METHODS
70         //
71
72         @Override
73         public boolean equals(Object object) {
74                 if (!(object instanceof Channel)) {
75                         return false;
76                 }
77                 Channel channel = (Channel) object;
78                 if (!network().equals(channel.network())) {
79                         return false;
80                 }
81                 if (!name().equalsIgnoreCase(channel.name())) {
82                         return false;
83                 }
84                 return true;
85         }
86
87         @Override
88         public int hashCode() {
89                 return network().hashCode() ^ name().hashCode();
90         }
91
92 }