From 1d7faa049ad6ecc833b3c26547843183f7340e02 Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 4 Feb 2002 01:14:49 +0000 Subject: [PATCH] Added a version of fieldsToString() that takes a string buffer. git-svn-id: https://samskivert.googlecode.com/svn/trunk@560 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/StringUtil.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java index 6619adcd..76bf029a 100644 --- a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java @@ -1,5 +1,5 @@ // -// $Id: StringUtil.java,v 1.24 2002/02/03 02:11:09 mdb Exp $ +// $Id: StringUtil.java,v 1.25 2002/02/04 01:14:49 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -272,6 +272,23 @@ public class StringUtil public static String fieldsToString (Object object) { StringBuffer buf = new StringBuffer("["); + fieldsToString(buf, object); + return buf.append("]").toString(); + } + + /** + * Appends to the supplied string buffer a representation of the + * supplied object by calling {@link #toString} on the contents of its + * public fields and prefixing that by the name of the fields. For + * example: + * + *

itemId=25, itemName=Elvis, itemCoords=(14, 25) + * + *

Note: unlike the version of this method that returns a string, + * enclosing brackets are not included in the output of this method. + */ + public static void fieldsToString (StringBuffer buf, Object object) + { Class clazz = object.getClass(); Field[] fields = clazz.getFields(); @@ -294,8 +311,6 @@ public class StringUtil buf.append(""); } } - - return buf.append("]").toString(); } /**