You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Will Hartung <wi...@msoft.com> on 2001/12/05 01:12:50 UTC

Comparing things besides Integers?

I'm adding (changing) Velocity so that it will support Comparable objects
for >, >= , ==, <= , < rather than simply Integers and objects of the same
class.

Is this some great crime? Would this be of interest to Others?

I'm going to do this anyway, and if anyone else would like it, they can
e-mail me.

I'm doing it because my internal scripting language has a runtime-typed
value, and I want to be able to use the comparison operators as well as
something like "contains()" on the values passed to Velocity.

Currently if you do $var.contains("thing") and var is a string, Velocity
seems to silently ignore the error and simply continues.

My code replaces the runtime/parser/node/AST[EQ, GT, GE, LT, LE]Node.java
and I added a Comparator class with static methods in util.

Comparator can be extended for "special cases" if we like. Currently it
casts the Object parameters to Comparable and does a left.compareTo(right).

It'll throw a ClassCastException as appropriate, the Node classes catch the
exception and log the error.

And if no one is interested, I'm curious as to why it's a problem.

Thanx!

Best Regards,

Will Hartung
(willh@msoft.com)



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Comparing things besides Integers?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/4/01 7:12 PM, "Will Hartung" <wi...@msoft.com> wrote:

> I'm adding (changing) Velocity so that it will support Comparable objects
> for >, >= , ==, <= , < rather than simply Integers and objects of the same
> class.
> 
> Is this some great crime? Would this be of interest to Others?

A heineous crime that is of interest to others indeed... :)

> 
> I'm going to do this anyway, and if anyone else would like it, they can
> e-mail me.
> 
> I'm doing it because my internal scripting language has a runtime-typed
> value, and I want to be able to use the comparison operators as well as
> something like "contains()" on the values passed to Velocity.
> 
> Currently if you do $var.contains("thing") and var is a string, Velocity
> seems to silently ignore the error and simply continues.
> 
> My code replaces the runtime/parser/node/AST[EQ, GT, GE, LT, LE]Node.java
> and I added a Comparator class with static methods in util.
> 
> Comparator can be extended for "special cases" if we like. Currently it
> casts the Object parameters to Comparable and does a left.compareTo(right).
> 
> It'll throw a ClassCastException as appropriate, the Node classes catch the
> exception and log the error.
> 
> And if no one is interested, I'm curious as to why it's a problem.

Check the archives first.  There are long threads on this :)

> 
> Thanx!
> 
> Best Regards,
> 
> Will Hartung
> (willh@msoft.com)
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>