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)
 
Constructor Summary
Stringify()
           
 
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
 

Field Detail

printLength

public static int printLength
printLength -- How many elts of an array to print (default 3)
Constructor Detail

Stringify

public Stringify()
Method Detail

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

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-bugs@ai.mit.edu