Class Format

java.lang.Object
java.text.Format
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
DateFormat, MessageFormat, NumberFormat

public abstract class Format extends Object implements Cloneable, Serializable

The base of the formats that turn locale sensitive values into text and back: DateFormat, NumberFormat and MessageFormat.

A subclass implements format(Object, StringBuffer, FieldPosition) and parseObject(String, ParsePosition); the one-argument forms are written over them, as in the JDK.

Differences from the JDK
  • No clone here: Object.clone() answers null on the device for anything but an array, so every format of this package declares a clone that copies its own fields.
  • No formatToCharacterIterator: the device has no AttributedCharacterIterator.
See Also:
  • Constructor Details

    • Format

      protected Format()
  • Method Details

    • format

      public final String format(Object obj)

      Formats an object to text.

      Throws
      • IllegalArgumentException: if this format cannot format obj
    • format

      public abstract StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)

      Formats an object, appending the text to toAppendTo, and reports the range the field pos names took.

      Throws
      • IllegalArgumentException: if this format cannot format obj
    • parseObject

      public abstract Object parseObject(String source, ParsePosition pos)
      Parses an object from source starting at pos. On success the index of pos is moved past what was read; on failure it is left alone, the error index is set and null is returned.
    • parseObject

      public Object parseObject(String source) throws ParseException

      Parses an object from the beginning of source.

      Throws
      • ParseException: if nothing at the beginning of source parses
      Throws:
      ParseException