• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extends java.text.Format

 
Josee Paradis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I try to define a format for an object (an object I have created). I know I have to implement these 3 methods
1) format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
2) formatToCharacterIterator(Object obj)
3) parseObject(String source, ParsePosition pos).

My problem is I don't know what to put in these methods.

For exemple my object has 3 fields. Two of them are string. I would like when format is call on this object display the two String.

Thank you
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by reading the documentation for interface you're implementing or the abstract class that you're extending. What do these methods belong to?
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
obj - your object with the two String objects.

toAppendTo - a StringBuffer that you instantiate(could be empty to begin with)

pos - new FieldPosition(0); object for storing the beginning and ending of a substring within your formatted String.

2) formatToCharacterIterator(Object obj)
The method is concrete(not abstract) and DateFormat does not override it so I don't know why you should.

3) parseObject(String source, ParsePosition pos).
source - the formatted String that you created from your object with the two Strings.

pos - the beginning and ending of a substring within your formatted String that you want to parse.

NOTE: May I suggests that you read the javadoc for java.text.DateFormat for and example.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic