Added ArrayUtil.safeToString(), which encapsulates the logic to check if it's an array.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2970 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray.j.greenwell
2010-12-15 01:57:47 +00:00
parent 059d557ec9
commit cb82f080d6
3 changed files with 11 additions and 8 deletions
@@ -908,7 +908,15 @@ public class ArrayUtil
}
/**
* Return the String representation of the specified Object, which must be an array.
* Return the String representation of the specified Object, which may or may not be an array.
*/
public static String safeToString (Object o)
{
return ((o == null) || !o.getClass().isArray()) ? String.valueOf(o) : toString(o);
}
/**
* Return the String representation of the specified Object, which <em>must</em> be an array.
*
* @throws IllegalArgumentException if array is not actually an array.
*/
@@ -63,9 +63,7 @@ public class LogBuilder
}
_log.append(args[ii]).append('=');
try {
Object arg = args[ii + 1];
_log.append(((arg == null) || !arg.getClass().isArray())
? arg : ArrayUtil.toString(arg));
_log.append(ArrayUtil.safeToString(args[ii + 1]));
} catch (Throwable t) {
_log.append("<toString() failure: ").append(t).append('>');
}
@@ -157,10 +157,7 @@ public abstract class Logger
}
buf.append(args[ii]).append('=');
try {
Object arg = args[ii + 1];
buf.append(((arg == null) || !arg.getClass().isArray())
? arg
: ArrayUtil.toString(arg));
buf.append(ArrayUtil.safeToString(args[ii + 1]));
} catch (Throwable t) {
buf.append("<toString() failure: ").append(t).append(">");
}