Am 07.05.2010 um 06:25 schrieb Chuck Hill: > > On May 6, 2010, at 3:29 AM, Paul Hoadley wrote: > >> On 06/05/2010, at 4:41 PM, Timo Hoepfner wrote: >> >>> I did something similar before. I basically took the "Strings" class from >>> here: >>> >>> <http://weblogs.java.net/blog/skelvin/archive/2006/01/natural_string.html> >>> >>> and wired it up in a EOSortOrdering.ComparisonSupport subclass derived from >>> ERXComparisonSupport. I attached a cleaned up version of the file. >>> >>> Then add something like this to your Application (if it extends >>> ERXApplication): >>> >>> @Override >>> public void finishInitialization() { >>> super.finishInitialization(); >>> NaturalOrderStringSortSupport.initialize(); >>> } >>> >>> >>> As Johann pointed out before, this is then globally used for all String >>> sorting. >> >> Thanks Timo. Very helpful. >> >> If the list could just bear with me for a little longer... I take it that >> I've fundamentally misunderstood what an EOSortOrdering is doing. When I >> wanted to create an EOSortOrdering that sorts in some particular way _on >> some particular EO's attribute_, there's actually no such thing—right? An >> EOSortOrdering takes a key, but then sorts in a pre-defined way based on the >> type of the key (and the NSSelector supplied)—right? So I've really only >> got the following options: >> >> 1. Take Timo and Johann's advice, and implement a custom sorting algorithm >> that would be used globally for all Strings. >> 2. Change the Java type of that attribute to some custom type (that >> presumably includes a String by composition), implement the sorting >> algorithm for that type, and register that for global use as described. (Is >> that even feasible? Sounds like a lot of work.) > > I think I could make a good case for that being the right answer. Maybe not > the easy answer, but right.
I would consider that option too. You have to bear in mind that if you change the comparator globally for all String objects you can considerably slow down your app if you are doing expensive things like using pattern matching and all that kind of stuff, especially when working with big arrays. Though it could be negligible in a small app. I think the ideal implementation would be to keep the normal String prototype in your model (as your model could be reused in other apps that don't need the custom sorting) and change it programmatically to your custom subclass of String in the constructor/initializer of your custom comparator. jw > > >> 3. Stick with the current hack that will break if the attribute value can't >> be cast to an Integer. >> >> Any other options? Or do I sound completely insane? > > > Completely is a little harsh. ;-) > > Chuck
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
