2 * XdccDownloader - Channel.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 static java.lang.String.format;
22 import com.google.common.base.Function;
25 * Defines a channel in a {@link Network}.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class Channel {
31 /** Function to convert a channel to its network. */
32 public static final Function<Channel, Network> TO_NETWORK = new Function<Channel, Network>() {
34 public Network apply(Channel channel) {
35 return channel.network();
39 /** The network this channel belongs to. */
40 private final Network network;
42 /** The name of the channel. */
43 private final String name;
46 * Creates a new channel.
49 * The network the channel belongs to
51 * The name of the channel
53 public Channel(Network network, String name) {
54 this.network = network;
63 * Returns the network this channel belongs to
65 * @return The network this channel belongs to
67 public Network network() {
72 * Returns the name of this channel.
74 * @return The name of this channel
76 public String name() {
85 public boolean equals(Object object) {
86 if (!(object instanceof Channel)) {
89 Channel channel = (Channel) object;
90 if (!network().equals(channel.network())) {
93 if (!name().equalsIgnoreCase(channel.name())) {
100 public int hashCode() {
101 return network().hashCode() ^ name().hashCode();
105 public String toString() {
106 return format("%s/%s", name(), network().name());