Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#26 Top level cell processors that can be applied to any cell

Outstanding
closed
nobody
None
1
2015-01-23
2013-02-19
Karl D. Moore
No

Cell Processors are very powerful, but it's quite limiting that I have to supply an array of processors when writing a row. What I'd like to do is supply a processor to the writer and when a cell of this type is encountered this is called. At the minute I've got to create an array of 29 nulls and custom cell processor. It seems unnecessary. Likewise if I want all date formatting to be performed using a single pattern it would be easy to register this once for all date columns.

writer.addCellProcessor(Date.class, new CustomDateFormatter("yyyy-MM-dd"));

Discussion

  • Rather than messing up with the existing framework, you should extend it. Create a cellprocessor which allows you to register types and converters to it as you just specified. Then make a helper method which given an int, returns an array of such processors.

     
  • Karl D. Moore
    Karl D. Moore
    2013-02-19

    That's pretty much what I've implemented. Is that something you'd be interested in adding to the library? I'm happy to contribute it back.

     
  • James Bassett
    James Bassett
    2013-02-19

    Yes, that'd be great. Obviously it's only applicable to writing, but it sounds generic enough to be a good addition to the library. If we use it you'll get credit as a contributor on the website :)

    Oh, and seeing your CustomDateFormatter - don't forget there's already a date formatting processor FmtDate.

     
  • Karl D. Moore
    Karl D. Moore
    2013-02-19

    Yes that was probably a bad example, I'm using FmtDate already. I have a few other processors I've been playing around with so once it's cleaned up, I'll send it over.

     
  • Hi Karl!

    Sure sounds great! Before submitting anything, I urge you to consider a few complicating examples. I hope they don't break your spirit, its just "problems" that can easily arise when such a feature comes to play.

    1. Are you handling inheritance properly? The problem in its simplest form: Given the classes Living and Human (extending Living) and you register processing for both classes, what happens when you want to write a human? Hint, Human is typeof Living.

    2. How are generic handled? Can I register both a PaymentContainer<Human> and a PaymentContainer<VIPCustomer> ? And what happens if I register for List<String> and deliver a List object?

    3. Are there issues with simpletypes? Can they be registered? Do I need to register both types int and Integer?

    4. Finally, maybe we need to add some caching mapping between type of input and the appropriate processor to use. This is due to the potentially expensive resolution I've hinted in (1)

    5. Just out of curiosity, what does said processors do?

    cheers
    Kasper

     
    Last edit: James Bassett 2013-03-01
  • Karl never returned...

     
    • status: open --> closed