• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting objects using my own criteria
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting objects using my own criteria


  • Subject: Re: Sorting objects using my own criteria
  • From: Chuck Hill <email@hidden>
  • Date: Fri, 17 Feb 2006 11:25:13 -0800

Create an NSComparator to do this. That gives you the full power of Java to do sorting. I usually make them a public inner class of the EO I am sorting. Then use the NSArray method sortedArrayUsingComparator or the NSMutableArray method sortUsingComparator to sort using an instance of your new NSComparator subclass.

A trivial example:

    /**
     * Compares Websites by the site ID.
     */
     static class SiteIDComparator extends NSComparator
     {

/**
* Compares Websites by the site ID.
*
* @see com.webobjects.foundation.NSComparator#compare (java.lang.Object, java.lang.Object)
*/
public int compare(Object firstObject, Object secondObject) throws ComparisonException
{
if ((firstObject == null) || (secondObject == null))
{
throw new NSComparator.ComparisonException("Can't compare null objects");
}


            Website firstSite = (Website)firstObject;
            Website secondSite = (Website)secondObject;

return NSComparator.AscendingStringComparator.compare (firstSite.siteID(),
secondSite.siteID());
}


     }


Chuck


On Feb 17, 2006, at 11:08 AM, Miguel Arroz wrote:

Hi!

This is probably a simple question, but I'm not finding an answer... how can I sort objects in memory using my own criteria? The alphabetic ordering is not enough... :)

  Yours

Miguel Arroz

      "GUERRA E' PAZ
       LIBERDADE E' ESCRAVIDAO
       IGNORANCIA E' FORCA"       -- 1984

Miguel Arroz
http://www.ipragma.com



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40global-village.net


This email sent to email@hidden

--
Coming in 2006 - an introduction to web applications using WebObjects and Xcode http://www.global-village.net/wointro


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 (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Sorting objects using my own criteria (From: Miguel Arroz <email@hidden>)

  • Prev by Date: Sorting objects using my own criteria
  • Next by Date: Re: Sorting objects using my own criteria
  • Previous by thread: Sorting objects using my own criteria
  • Next by thread: Re: Sorting objects using my own criteria
  • Index(es):
    • Date
    • Thread