This abstract
class is the base class for all
number,
date, and string formatting classes in the
java.text package. It defines the key formatting
and parsing methods that are implemented by all subclasses.
format( ) converts
an object to a string using the formatting rules encapsulated by the
Format subclass and optionally appends the
resulting string to an existing StringBuffer.
parseObject( ) performs the reverse operation; it parses a
formatted string and returns the corresponding object. Status
information for these two operations is returned in
FieldPosition and ParsePosition
objects.
Java 1.4 defined a variant on the format( )
method. formatToCharacterIterator(
) performs the same formating operation as
format( ) but returns the result as an
AtttributedCharacterIterator which uses attributes
to identify the various parts (such the integer part, the decimal
separtator, and the fractional part of a formatted number) of the
formatted string. The attribute keys are all instances of the
Format.Field inner class. Each of the
Format subclasses define a
Field subclass that defines a set of
Field constants, (such as
NumberFormat.Field.DECIMAL_SEPARATOR) for use by
the character iterator returned by this method. See
ChoiceFormat, DateFormat,
MessageFormat, and NumberFormat
for subclasses that perform specific types of formatting.
Figure 15-11. java.text.Format
public abstract class
Format implements Cloneable, Serializable {
// Public Constructors
public
Format ( );
// Nested Types
1.4 public static class
Field extends AttributedCharacterIterator.Attribute;
// Public Instance Methods
public final String
format (Object
obj );
public abstract StringBuffer
format (Object
obj , StringBuffer
toAppendTo ,
FieldPosition
pos );
1.4 public AttributedCharacterIterator
formatToCharacterIterator (Object
obj );
public Object
parseObject (String
source ) throws ParseException;
public abstract Object
parseObject (String
source , ParsePosition
pos );
// Public Methods Overriding Object
public Object
clone ( );
}
MessageFormat.{setFormat( ),
setFormatByArgumentIndex( ), setFormats(
), setFormatsByArgumentIndex( )}