[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to use a comparator?
Hi Neil,
>Is it possible to use a comparator in my database classes?
Yes
>I want to use a custom comparator with a TreeSet to keep my
>objects in a given ordering, but the Comparator is not
>serializable
Keeping a TreeSet in a custom ordering in ozone isn't a problem. I use
custom Comparator in several places in my application. I also implement the
Comparable interface where appropriate. The application has collections that
are sorted in more than one way. I haven't found the inability to serialize
a Comparator a problem.
Keep in mind that the ordering of the collection should be done on the
server. This way no serialization of the comparator is required.
There are two options for doing your sorting. If the objects are always
sorted in the same way implement the Comparable interface with a compareTo()
method. If you need more than one sort order use custom Comparators.
>nor can I declare my class to extend Comparator
>and the Ozone objects.
>
Could you please explain why this is required? I can't conceive of a
situation where one would want to have a ozone persistent class extend
Comparator. Why would you want to extend both Comparator and OzoneObject?
cheers,
don
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com