From: SourceForge.net <no...@so...> - 2007-06-02 22:49:36
|
Feature Requests item #1730090, was opened at 2007-06-03 00:49 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=684733&aid=1730090&group_id=119701 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Classes Group: Next Release Status: Open Resolution: None Priority: 5 Private: No Submitted By: Rony G. Flatscher (orexx) Assigned to: Nobody/Anonymous (nobody) Summary: 'MessageBasedComparator' Initial Comment: Now that sorting has become possible, using comparators, it would be handy to allow for a dynamic means of retrieving the values to be used for comparisons. Many times arrays may have non-string objects and objects that do not implement the 'Comparable' protocol (method "compareTo"). However, in most cases such objects have one or more methods that may render (part or whole of) the object into a comparable value. E.g. if having an array of class objects, and one wishes to sort that array such, that all class objects are sorted ascendingly, then one would need access to either the result of sending the message "ID" or "STRING" to the class object. The resulting array should still contain the class objects, but now they should be arranged in it in the desired order. A program could look like: ------------ cut here ------------- a=.array~of(.object, .array, .relation) mbc=.MessageBasedComparator~new("ID") say "Sorting class objects using their 'ID' string for comparisons:" say a~sortWith(mbc) do clz over a say " " clz~id end say "---" say "Now sorting descendingly:" say rev=.InvertingComparator~new(mbc) a~sortWith(rev) do clz over a say " " clz~id end ------------ cut here ------------- The output should be: ------------ cut here ------------- Sorting class objects using their 'ID' string for comparisons: Array Object Relation --- Now sorting descendingly: Relation Object Array ------------ cut here ------------- With this RFE there is an implementation of such a 'MessageBasedComparator' class enclosed for inclusion in ooRexx. The above program and its output was actually created using that uploaded class. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=684733&aid=1730090&group_id=119701 |