import java.beans.PropertyChangeListener;
+import net.pterodactylus.jsite.util.IdGenerator;
import net.pterodactylus.util.beans.AbstractBean;
-import net.pterodactylus.util.beans.Comparer;
+import net.pterodactylus.util.number.Hex;
/**
* Container for a Freenet node. A Node is capable of notifying
* {@link PropertyChangeListener}s if any of the contained properties change.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
public class Node extends AbstractBean {
/** Name of the “port” property. */
public static final String PROPERTY_PORT = "port";
+ /** Internal ID. */
+ private String id;
+
/** The name of the node. */
private String name;
/** The port number of the node. */
private int port;
- //
- // EVENT MANAGEMENT
- //
+ /**
+ * Creates a new node.
+ */
+ public Node() {
+ id = Hex.toHex(IdGenerator.generateId());
+ }
+
+ /**
+ * Returns the internal ID of the node.
+ *
+ * @return The internal ID of the node
+ */
+ String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the internal ID of the node.
+ *
+ * @param id
+ * The internal ID of the node
+ */
+ void setId(String id) {
+ if (id == null) {
+ this.id = Hex.toHex(IdGenerator.generateId());
+ } else {
+ this.id = id;
+ }
+ }
/**
* Returns the user-given name of the node.
public void setName(String name) {
String oldName = this.name;
this.name = name;
- if (!Comparer.equal(oldName, name)) {
- firePropertyChange(PROPERTY_NAME, oldName, name);
- }
+ fireIfPropertyChanged(PROPERTY_NAME, oldName, name);
}
/**
public void setHostname(String hostname) {
String oldHostname = this.hostname;
this.hostname = hostname;
- if (!Comparer.equal(oldHostname, hostname)) {
- firePropertyChange(PROPERTY_HOSTNAME, oldHostname, hostname);
- }
+ fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname);
}
/**
public void setPort(int port) {
int oldPort = this.port;
this.port = port;
- if (oldPort != port) {
- firePropertyChange(PROPERTY_PORT, oldPort, port);
- }
+ fireIfPropertyChanged(PROPERTY_PORT, oldPort, port);
}
/**
*/
@Override
public String toString() {
- return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")";
+ return getClass().getName() + "[name=" + name + ",hostname=" + hostname + ",port=" + port + "]";
}
}