From: David ‘Bombe’ Roden Date: Wed, 18 Apr 2012 10:26:25 +0000 (+0200) Subject: Override some Object methods. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;ds=inline;h=cd92c6320951a4f38f0ee9d604cc23ec89fd4680;p=demoscenemusic.git Override some Object methods. --- 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;