Override some Object methods.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 18 Apr 2012 10:26:25 +0000 (12:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 18 Apr 2012 10:26:25 +0000 (12:26 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/AbstractBase.java

index 84c9da0..ad5cfd8 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.demoscenemusic.data;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * TODO
@@ -56,6 +57,44 @@ public abstract class AbstractBase implements Base {
                return false;
        }
 
+       //
+       // OBJECT METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public int hashCode() {
+               return id().hashCode();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean equals(Object obj) {
+               if (!(obj instanceof Base)) {
+                       return false;
+               }
+               return id().equals(((Base) obj).id());
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public String toString() {
+               StringBuilder stringBuilder = new StringBuilder();
+               stringBuilder.append(getClass().getName());
+               stringBuilder.append('[').append("id=").append(id());
+               for (Entry<String, Value<?>> attributeEntry : attributes.entrySet()) {
+                       stringBuilder.append(',').append(attributeEntry.getKey()).append('=').append(attributeEntry.getValue().get());
+               }
+               stringBuilder.append(']');
+               return stringBuilder.toString();
+       }
+
        protected static class Value<T> {
 
                private T original;