<br> Just a comment:<br><br>"There is no operator overloading in java, so the "<" operator must act on a numerical primitive. (int, double, etc.) "<br><br> This is not true. Comparison operators will work on any "comparable" type. So if Quantity implements Comparable interface, it must work. Otherwise it is a bug.<br>
<br> Although, remember that Drools always makes type coercion from the right to the left value, so, for that to actually work:<br><br>Person( height < $2m )<br><br> "height" must be comparable to $2m.<br>
<br> []s<br> Edson<br><br><br><div class="gmail_quote">2009/2/26 Greg Barton <span dir="ltr"><<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The problem is the "Person( height < $2m )" part. There is no operator overloading in java, so the "<" operator must act on a numerical primitive. (int, double, etc.) $2m is a Quantity. As for why this doesn't error out, I'm not sure, but it certainly won't execute. (Unless mvel has some capabilities I'm not aware of.)<br>
<br>
Try<br>
<br>
Person( height < $2m.height )<br>
<br>
...as long as Person.height and Quantity.height are both numerical types.<br>
<br>
If you want to specifically call compareTo() you should use an eval block:<br>
<div class="Ih2E3d"><br>
WHEN<br>
$meter:UoM( ) from UoMs.get("length","m")<br>
$2m:Quantity() from Quantities.get(2,$meter)<br>
</div> $p: Person()<br>
eval($p.getHeight().compareTo($2m))<br>
<br>
However, even if this works, I hope you're not going to be putting too much data through rules like this. The way it's currently constructed it completely circumvents all of drools' indexing ability. :) The power of rules comes from tracking the changes in a set of objects, and firing rules based on only the changes observed. (That set is the working memory.) The "from" keyword allows you to have rules that draw objects from outside working memory, but you pay for that convenience: the cost is not being able to track changes. As a result, objects gathered using "from" must be reconsidered even if they haven't changed (i.e. every time the condition is encountered) because drools has no way of knowing if they've changed or not.<br>
<br>
So, after this long winded spiel, here's my suggestion: get the rule(s) to work using "from" but also try inserting the Quantity object in working memory. If you're processing enough data with the rules you will notice a difference.<br>
<div class="Ih2E3d"><br>
--- On Thu, 2/26/09, David Boaz <<a href="mailto:davidb@dbmotion.com">davidb@dbmotion.com</a>> wrote:<br>
<br>
> From: David Boaz <<a href="mailto:davidb@dbmotion.com">davidb@dbmotion.com</a>><br>
> Subject: Re: [rules-users] Creating objects in WHEN clause<br>
> To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
</div>> Date: Thursday, February 26, 2009, 9:13 AM<br>
<div class="Ih2E3d">> Thanks for your all help.<br>
> with your help, my rule looks now as:<br>
> WHEN $meter:UoM( ) from<br>
> UoMs.get("length","m")<br>
> $2m:Quantity() from Quantities.get(2,$meter)<br>
> Person( height < $2m )<br>
><br>
> My Quantity class implements Comparable interface. When<br>
> running the rule on<br>
> a good dataset (where I expect the rule to fire), the rule<br>
> fails with no<br>
> error. in addition, the compareTo(Object o) method is not<br>
> called (the<br>
> debugger doesn't stop in this method).<br>
><br>
> Can you please help?<br>
> Thanks, David<br>
<br>
<br>
<br>
</div><div><div></div><div class="Wj3C7c">_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>