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