From 4280391d037108cd3fd7bd51ace953dbea3b7559 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 20 Oct 2007 18:48:06 +0000 Subject: [PATCH] Implemented hashCode() and equals() as it could come in handy if we want to stick objects in a collection. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4852 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/presents/dobj/DObject.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/presents/dobj/DObject.java b/src/java/com/threerings/presents/dobj/DObject.java index b8a46f5ee..95b6c4f9b 100644 --- a/src/java/com/threerings/presents/dobj/DObject.java +++ b/src/java/com/threerings/presents/dobj/DObject.java @@ -592,6 +592,31 @@ public class DObject return buf.toString(); } + @Override // from Object + public String toString () + { + StringBuilder buf = new StringBuilder(); + toString(buf); + return buf.append("]").toString(); + } + + @Override // from Object + public int hashCode () + { + return _oid; + } + + @Override // from Object + public boolean equals (Object other) + { + if (other == null) { + return false; + } else if (!getClass().equals(other.getClass())) { + return false; + } + return _oid == ((DObject)other).getOid(); + } + /** * Used to briefly describe this distributed object. */ @@ -601,16 +626,6 @@ public class DObject buf.append(":").append(_oid); } - /** - * Generates a string representation of this object. - */ - public String toString () - { - StringBuilder buf = new StringBuilder(); - toString(buf); - return buf.append("]").toString(); - } - /** * Generates a string representation of this object. */