From cd92c6320951a4f38f0ee9d604cc23ec89fd4680 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 18 Apr 2012 12:26:25 +0200 Subject: [PATCH] Override some Object methods. --- .../demoscenemusic/data/AbstractBase.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/AbstractBase.java b/src/main/java/net/pterodactylus/demoscenemusic/data/AbstractBase.java index 84c9da0..ad5cfd8 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/AbstractBase.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/AbstractBase.java @@ -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> attributeEntry : attributes.entrySet()) { + stringBuilder.append(',').append(attributeEntry.getKey()).append('=').append(attributeEntry.getValue().get()); + } + stringBuilder.append(']'); + return stringBuilder.toString(); + } + protected static class Value { private T original; -- 2.7.4