remove Id keyword
[jSite2.git] / src / net / pterodactylus / jsite / core / Node.java
index b3a98e9..183a916 100644 (file)
 
 package net.pterodactylus.jsite.core;
 
+import java.beans.PropertyChangeListener;
+
+import net.pterodactylus.util.beans.AbstractBean;
+
 /**
- * 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";
 
        /** The name of the node. */
        private String name;
@@ -36,9 +49,13 @@ public class Node {
        /** The port number of the node. */
        private int port;
 
+       //
+       // EVENT MANAGEMENT
+       //
+
        /**
         * Returns the user-given name of the node.
-        *
+        * 
         * @return The name of the node
         */
        public String getName() {
@@ -47,17 +64,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() {
@@ -66,17 +85,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() {
@@ -85,25 +106,14 @@ 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;
-       }
-
-       /**
-        * {@inheritDoc} Two Node objects are considered equal if their hostnames
-        * and their port numbers are equal.
-        */
-       @Override
-       public boolean equals(Object object) {
-               if ((object == null) || !(object instanceof Node)) {
-                       return false;
-               }
-               Node node = (Node) object;
-               return hostname.equals(node.hostname) && port == node.port;
+               fireIfPropertyChanged(PROPERTY_PORT, oldPort, port);
        }
 
        /**