/* * @(#) ToString.java - Class for 'object-to-string' converters. * (c) 2000 Ivan Maidanski http://ivmai.chat.ru * Freeware class library sources. All rights reserved. ** * Language: Java [pure] * Tested with: JDK v1.1.6 * Last modified: 2000-12-15 23:10:00 GMT+03:00 */ /* * This software is the proprietary information of the author. ** * Permission to use, copy, and distribute this software and its * documentation for non-commercial purposes and without fee is * hereby granted provided that this copyright notice appears in all * copies. ** * This software should not be modified in any way; any found bug * should be reported to the author. ** * The author disclaims all warranties with regard to this software, * including all implied warranties of merchantability and fitness. * In no event shall the author be liable for any special, indirect * or consequential damages or any damages whatsoever resulting from * loss of use, data or profits, whether in an action of contract, * negligence or other tortuous action, arising out of or in * connection with the use or performance of this software. */ package ivmai.util; import java.io.Serializable; /** * Class for 'object-to-string' converters. ** * All 'object-to-string' converters should extend this adapter * class and override toString(Object), implementing * their own conversion rules. The converters may be used in * serializable data structures since Serializable * interface is implemented. ** * @see GComparator ** * @version 2.0 * @author Ivan Maidanski */ public class ToString implements Serializable { /** * The class version unique identifier for serialization * interoperability. ** * @since 1.1 */ private static final long serialVersionUID = 6412171811255872037L; /** * The default 'to-string' converter providing the standard Java * toString() functionality. ** * This constant field is initialized with the instantiation of * exactly this converter. ** * @see #toString(java.lang.Object) ** * @since 2.0 */ public static final ToString INSTANCE = new ToString(); /** * Constructs a new 'to-string' converter. ** * This constructor is made public to allow custom * dynamic instantiation of this class. ** * @see #INSTANCE ** * @since 1.1 */ public ToString() {} /** * The body of 'Object-to-String' converter. ** * Returns its operand as a string. If the argument is not instance * of the expected type then standard Java toString() * method for the specified argument is executed (or "null" is * returned if argument is null). This method should be * overridden in adapter subclasses to implement specific * 'to-string' conversion (instead of the standard conversion). ** * @param obj * the object to be converted (may be null). * @return * the string representation (not null) of the * specified object. * @exception OutOfMemoryError * if there is not enough memory. ** * @see #INSTANCE */ public String toString(Object obj) { String str = "null"; if (obj != null) str = obj.toString(); return str; } }