/*
 * @(#) ToString.java - Class for 'object-to-string' converters.
 * (c) 2000 Ivan Maidanski <ivmai@chat.ru> 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 <CODE>toString(Object)</CODE>, implementing
 * their own conversion rules. The converters may be used in
 * serializable data structures since <CODE>Serializable</CODE>
 * 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
 * <CODE>toString()</CODE> 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 <CODE>public</CODE> 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 <CODE>toString()</CODE>
 * method for the specified argument is executed (or "null" is
 * returned if argument is <CODE>null</CODE>). 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 <CODE>null</CODE>).
 * @return
 * the string representation (not <CODE>null</CODE>) 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;
 }
}
