or (untested ... syntactically correct is all i can vouch for here):

public class CompositeComparator extends NSComparator {
  private NSComparator[] _comparators;

  public CompositeComparator(NSComparator... comparators) {
    _comparators = comparators;
  }

  @Override
public int compare(Object object1, Object object2) throws ComparisonException {
    int result = NSComparator.OrderedSame;
    for (NSComparator comparator : _comparators) {
      result = comparator.compare(object1, object2);
      if (result != NSComparator.OrderedSame) {
        break;
      }
    }
    return result;
  }
}

On May 11, 2007, at 3:52 PM, Chuck Hill wrote:


On May 11, 2007, at 12:55 AM, 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 ...

Absolutely you can sort by multiple keys!  Here is how to do it:


    /**
* NSComparator to sort on Zone, Production Status, and Product Type. This relies on the Any status/type * having a value of 0 so that more general associations sort later in the list. The more specific ones
     * earlier in the list have a higher priority.
     */
    public static class TypeStatusComparator extends NSComparator
    {
public int compare(Object object1, Object object2) throws NSComparator.ComparisonException
        {

int result = NSComparator.AscendingNumberComparator.compare(((ColorSwatchZone) object1).zone().zoneID(), ((ColorSwatchZone)object2).zone().zoneID());

            if (result == NSComparator.OrderedSame)
            {
result = NSComparator.DescendingNumberComparator.compare(((ColorSwatchZone) object1).productionStatus(), ((ColorSwatchZone)object2).productionStatus());
            }

            if (result == NSComparator.OrderedSame)
            {
result = NSComparator.DescendingNumberComparator.compare(((ColorSwatchZone) object1).productType(), ((ColorSwatchZone)object2).productType());
            }
            return result;
        }
    }




Chuck





--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects





_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/mschrag% 40mdimension.com

This email sent to [EMAIL PROTECTED]


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to