edu.mit.ai.psg.strings
Class Stringify
java.lang.Object
|
+--edu.mit.ai.psg.strings.Stringify
- public class Stringify
- extends Object
Stringify safely prints object references to strings:
catching errors, eliding long collections, etc., and
printing classes, arrays, and strings in a more recognizeable
syntax than their default toString method provides.
- Author:
- CarlManning, caroma@ai.mit.edu
Copyright (c) 1996, 1997, 1999 Massachusetts Institute of Technology
|
Field Summary |
static int |
printLength
printLength -- How many elts of an array to print (default 3) |
|
Method Summary |
static String |
addCharEscapes(char charToEscape,
String s)
AddCharEscapes: adds '\' in front of any charToEscape in s |
static String |
printToString(int printLength,
Object obj)
|
static String |
printToString(Object obj)
printToString -- safely prints object to string: prints null as
"null", adds quotes around strings, only prints up to
printLength array, java.util.Collection, java.util.Map, or java.util.Set
elements. |
static String |
removeCharEscapes(char escapedChar,
String s)
RemoveCharEscapes: removes '\' in front of any charToEscape in s |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
printLength
public static int printLength
- printLength -- How many elts of an array to print (default 3)
Stringify
public Stringify()
printToString
public static String printToString(Object obj)
- printToString -- safely prints object to string: prints null as
"null", adds quotes around strings, only prints up to
printLength array, java.util.Collection, java.util.Map, or java.util.Set
elements. Prints classes as ClassName.class, and array classes as
ComponentClass[].class. Safely calls toString() on other objects,
catching throws and returning an alternate string containing the
class of the object and the thrown exception name.
printToString
public static String printToString(int printLength,
Object obj)
addCharEscapes
public static String addCharEscapes(char charToEscape,
String s)
- AddCharEscapes: adds '\' in front of any charToEscape in s
removeCharEscapes
public static String removeCharEscapes(char escapedChar,
String s)
- RemoveCharEscapes: removes '\' in front of any charToEscape in s