Sorting collections

For questions and postings not covered by the other forums
timmeh
Posts: 18
Joined: Fri Apr 13, 2012 3:12 pm

Re: Sorting collections

Postby timmeh » Fri Jun 22, 2012 12:52 pm

Okay I resolved this last issue by using a subclass of Array with the Any type, and a if statement to typecast values =]

murray
Posts: 144
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: Sorting collections

Postby murray » Fri Jun 22, 2012 12:58 pm

I'd go with 7 String keys on the ExtKeyDynaDict, and then if they've only chosen 3 of 7 sort options, set the remaining key values to a null string as you don't care about the sort ordering from that point onwards.

Then, when you're deciding what to use for each of the 7 string key parameters to the putAtKey, you can "generate" a string key from the underlying data in a format that will sort correctly regardless of the type of data that is actually in that column.

Cheers,
BeeJay.
I tried this just now which is almost perfect although it breaks on timestamps, as it sorts them as a string value and 01/01/2012 is lower then 10/01/1999
Try using TimeStamp::literalFormat().
Murray (N.Z.)

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Sorting collections

Postby BeeJay » Fri Jun 22, 2012 2:56 pm

I tried this just now which is almost perfect although it breaks on timestamps, as it sorts them as a string value and 01/01/2012 is lower then 10/01/1999
That's what I meant by
you can "generate" a string key from the underlying data in a format that will sort correctly
For TimeStamps, and other similarly affected values, I don't just type-cast to a String but rather use a formatted string that will sort correctly.

eg: Suppose you have a TimeStamp in a local variable called someTS, the first option would potentially not sort correctly, but the 2nd and third options would sort correctly:

Code: Select all

theKey := someTS.String; dynaDict.putAtKey( theKey, someObject ); theKey := someTS.Date.format("yyyyMMdd") & " " & someTS.Time.format("HH:mm:ss"); dynaDict.putAtKey( theKey, someObject ); // The following only works if you've defined a Short Date format and Short Time format called ShortDateSortingFormat and ShortTimeSortingFormat respectively: theKey := someTS.Date.userFormat($ShortDateSortingFormat) & " " & someTS.Time.userFormat($ShortTimeSortingFormat); dynaDict.putAtKey( theKey, someObject );
Here's what the ShortDateSortingFormat and ShortTimeSortingFormat definitions look like:
ShortDateSortingFormat.png
ShortDateSortingFormat.png (11.21 KiB) Viewed 4894 times
ShortTimeSortingFormat.png
ShortTimeSortingFormat.png (11.44 KiB) Viewed 4894 times
Cheers,
BeeJay.

JohnP
Posts: 73
Joined: Mon Sep 28, 2009 8:41 am
Location: Christchurch

Re: Sorting collections

Postby JohnP » Mon Jun 25, 2012 8:58 am

Similarly, Integers will need to be standardised to a 10-digit length, so that 100 sorts higher than 99.

timmeh
Posts: 18
Joined: Fri Apr 13, 2012 3:12 pm

Re: Sorting collections

Postby timmeh » Wed Jun 27, 2012 1:09 pm

cheers for the clarification, all works really well now.

Thanks again!


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 31 guests

cron