Re: A custom way to sort EOs by key ?
Re: A custom way to sort EOs by key ?
- Subject: Re: A custom way to sort EOs by key ?
- From: Lachlan Deck <email@hidden>
- Date: Sat, 12 May 2007 10:44:44 +1000
Hi Fabrice,
On 11/05/2007, at 5:55 PM, Fabrice Pipart wrote:
On May 10, 2007, at 11:19 PM, Matthew W. Taylor wrote:
It sounds like what you want to do is perform "Natural" sort
ordering to the results.
sortedArray = unsortedArray.sortedArrayUsingComparator(new
EOCustomObjectNaturalOrderComparator("nameOfKeyToSortBy"));
// EOCustomObjectNaturalOrderComparator.java
That's absolutely what I was looking for :-)
I had just missed the NSArray.sortedArrayUsingComparator method :(
And it's far more obvious how to subclass a NSComparator than a
NSSelector ;-)
The only drawback compared to
EOSortOrdering.sortedArrayUsingKeyOrderArray is that I cannot do
ordering for several keys : ORDER BY name, otherKey ...
You wouldn't want to subclass EOSortOrdering anyway, but either
- have your 'Screen' entity implement EOSortOrdering.Comparison, or
- create YourNaturalSortOrdering extending
EOSortOrdering.ComparisonSupport and, at application launch, for
every entity that you need in-memory natural sort ordering:
public Application extends ... {
private static final EOSortOrdering.ComparisonSupport
naturalOrdering = new YourNaturalSortOrdering();
foreach natural sorting entity:
EOSortOrdering.ComparisonSupport.setSupportForClass
( naturalOrdering, <entity>.class );
}
or follow the NSComparator approach as others have suggested.
with regards,
--
Lachlan Deck
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden