add javadoc
[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  * Container for node information.
24  * 
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  */
27 public class Node extends de.todesbaum.util.freenet.fcp2.Node {
28
29         /** The name of the node. */
30         protected String name;
31
32         /**
33          * Creates a new node with the given hostname and the default port.
34          * 
35          * @see de.todesbaum.util.freenet.fcp2.Node#DEFAULT_PORT
36          * @param hostname
37          *            The hostname of the new node
38          */
39         public Node(String hostname) {
40                 this(hostname, DEFAULT_PORT);
41         }
42
43         /**
44          * Creates a new node with the given hostname and port.
45          * 
46          * @param hostname
47          *            The hostname of the new node
48          * @param port
49          *            The port of the new node
50          */
51         public Node(String hostname, int port) {
52                 this(hostname, port, "");
53         }
54
55         /**
56          * Creates a new node with the given hostname, port, and name.
57          * 
58          * @param hostname
59          *            The hostname of the new node
60          * @param port
61          *            The port of the new node
62          * @param name
63          *            The name of the node
64          */
65         public Node(String hostname, int port, String name) {
66                 super(hostname, port);
67                 this.name = name;
68         }
69
70         /**
71          * Creates a new node that gets its settings from the given node.
72          * 
73          * @param node
74          *            The node to copy
75          */
76         public Node(Node node) {
77                 this(node.getHostname(), node.getPort());
78         }
79
80         /**
81          * Creates a new node from the given node, overwriting the name.
82          * 
83          * @param node
84          *            The node to copy from
85          * @param name
86          *            The new name of the node
87          */
88         public Node(Node node, String name) {
89                 this(node.getHostname(), node.getPort(), name);
90         }
91
92         /**
93          * Sets the name of the node.
94          * 
95          * @param name
96          *            The name of the node
97          */
98         public void setName(String name) {
99                 this.name = name;
100         }
101
102         /**
103          * Returns the name of the node.
104          * 
105          * @return The name of the node
106          */
107         public String getName() {
108                 return name;
109         }
110
111         /**
112          * Sets the hostname of the node.
113          * 
114          * @param hostname
115          *            The hostname of the node
116          */
117         public void setHostname(String hostname) {
118                 this.hostname = hostname;
119         }
120
121         /**
122          * Sets the port of the node.
123          * 
124          * @param port
125          *            The port of the node
126          */
127         public void setPort(int port) {
128                 this.port = port;
129         }
130
131         /**
132          * {@inheritDoc}
133          * <p>
134          * A node is considered as being equal to this node its name, hostname, and
135          * port equal their counterparts in this node.
136          */
137         @Override
138         public boolean equals(Object o) {
139                 if ((o == null) || !(o instanceof Node)) {
140                         return false;
141                 }
142                 Node node = (Node) o;
143                 return name.equals(node.name) && hostname.equals(node.hostname) && (port == node.port);
144         }
145
146         /**
147          * {@inheritDoc}
148          * <p>
149          * The hashcode for a node is created from its name, its hostname, and its
150          * port.
151          */
152         @Override
153         public int hashCode() {
154                 return name.hashCode() ^ hostname.hashCode() ^ port;
155         }
156
157         /**
158          * {@inheritDoc}
159          * <p>
160          * Creates a textual representation of this node.
161          */
162         @Override
163         public String toString() {
164                 return name + " (" + hostname + ":" + port + ")";
165         }
166
167 }