Whole document tree
java.text
|
Constructor Summary | |
Format()
|
Method Summary | |
Object |
clone()
Overrides Cloneable |
String |
format(Object obj)
Formats an object to produce a string. |
abstract StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
Formats an object to produce a string. |
Object |
parseObject(String source)
Parses a string to produce an object. |
abstract Object |
parseObject(String source,
ParsePosition status)
Parses a string to produce an object. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Format()
Method Detail |
public final String format(Object obj)
Subclasses will override the StringBuffer version of format.
obj
- The object to formatIllegalArgumentException
- when the Format cannot format the
type of object.MessageFormat
,
format(Object, StringBuffer, FieldPosition)
public abstract StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
StringBuffer format (Number obj, StringBuffer toAppendTo) Number parse (String str)These general routines allow polymorphic parsing and formatting for objects such as the MessageFormat.
obj
- The object to formattoAppendTo
- where the text is to be appendedpos
- On input: an alignment field, if desired.
On output: the offsets of the alignment field.IllegalArgumentException
- when the Format cannot format the
given object.MessageFormat
,
FieldPosition
public abstract Object parseObject(String source, ParsePosition status)
String format (Number obj); String format (long obj); String format (double obj); Number parse (String str);
status
- Input-Output parameter.
Before calling, set status.index to the offset you want to start parsing at in the source. After calling, status.index is the end of the text you parsed. If error occurs, index is unchanged.
When parsing, leading whitespace is discarded (with successful parse), while trailing whitespace is left as is.
Example: Parsing "_12_xy" (where _ represents a space) for a number, with index == 0 will result in the number 12, with status.index updated to 3 (just before the second space). Parsing a second time will result in a ParseException since "xy" is not a number, and leave index at 3.
Subclasses will typically supply specific parse methods that return different types of values. Since methods can't overload on return types, these will typically be named "parse", while this polymorphic method will always be called parseObject. Any parse method that does not take a status should throw ParseException when no text in the required format is at the start position.
ParsePosition
public Object parseObject(String source) throws ParseException
ParseException
- if the specified string is invalid.public Object clone()
java.lang.Object
CloneNotSupportedException
- if the object's class does not
support the Cloneable
interface. Subclasses
that override the clone
method can also
throw this exception to indicate that an instance cannot
be cloned.OutOfMemoryError
- if there is not enough memory.Cloneable
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.