838346e8d483d992dbeb4c8fd1157baedc3a0383
[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 Roden <droden@gmail.com>
24  * @version $Id$
25  */
26 public class Node extends de.todesbaum.util.freenet.fcp2.Node {
27
28         protected String name;
29
30         /**
31          * @param hostname
32          */
33         public Node(String hostname) {
34                 this(hostname, DEFAULT_PORT);
35         }
36
37         /**
38          * @param hostname
39          * @param port
40          */
41         public Node(String hostname, int port) {
42                 this(hostname, port, "");
43         }
44
45         public Node(String hostname, int port, String name) {
46                 super(hostname, port);
47                 this.name = name;
48         }
49
50         public Node(Node node) {
51                 this(node.getHostname(), node.getPort());
52         }
53
54         public Node(Node node, String name) {
55                 this(node.getHostname(), node.getPort(), name);
56         }
57
58         /**
59          * @param name
60          *            The name to set.
61          */
62         public void setName(String name) {
63                 this.name = name;
64         }
65
66         /**
67          * @return Returns the name.
68          */
69         public String getName() {
70                 return name;
71         }
72
73         public void setHostname(String hostname) {
74                 this.hostname = hostname;
75         }
76
77         public void setPort(int port) {
78                 this.port = port;
79         }
80         
81         @Override
82         public boolean equals(Object o) {
83                 if ((o == null) || !(o instanceof Node)) {
84                         return false;
85                 }
86                 Node node = (Node) o;
87                 return name.equals(node.name) && hostname.equals(node.hostname) && (port == node.port);
88         }
89         
90         @Override
91         public int hashCode() {
92                 return name.hashCode() ^ hostname.hashCode() ^ port;
93         }
94
95         @Override
96         public String toString() {
97                 return name + " (" + hostname + ":" + port + ")";
98         }
99
100 }