add id to node
[jSite2.git] / src / net / pterodactylus / jsite / core / Node.java
1 /*
2  * jSite2 - Node.java -
3  * Copyright © 2008 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 net.pterodactylus.jsite.core;
21
22 import java.beans.PropertyChangeListener;
23
24 import net.pterodactylus.util.beans.AbstractBean;
25
26 /**
27  * Container for a Freenet node. A Node is capable of notifying
28  * {@link PropertyChangeListener}s if any of the contained properties change.
29  * 
30  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31  */
32 public class Node extends AbstractBean {
33
34         /** Name of the “name” property. */
35         public static final String PROPERTY_NAME = "name";
36
37         /** Name of the “hostname” property. */
38         public static final String PROPERTY_HOSTNAME = "hostname";
39
40         /** Name of the “port” property. */
41         public static final String PROPERTY_PORT = "port";
42
43         /** Internal ID. */
44         private String id;
45
46         /** The name of the node. */
47         private String name;
48
49         /** The hostname of the node. */
50         private String hostname;
51
52         /** The port number of the node. */
53         private int port;
54
55         /**
56          * Returns the internal ID of the node.
57          * 
58          * @return The internal ID of the node
59          */
60         String getId() {
61                 return id;
62         }
63
64         /**
65          * Sets the internal ID of the node.
66          * 
67          * @param id
68          *            The internal ID of the node
69          */
70         void setId(String id) {
71                 this.id = id;
72         }
73
74         /**
75          * Returns the user-given name of the node.
76          * 
77          * @return The name of the node
78          */
79         public String getName() {
80                 return name;
81         }
82
83         /**
84          * Sets the user-given name of the node.
85          * 
86          * @param name
87          *            The name of the node
88          */
89         public void setName(String name) {
90                 String oldName = this.name;
91                 this.name = name;
92                 fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
93         }
94
95         /**
96          * Returns the hostname of the node.
97          * 
98          * @return The hostname of the node
99          */
100         public String getHostname() {
101                 return hostname;
102         }
103
104         /**
105          * Sets the hostname of the node.
106          * 
107          * @param hostname
108          *            The hostname of the node
109          */
110         public void setHostname(String hostname) {
111                 String oldHostname = this.hostname;
112                 this.hostname = hostname;
113                 fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname);
114         }
115
116         /**
117          * Returns the port number of the node.
118          * 
119          * @return The port number of the node
120          */
121         public int getPort() {
122                 return port;
123         }
124
125         /**
126          * Sets the port number of the node.
127          * 
128          * @param port
129          *            The port number of the node
130          */
131         public void setPort(int port) {
132                 int oldPort = this.port;
133                 this.port = port;
134                 fireIfPropertyChanged(PROPERTY_PORT, oldPort, port);
135         }
136
137         /**
138          * {@inheritDoc}
139          */
140         @Override
141         public String toString() {
142                 return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")";
143         }
144
145 }