whitespace fixups
[jSite2.git] / src / net / pterodactylus / jsite / core / Node.java
index b7bf637..3d35b47 100644 (file)
@@ -21,14 +21,15 @@ 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. 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 {
 
@@ -41,6 +42,9 @@ 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;
 
@@ -50,13 +54,39 @@ public class Node extends AbstractBean {
        /** 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.
-        * 
+        *
         * @return The name of the node
         */
        public String getName() {
@@ -65,7 +95,7 @@ public class Node extends AbstractBean {
 
        /**
         * Sets the user-given name of the node.
-        * 
+        *
         * @param name
         *            The name of the node
         */
@@ -77,7 +107,7 @@ public class Node extends AbstractBean {
 
        /**
         * Returns the hostname of the node.
-        * 
+        *
         * @return The hostname of the node
         */
        public String getHostname() {
@@ -86,7 +116,7 @@ public class Node extends AbstractBean {
 
        /**
         * Sets the hostname of the node.
-        * 
+        *
         * @param hostname
         *            The hostname of the node
         */
@@ -98,7 +128,7 @@ public class Node extends AbstractBean {
 
        /**
         * Returns the port number of the node.
-        * 
+        *
         * @return The port number of the node
         */
        public int getPort() {
@@ -107,7 +137,7 @@ public class Node extends AbstractBean {
 
        /**
         * Sets the port number of the node.
-        * 
+        *
         * @param port
         *            The port number of the node
         */
@@ -122,7 +152,7 @@ public class Node extends AbstractBean {
         */
        @Override
        public String toString() {
-               return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")";
+               return getClass().getName() + "[name=" + name + ",hostname=" + hostname + ",port=" + port + "]";
        }
 
 }