J avolution v5.3 (J2SE 1.5+)

javolution.text
Class TextFormat<T>

java.lang.Object
  extended by javolution.text.TextFormat<T>

public abstract class TextFormat<T>
extends java.lang.Object

This class represents the base format for text parsing and formatting; it supports the CharSequence and Appendable interfaces for greater flexibility.

It is possible to retrieve the format for any class for which the format has been registered (typically during class initialization). For example:

     public class Complex extends RealtimeObject {
         private static final TextFormat<Complex> CARTESIAN = ...;
         static { // Sets default format to cartesian, users may locally change it later (see after).
             TextFormat.setInstance(Complex.class, CARTESIAN);
         }
         public Complex valueOf(CharSequence csq) {
             return TextFormat.getInstance(Complex.class).parse(csq);
         }
         public Text toText() {
             return TextFormat.getInstance(Complex.class).format(this);
         }
     }
     TextFormat<Complex> polar = ...;
     LocalContext.enter();
     try {
         TextFormat.setInstance(Complex.class, polar);
         Vector<Complex> vector ...
         System.out.println(vect); // Current thread displays the complex vector in polar coordinates.
     } finally {
         LocalContext.exit(); // Revert to default cartesian representation for complex numbers.
     }
 

The following standard types have a default TextFormat representation: