Ok, I'm having some amount of difficulty with trying implement some
operator overloading and am hoping someone has some ideas on how to
fix these issues.
Here's what I'm trying to do (and didn't think it would be this
difficult). I want to implement some Set notation like the following:
a is a subset of b (a <= b)
a is a proper subset of b (a < b)
a equals b (a == b)
and some Set operations:
a union b (a + b)
a intersect b (a / b)
a complement b (a - b)
For reference set notation and operations can be found on wikipedia
(
http://en.wikipedia.org/wiki/Naive_set_theory).
Now that I have the ground rules laid here are some of the issues I'm
encountering:
1) a == b, do this by overriding the equals method, right? Nope, the
compareTo(object) method gets called instead
2) a <= b, i have to implement Comparable to use the compareTo()
method (which by the way is not at all mentioned here -
http://groovy.codehaus.org/Operator+Overloading). But the compareTo()
method only returns -1, 0, or 1 (not true or false, which is needed
for my tests and would make sense to me)
Please tell me I'm wrong, I would love to be wrong on this. But this
seems overly complicated for overriding some of these methods. I know
that the leftShift operator is not nearly as difficult (and seems to
be the one that everyone goes after).
I'm attaching my test class and actual class I'm using. I also tried
initially to use ExpandoMetaClass to do this but kept getting argument
type mismatches when I called. This led me down my current path of
using my own class as originally I wanted to use this on all
Collections.
--
Warner Onstine - Programmer/Author
New book on Tapestry 4!
Tapestry 101 available at
http://sourcebeat.com/books/tapestrylive.htmlwarner@...
http://warneronstine.com/blog ---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email