8a486b8ae0d61b1d7820a1b9236491b869a5341a
[jSite.git] / src / de / todesbaum / jsite / application / Node.java
1 /*
2  * jSite-0.7 - 
3  * Copyright (C) 2006 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.jsite.application;
21
22 /**
23  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
24  */
25 public class Node extends de.todesbaum.util.freenet.fcp2.Node {
26
27         protected String name;
28
29         /**
30          * @param hostname
31          */
32         public Node(String hostname) {
33                 this(hostname, DEFAULT_PORT);
34         }
35
36         /**
37          * @param hostname
38          * @param port
39          */
40         public Node(String hostname, int port) {
41                 this(hostname, port, "");
42         }
43
44         public Node(String hostname, int port, String name) {
45                 super(hostname, port);
46                 this.name = name;
47         }
48
49         public Node(Node node) {
50                 this(node.getHostname(), node.getPort());
51         }
52
53         public Node(Node node, String name) {
54                 this(node.getHostname(), node.getPort(), name);
55         }
56
57         /**
58          * @param name
59          *            The name to set.
60          */
61         public void setName(String name) {
62                 this.name = name;
63         }
64
65         /**
66          * @return Returns the name.
67          */
68         public String getName() {
69                 return name;
70         }
71
72         public void setHostname(String hostname) {
73                 this.hostname = hostname;
74         }
75
76         public void setPort(int port) {
77                 this.port = port;
78         }
79         
80         @Override
81         public boolean equals(Object o) {
82                 if ((o == null) || !(o instanceof Node)) {
83                         return false;
84                 }
85                 Node node = (Node) o;
86                 return name.equals(node.name) && hostname.equals(node.hostname) && (port == node.port);
87         }
88         
89         @Override
90         public int hashCode() {
91                 return name.hashCode() ^ hostname.hashCode() ^ port;
92         }
93
94         @Override
95         public String toString() {
96                 return name + " (" + hostname + ":" + port + ")";
97         }
98
99 }