DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21663>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21663

[lang] Add support in ToStringStyle for DateFormat.





------- Additional Comments From [EMAIL PROTECTED]  2003-07-17 07:45 -------
Rather than adding support for just java.util.Date, consider adding support to 
allow a user to custom format any type of field.  Something like this:

1. Create an interface called say ToStringer

    public class ToStringer{
          String toString(Object objectToFormat);
    }

2. Add a method to ToStringStyle called say addToStringer to add custom 
formatters for specific field types.  Add a map field to hold the formatters.

    public void addToStringer(Class type, ToStringer formatter){
       formatters.put(type,formatter);
    }

3. Then a client will use/configure ToStringStyle like this to custom format 
say fields of type Dates, Doubles and Foos:

        ToStringStyle t = new ToStringStyle();
        t.addToStringer(java.util.Date.class,new ToStringer(){
            String toString(Object date){
                Date d = (Date date);
                return new SimpleDateFormat("yyyy-MM-dd").format(d);
            }
        });
        t.addToStringer(Double.class,new ToStringer(){
              String toString(Object decimal){
                  return new DecimalFormat("#,000.0000").format(decimal);
              }
          });
        t.addToStringer(Foo.class,new ToStringer(){
              String toString(Object foo){
                  Foo f = (Foo)foo;
                  return "Foo object #" + f.getId();
              }
          });
        }

-Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to