From 54c809d21a814ff44afbe3af4b34440aba0bab61 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 16 Sep 2009 21:15:03 +0000 Subject: [PATCH] Use Joiner instead of StringBuilder. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@880 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../com/threerings/parlor/card/data/Card.as | 53 ++++++++++--------- src/as/com/threerings/parlor/data/Table.as | 21 +++----- .../threerings/parlor/game/data/GameObject.as | 9 ++-- .../threerings/whirled/data/SceneUpdate.as | 13 +++-- .../threerings/whirled/spot/data/Portal.as | 9 ++-- 5 files changed, 49 insertions(+), 56 deletions(-) diff --git a/src/as/com/threerings/parlor/card/data/Card.as b/src/as/com/threerings/parlor/card/data/Card.as index ac6a5ae2..246a30d1 100644 --- a/src/as/com/threerings/parlor/card/data/Card.as +++ b/src/as/com/threerings/parlor/card/data/Card.as @@ -28,7 +28,7 @@ import com.threerings.util.Byte; import com.threerings.util.Comparable; import com.threerings.util.Hashable; import com.threerings.util.Integer; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; import com.threerings.presents.dobj.DSet; import com.threerings.presents.dobj.DSet_Entry; @@ -168,30 +168,7 @@ public class Card return "BJ"; } else { - var sb : StringBuilder = new StringBuilder(); - if (number >= 2 && number <= 9) { - sb.append(number); - - } else { - switch (number) { - case 10: sb.append('T'); break; - case CardCodes.JACK: sb.append('J'); break; - case CardCodes.QUEEN: sb.append('Q'); break; - case CardCodes.KING: sb.append('K'); break; - case CardCodes.ACE: sb.append('A'); break; - default: sb.append('?'); break; - } - } - - switch (getSuit()) { - case CardCodes.SPADES: sb.append('s'); break; - case CardCodes.HEARTS: sb.append('h'); break; - case CardCodes.CLUBS: sb.append('c'); break; - case CardCodes.DIAMONDS: sb.append('d'); break; - default: sb.append('?'); break; - } - - return sb.toString(); + return rankToString(number) + suitToString(getSuit()); } } @@ -239,6 +216,32 @@ public class Card out.writeByte(_value); } + protected function rankToString (rank :int) :String + { + if (rank >= 2 && rank <= 9) { + return String(rank); + } + switch (rank) { + case 10: return "T"; + case CardCodes.JACK: return "J"; + case CardCodes.QUEEN: return "Q"; + case CardCodes.KING: return "K"; + case CardCodes.ACE: return "A"; + } + return "?"; + } + + protected function suitToString (suit :int) :String + { + switch (suit) { + case CardCodes.SPADES: return "s"; + case CardCodes.HEARTS: return "h"; + case CardCodes.CLUBS: return "c"; + case CardCodes.DIAMONDS: return "d"; + } + return "?"; + } + /** The number of the card. */ protected var _value :int; } diff --git a/src/as/com/threerings/parlor/data/Table.as b/src/as/com/threerings/parlor/data/Table.as index 349d4ba8..a447c94e 100644 --- a/src/as/com/threerings/parlor/data/Table.as +++ b/src/as/com/threerings/parlor/data/Table.as @@ -24,8 +24,8 @@ package com.threerings.parlor.data { import com.threerings.util.ArrayUtil; import com.threerings.util.ClassUtil; import com.threerings.util.Hashable; +import com.threerings.util.Joiner; import com.threerings.util.Name; -import com.threerings.util.StringBuilder; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -218,12 +218,9 @@ public class Table */ public function toString () :String { - var buf :StringBuilder = new StringBuilder(); - buf.append(ClassUtil.shortClassName(this)); - buf.append(" ["); - toStringBuilder(buf); - buf.append("]"); - return buf.toString(); + var j :Joiner = Joiner.createFor(this); + toStringJoiner(j); + return j.toString(); } // documentation inherited @@ -259,14 +256,10 @@ public class Table /** * Helper method for toString, ripe for overrideability. */ - protected function toStringBuilder (buf :StringBuilder) :void + protected function toStringJoiner (j :Joiner) :void { - buf.append("tableId=").append(tableId); - buf.append(", lobbyOid=").append(lobbyOid); - buf.append(", gameOid=").append(gameOid); - buf.append(", players=").append(players == null ? "" : players.join()); - buf.append(", watchers=").append(watchers == null ? "" : watchers.join()); - buf.append(", config=").append(config); + j.add("tableId", tableId, "lobbyOid", lobbyOid, "gameOid", gameOid, + "players", players, "watchers", watchers, "config", config); } /** A counter for assigning table ids. */ diff --git a/src/as/com/threerings/parlor/game/data/GameObject.as b/src/as/com/threerings/parlor/game/data/GameObject.as index 1f949478..ae969b57 100644 --- a/src/as/com/threerings/parlor/game/data/GameObject.as +++ b/src/as/com/threerings/parlor/game/data/GameObject.as @@ -23,9 +23,9 @@ package com.threerings.parlor.game.data { import com.threerings.util.ArrayUtil; import com.threerings.util.Integer; +import com.threerings.util.Joiner; import com.threerings.util.langBoolean; import com.threerings.util.Name; -import com.threerings.util.StringBuilder; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -230,11 +230,10 @@ public class GameObject extends PlaceObject return playerStatus == PLAYER_IN_PLAY; } - override protected function whichBuf (buf :StringBuilder) :void + override protected function whichJoiner (j :Joiner) :void { - super.whichBuf(buf); - buf.append("(").append(players.join()).append(")"); - buf.append(":").append(state); + super.whichJoiner(j); + j.addArgs("(" + players.join() + ")", state); } // // AUTO-GENERATED: METHODS START diff --git a/src/as/com/threerings/whirled/data/SceneUpdate.as b/src/as/com/threerings/whirled/data/SceneUpdate.as index aba914a3..dbcd6f0e 100644 --- a/src/as/com/threerings/whirled/data/SceneUpdate.as +++ b/src/as/com/threerings/whirled/data/SceneUpdate.as @@ -23,7 +23,7 @@ package com.threerings.whirled.data { import flash.errors.IllegalOperationError; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -83,9 +83,9 @@ public class SceneUpdate */ public function toString () :String { - var buf :StringBuilder = new StringBuilder("["); - toStringBuilder(buf); - return buf.append("]").toString(); + var j :Joiner = Joiner.createFor(this); + toStringJoiner(j); + return j.toString(); } /** @@ -149,10 +149,9 @@ public class SceneUpdate * An extensible mechanism for generating a string representation of * this instance. */ - protected function toStringBuilder (buf :StringBuilder) :void + protected function toStringJoiner (j :Joiner) :void { - buf.append("sceneId=").append(_targetId); - buf.append(", version=").append(_targetVersion); + j.add("sceneId", _targetId, "version", _targetVersion); } /** The version number of the scene on which we operate. */ diff --git a/src/as/com/threerings/whirled/spot/data/Portal.as b/src/as/com/threerings/whirled/spot/data/Portal.as index 95ba9fa7..266b76d2 100644 --- a/src/as/com/threerings/whirled/spot/data/Portal.as +++ b/src/as/com/threerings/whirled/spot/data/Portal.as @@ -24,7 +24,7 @@ package com.threerings.whirled.spot.data { import com.threerings.util.ClassUtil; import com.threerings.util.Cloneable; import com.threerings.util.Hashable; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -143,11 +143,10 @@ public class Portal extends SimpleStreamableObject } // from SimpleStreamableObject - override protected function toStringBuilder (buf :StringBuilder): void + override protected function toStringJoiner (j :Joiner): void { - buf.append("id=").append(portalId); - buf.append(", destScene=").append(targetSceneId); - buf.append(", loc=").append(loc); + // no super + j.add("id", portalId, "destScene", targetSceneId, "loc", loc); } } }