• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Extends java.text.Format

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic