X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FNode.java;h=3d35b4727189f31fd7ed94e06423880ea5725fba;hb=c63257e8cc0ba1a5aca9364b22171abe7279d479;hp=e0d61f7a9adedf273fc384e6dd82eb9e1fd62519;hpb=3189829661d3411ba3f79b1199ee5fab5c75aae5;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/Node.java b/src/net/pterodactylus/jsite/core/Node.java index e0d61f7..3d35b47 100644 --- a/src/net/pterodactylus/jsite/core/Node.java +++ b/src/net/pterodactylus/jsite/core/Node.java @@ -19,13 +19,31 @@ package net.pterodactylus.jsite.core; +import java.beans.PropertyChangeListener; + +import net.pterodactylus.jsite.util.IdGenerator; +import net.pterodactylus.util.beans.AbstractBean; +import net.pterodactylus.util.number.Hex; + /** - * Container for a Freenet node. - * + * 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 { +public class Node extends AbstractBean { + + /** Name of the “name” property. */ + public static final String PROPERTY_NAME = "name"; + + /** Name of the “hostname” property. */ + public static final String PROPERTY_HOSTNAME = "hostname"; + + /** 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; @@ -36,12 +54,39 @@ public class Node { /** The port number of the node. */ private int port; - /** Whether the node is running on the same machine as jSite. */ - private boolean sameMachine; + /** + * 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. - * + * * @return The name of the node */ public String getName() { @@ -50,17 +95,19 @@ public class Node { /** * Sets the user-given name of the node. - * + * * @param name * The name of the node */ public void setName(String name) { + String oldName = this.name; this.name = name; + fireIfPropertyChanged(PROPERTY_NAME, oldName, name); } /** * Returns the hostname of the node. - * + * * @return The hostname of the node */ public String getHostname() { @@ -69,17 +116,19 @@ public class Node { /** * Sets the hostname of the node. - * + * * @param hostname * The hostname of the node */ public void setHostname(String hostname) { + String oldHostname = this.hostname; this.hostname = hostname; + fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname); } /** * Returns the port number of the node. - * + * * @return The port number of the node */ public int getPort() { @@ -88,33 +137,22 @@ public class Node { /** * Sets the port number of the node. - * + * * @param port * The port number of the node */ public void setPort(int port) { + int oldPort = this.port; this.port = port; + fireIfPropertyChanged(PROPERTY_PORT, oldPort, port); } /** - * Returns whether this node is running on the same machine as jSite. - * - * @return the sameMachine true if, and only if, the node is - * running on the same machine as jSite - */ - boolean isSameMachine() { - return sameMachine; - } - - /** - * Sets whether this node is running on the same machine as jSite. - * - * @param sameMachine - * true if the node is running on the same machine - * as jSite, false otherwise + * {@inheritDoc} */ - void setSameMachine(boolean sameMachine) { - this.sameMachine = sameMachine; + @Override + public String toString() { + return getClass().getName() + "[name=" + name + ",hostname=" + hostname + ",port=" + port + "]"; } }