net.sf.japaki.text
Class AbstractFormat

java.lang.Object
  extended by java.text.Format
      extended by net.sf.japaki.text.AbstractFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
ClassFormat, RegexFormat

public abstract class AbstractFormat
extends Format

This class provides a skeletal implementation of the Format class, to minimize the effort required to implement a format.

See Also:
Serialized Form

Nested Class Summary
protected static class AbstractFormat.DefaultField
          Miminal implementation of the Field class.
 
Nested classes/interfaces inherited from class java.text.Format
Format.Field
 
Constructor Summary
AbstractFormat()
           
 
Method Summary
static void appendAndSetIndexes(StringBuffer toAppendTo, String text, Format.Field field, FieldPosition pos)
          Appends the given text to the buffer.
 StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
          Appends the Object.toString() representation of the object to the buffer.
 Format.Field getField()
          Returns the field used by this format.
 void setField(Format.Field field)
          Sets the field used by this format.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFormat

public AbstractFormat()
Method Detail

getField

public Format.Field getField()
Returns the field used by this format.

Returns:
the field used by this format.

setField

public void setField(Format.Field field)
Sets the field used by this format.

Parameters:
field - the field to be compared in format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) used by this format.

appendAndSetIndexes

public static void appendAndSetIndexes(StringBuffer toAppendTo,
                                       String text,
                                       Format.Field field,
                                       FieldPosition pos)
Appends the given text to the buffer. Then it checks if a valid field position is defined and if so sets the given indexes.

Parameters:
toAppendTo - where the text is to be appended
text - newly formatted text for this field
field - field to check aganinst the field in pos
pos - field position to be updated
Throws:
NullPointerException - if toAppendTo or pos or field is null

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Appends the Object.toString() representation of the object to the buffer.

Specified by:
format in class Format
Parameters:
obj - the object to format
toAppendTo - where the text is to be appended
pos - ignored
Returns:
the string buffer passed in as toAppendTo, with formatted text appended
Throws:
NullPointerException - if obj is null.