2 * jSite - Node.java - Copyright © 2006–2019 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 2 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, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.application;
22 * Container for node information.
24 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26 public class Node extends de.todesbaum.util.freenet.fcp2.Node {
28 /** The name of the node. */
29 protected String name;
32 * Creates a new node with the given hostname and the default port.
34 * @see de.todesbaum.util.freenet.fcp2.Node#DEFAULT_PORT
36 * The hostname of the new node
38 public Node(String hostname) {
39 this(hostname, DEFAULT_PORT);
43 * Creates a new node with the given hostname and port.
46 * The hostname of the new node
48 * The port of the new node
50 public Node(String hostname, int port) {
51 this(hostname, port, "");
55 * Creates a new node with the given hostname, port, and name.
58 * The hostname of the new node
60 * The port of the new node
62 * The name of the node
64 public Node(String hostname, int port, String name) {
65 super(hostname, port);
70 * Creates a new node that gets its settings from the given node.
75 public Node(Node node) {
76 this(node.getHostname(), node.getPort());
80 * Creates a new node from the given node, overwriting the name.
83 * The node to copy from
85 * The new name of the node
87 public Node(Node node, String name) {
88 this(node.getHostname(), node.getPort(), name);
92 * Sets the name of the node.
95 * The name of the node
97 public void setName(String name) {
102 * Returns the name of the node.
104 * @return The name of the node
106 public String getName() {
111 * Sets the hostname of the node.
114 * The hostname of the node
116 public void setHostname(String hostname) {
117 this.hostname = hostname;
121 * Sets the port of the node.
124 * The port of the node
126 public void setPort(int port) {
133 * A node is considered as being equal to this node its name, hostname, and
134 * port equal their counterparts in this node.
137 public boolean equals(Object o) {
138 if ((o == null) || !(o instanceof Node)) {
141 Node node = (Node) o;
142 return name.equals(node.name) && hostname.equals(node.hostname) && (port == node.port);
148 * The hashcode for a node is created from its name, its hostname, and its
152 public int hashCode() {
153 return name.hashCode() ^ hostname.hashCode() ^ port;
159 * Creates a textual representation of this node.
162 public String toString() {
163 return name + " (" + hostname + ":" + port + ")";