Mon 2 Jul 2007
I’ve come across the following statement on PeopleBooks (PeopleCode API Reference > Application Classes > When Would You Use Application Classes?). This statement can be found in PeopleBooks for PeopleTools versions 8.45 to 8.49:
… suppose you want to provide a more generic sort, with comparison function at the end of it. You want to use the array class Sort method, but your process has to be generic: you aren’t certain if you’re comparing two records or two strings. You could define a class that had as its main method a comparison, and return a -1, 0, or 1. Then write your personalized sort, extending the array class method Sort.
I find this statement very vague and lacking in details, that I am doubtful about its accuracy.
The statement seems to somewhat describe how one would define the ordering of objects in Java’s array and collection classes by creating an implementation of java.util.Comparator interface. However, according to PeopleBooks, the Sort method of the Array class does not have any optional parameters where such a comparator object may be provided.
I couldn’t find anything else in PeopleBooks where it describes the implementation of array sorting in the manner described in the statement above. Can anyone shed some light into this, and if possible, provide additional details? Does the PeopleCode Array class Sort method have an undocumented feature similar Java Arrays’ sort method?
July 6th, 2007 at 11:50 am
Why woudn’t they allow function overloading :(, especially when some of the delivered in-built classes (Records, Rowsets) support them.
July 6th, 2007 at 8:25 pm
Exactly! Unfortunately application classes doesn’t support method overloading. I wish future versions will.
Reflecting on the above quoted statement from PeopleBooks, it may indeed be possible that it was merely suggesting overriding the Sort method with a new method that takes in a comparator parameter. This would still require the developer to create his own sort routine though. Maybe I’ll take a shot at this.
July 11th, 2007 at 5:56 am
ChiliJoe,
I didn’t see these last comments before I tried an example.
I think that you are correct in saying that PeopleBooks talks about overriding the Sort method. That is what I understood when they said “extending the array class”.
Any way, here is an attempt at an example.