From e670b076e6ee090850cac96c6ee42442dc94a56f Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 13 Dec 2001 05:32:28 +0000 Subject: [PATCH] Made toString() extendable. Oh God, how I wish I had multiple inheritance and could just fold in a Stringable class instead of rewriting the same code thousands of times. Three cheers for code reuse! git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@766 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/server/PresentsClient.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index d82246ecd..258e3174b 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -1,5 +1,5 @@ // -// $Id: PresentsClient.java,v 1.26 2001/12/03 22:01:57 mdb Exp $ +// $Id: PresentsClient.java,v 1.27 2001/12/13 05:32:28 mdb Exp $ package com.threerings.presents.server; @@ -484,10 +484,25 @@ public class PresentsClient } } + /** + * Generates a string representation of this instance. + */ public String toString () { - return "[username=" + _username + ", conn=" + _conn + - ", cloid=" + ((_clobj == null) ? -1 : _clobj.getOid()) + "]"; + StringBuffer buf = new StringBuffer("["); + toString(buf); + return buf.append("]").toString(); + } + + /** + * Derived classes override this to augment stringification. + */ + protected void toString (StringBuffer buf) + { + buf.append("username=").append(_username); + buf.append(", conn=").append(_conn); + buf.append(", cloid=").append( + (_clobj == null) ? -1 : _clobj.getOid()); } /**