aspose file tools*
The moose likes Other Open Source Projects and the fly likes Apache POI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Apache POI" Watch "Apache POI" New topic
Author

Apache POI

Johannes Uhlmann
Greenhorn

Joined: May 25, 2011
Posts: 5

Hello,

i got a question regarding to the class hierarchy of Cell and the possibility to implement Comparable.

There are HSSFCell implements Cell and XSSFCell implements Cell. I wanted the compareTo functionality for both, hence my idea was to design a class like abstract class MyCell implements Cell, Comparable<Cell>. So i could implement compareTo but omit the Cell functions. The problem is that MyCell is not a Cell. Available options: 1.) always cast if a Cell is needed 2.) extend HSSFCell as well as XSSFCell and implement Comparable for both. Are there more options?

regards
Johannes

edit: ;-)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

Perhaps something like

Another option would be to forget about making a Cell comparable; you can compare a MyCell object to an XSSFCell object, because you wrote the code for MyCell, but you can't compare an XSSFCell object to a MyCell object because you didn't write the code for XSSFCell. A Comparator might be a better idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Apache POI
 
Similar Threads
Generics .. contravariance question on Collections.sort static method
Sorting arrays
Collections.sort method in java
How to fix blue triangle in top left corner of cell in excel while creating using apache poi 3.6
Using generics and the Comparable interface to implement a node