• 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: James Cicenia <email@hidden>
  • Date: Wed, 22 Sep 2004 12:42:51 -0500

ah yes the wonders of KVC. I knew there was a webobjects solution to this
problem. And yes it would have used less code... ;-)


-James

On Sep 22, 2004, at 12:27 PM, Jonathan 'Wolf' Rentzsch wrote:

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:
email@hidden


This email sent to email@hidden


_______________________________________________ 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: 
 >Re: Sorting question (From: "Jonathan 'Wolf' Rentzsch" <email@hidden>)

  • Prev by Date: Re: Sorting question
  • Next by Date: Architectural question regarding WOComonent Actions and Frameworks
  • Previous by thread: Re: Sorting question
  • Next by thread: asynchronous processing in WOLongResponsePage
  • Index(es):
    • Date
    • Thread