SourceForge has been redesigned. Learn more.
Close

#180 'MessageBasedComparator'

Rejected
closed
nobody
Classes (154)
5
2012-08-14
2007-06-02
No

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.

Discussion

  • Rony G. Flatscher

    An implementation of the 'MessageBasedComparator' class.

     
  • Rick McGuire

    Rick McGuire - 2007-06-04

    Logged In: YES
    user_id=1125291
    Originator: NO

    This RFE is slated to be rejected.

    Reason:

    New comparators customized to a particular purpose are very easy to create, and compare methods generally should be very simple, since they are called a lot during the sorting process.

    Adding this type of comparator doesn't really add anything to the Rexx language, and is likely to be an inappropriate choice for most sorting operations because of the relative inefficiencies of a generalized comparator vs. a purpose built one.

    To appeal this rejection please contact the Appeals Committee via Mr. Chip
    Davis
    oorexx-rfe-appeals@oorexx.org

    All further correspondence on this RFE should be directed to the Appeals
    Committee and MUST include
    this RFE number.

    The decision of the Appeals Committee is final.

     
  • Rick McGuire

    Rick McGuire - 2007-07-16

    Logged In: YES
    user_id=1125291
    Originator: NO

    This RFE has now passed the 30-day mark since rejection without appeal. This RFE is now closed.

     

Anonymous
Anonymous

Cancel  Add attachments