|
Chapter 16 The java.text Package |
|
Format
Name
Format
- Class Name:
-
java.text.Format
- Superclass:
-
java.lang.Object
- Immediate Subclasses:
-
java.text.DateFormat,
java.text.MessageFormat,
java.text.NumberFormat
- Interfaces Implemented:
-
java.lang.Cloneable,
java.io.Serializable
- Availability:
-
New as of JDK 1.1
The Format class is an abstract
class that is the superclass of all classes that handle locale-sensitive
parsing and formatting of dates, numbers, and messages. The two format()
methods take the information in a supplied object and convert it to a string.
The two parseObject() methods
do the reverse; they take the information from a string and construct an
appropriate object.
public abstract class java.text.Format extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable {
// Instance Methods
public Object clone();
public final String format(Object obj);
public abstract StringBuffer format(Object obj, StringBuffer toAppendTo,
FieldPosition pos);
public Object parseObject(String source);
public abstract Object parseObject(String source, ParsePosition status);
}
- Returns
-
A copy of this Format.
- Overrides
-
Object.clone()
- Description
-
This method creates a copy of this Format
and returns it.
- Parameters
-
- obj
-
The object to be formatted.
- Returns
-
A string that contains a formatted representation of the object.
- Throws
-
- IllegalArgumentException
-
If the given object cannot be formatted.
- Description
-
This method formats the given object by calling format(Object,
StringBuffer, FieldPosition)
with an empty StringBuffer
and a FieldPosition that has
a value of 0.
- Parameters
-
- obj
-
The object to be formatted.
- toAppendTo
-
A StringBuffer
on which to append the formatted information.
- pos
-
A field.
- Returns
-
The given buffer toAppendTo
with the formatted representation of the object appended to it.
- Throws
-
- IllegalArgumentException
-
If the given object cannot be formatted.
- Description
-
This method formats the given object and appends the result to the
given StringBuffer. After the object has been
formatted, the beginning and ending indices of the given
FieldPosition are updated to reflect the
field's position in the formatted output.
A subclass of Format must implement
this method.
- Parameters
-
- source
-
The string to be parsed.
- Returns
-
The object represented by the given string.
- Throws
-
- ParseException
-
If the text cannot be parsed by this Format.
- Description
-
This method parses the given text and returns an appropriate object. It
does this by calling parseObject(String,
ParsePosition) with a ParsePosition
that has an index of 0.
- Parameters
-
- source
-
The string to be parsed.
- status
-
A ParsePosition
object that specifies a position in the string.
- Returns
-
The object represented by the text starting at the given position.
- Description
-
This method parses the given text, starting at the specified position,
and returns an object created from the data. After the string has been
parsed, the given ParsePosition
object is updated so that its index is after the parsed text.
A subclass of Format must implement
this method.
DateFormat,
FieldPosition,
MessageFormat,
NumberFormat,
ParseException,
ParsePosition,
String,
StringBuffer
|
|