Issue Details (XML | Word | Printable)

Key: GROOVY-2756
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Jochen Theodorou
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

create new user overwritable operator methods for <,==,>,<=,=>,<==>

Created: 16/Apr/08 11:09 AM   Updated: 03/Sep/08 05:57 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0

Time Tracking:
Issue & Sub-Tasks
Issue Only
Not Specified

Issue Links:
Related
dependent
 

Sub-Tasks  All   Open   

 Description  « Hide
as not everything we want to let <,==,>,<=,=>,<==> operate on is a total order, it would be nice to have one of these defined only. Also the current solution with Comparable seems to lead to many problems, because Comparable itself is thought to be used with an exact counter part, but we might want to let it work on other classes as well. for this we should go away from Comparable. I would suggest we write a single method with a bitfield containing flags for <,> and ==. Then the user can throw an exception if a flagged operation is not available, also he can implement only < (100) or > (010) or == (001) or <= (101) or =>(011) or <=> (111). the way to keep backwards compatibility with this would be to add a compareTo method that uses the bits 111.. Well needs more discussion

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jörg Staudemeyer added a comment - 17/Jul/08 05:45 AM
What ever implementation (one or multiple methods) will be selected, comparison operator methods should be allowed to return arbitrary types, not only boolean (and certainly not only integer) results. Otherwise utilization in DSLs is too much restricted (as is the case with Groovy 1.x).
See discussions at http://www.nabble.com/Overloading-comparison-operators-td18504388.html and http://www.nabble.com/operator-overloading-td12984525.html.