• 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 question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting question


  • Subject: Re: Sorting question
  • From: "Jonathan 'Wolf' Rentzsch" <email@hidden>
  • Date: Wed, 22 Sep 2004 12:27:04 -0500

James Cicenia, email@hidden, wrote:
>I thought that EOSortOrderings were just for EOs.

It works fine with anything that supports KVC:

public static void main(String argv[]) {
  NSDictionary a = new NSDictionary( "Alice", "name" );
  NSDictionary b = new NSDictionary( "Bob", "name" );
  NSDictionary c = new NSDictionary( "Carl", "name" );
  NSArray unsorted = new NSArray( new Object[]{a,c,b} );
  System.out.println( "unsorted: "+unsorted );

  EOSortOrdering ascending = EOSortOrdering.sortOrderingWithKey("name",
EOSortOrdering.CompareAscending);
  NSArray sortedAscending = EOSortOrdering.sortedArrayUsingKeyOrderArray(
unsorted, new NSArray( ascending ) );
  System.out.println( "sortedAscending: "+sortedAscending );

  EOSortOrdering descending = EOSortOrdering.sortOrderingWithKey("name",
EOSortOrdering.CompareDescending);
  NSArray sortedDescending =
EOSortOrdering.sortedArrayUsingKeyOrderArray( unsorted, new NSArray(
descending ) );
  System.out.println( "sortedDescending: "+sortedDescending );
}

output:
unsorted: ({name = "Alice"; }, {name = "Carl"; }, {name = "Bob"; })
sortedAscending: ({name = "Alice"; }, {name = "Bob"; }, {name = "Carl"; })
sortedDescending: ({name = "Carl"; }, {name = "Bob"; }, {name = "Alice";
})

>I just wound up
>creating a simple
>utility class with a compareTo in it. It works.

I'm sure it does. But my way's less code :-)

| Jonathan 'Wolf' Rentzsch   http://rentzsch.com
| Red Shed Software           http://redshed.net
|     "better" necessarily means "different"

 _______________________________________________
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

  • Follow-Ups:
    • Re: Sorting question
      • From: James Cicenia <email@hidden>
  • Prev by Date: asynchronous processing in WOLongResponsePage
  • Next by Date: Re: Sorting question
  • Previous by thread: Re: Sorting question
  • Next by thread: Re: Sorting question
  • Index(es):
    • Date
    • Thread