X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FNode.java;h=bb61ee9d0552eaf3e6f14e1c5a1f9312a07175bd;hb=adfe0cdb33f5d1a5a371e2cc35808550c4e4ab73;hp=37664985d8ff2ff9269283060432912dba07e47c;hpb=811c8f26e0ea0f1418451acb34ddabedafdbc3b3;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/Node.java b/src/net/pterodactylus/jsite/core/Node.java index 3766498..bb61ee9 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; @@ -37,6 +55,32 @@ public class Node { private int port; /** + * 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) { + this.id = id; + } + + /** * Returns the user-given name of the node. * * @return The name of the node @@ -52,7 +96,9 @@ public class Node { * The name of the node */ public void setName(String name) { + String oldName = this.name; this.name = name; + fireIfPropertyChanged(PROPERTY_NAME, oldName, name); } /** @@ -71,7 +117,9 @@ public class Node { * The hostname of the node */ public void setHostname(String hostname) { + String oldHostname = this.hostname; this.hostname = hostname; + fireIfPropertyChanged(PROPERTY_HOSTNAME, oldHostname, hostname); } /** @@ -90,7 +138,17 @@ public class Node { * The port number of the node */ public void setPort(int port) { + int oldPort = this.port; this.port = port; + fireIfPropertyChanged(PROPERTY_PORT, oldPort, port); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")"; } }