[rules-users] using BigDecimal in rules

Edson Tirelli tirelli at post.com
Thu Nov 6 14:04:05 EST 2008


   Take a look at the manual for details, but the short answer is:

mvn clean install

   You need maven and java installed.
   To run that single unit test, you can simply import drools-core as a
project into eclipse and just run the test.

   []s
   Edson

2008/11/6 Marina <ppine7 at yahoo.com>

> Thanks, Edson.
> I do have the source code for Drools4.0.7. How do I build and run the unit
> tests?
>
> Marina
>
> ------------------------------
> *From:* Edson Tirelli <tirelli at post.com>
> *To:* Rules Users List <rules-users at lists.jboss.org>
> *Sent:* Thursday, November 6, 2008 10:46:46 AM
> *Subject:* Re: [rules-users] using BigDecimal in rules
>
>
>    It sounds like a bug. Can you get Drools source code and look at the
> unit test for this to make sure your scenario works there? The file is:
>
> drools-core/src/test/java/org/drools/base/EvaluatorFactoryTest.java
>
>    Method is:
>
> testBigDecimal()
>
>    Very easy to add your use case in there.
>
>    Let us know what you find.
>
>    Edson
>
> 2008/11/6 Marina <ppine7 at yahoo.com>
>
>> Hi,
>>
>> I'm getting unexpected results when when using BigDecimal objects for
>> matching in rules.
>> I'm generating DRL in my code, using freemaker.
>>
>> I have a RuleEngineNumericFact object which has two attributes:
>> String propertyName
>> BigDecimal propertyValue
>>
>> Below is an example of a rule where I try to match a RuleEngineNumericFact
>> object based on the two attributes:
>>
>> rule "aaa"
>>     agenda-group "r1"
>>     dialect "java"
>>     when
>>         (RuleEngineNumericFact( propertyName == "somename" , propertyValue
>> == 10.8 ))
>>     then
>>         String ruleId = drools.getRule().getName();
>>         firedRuleIDs.add(ruleId);
>> end
>>
>>
>> Then I create a new RuleEngineNumericFact object and set its propertyValue
>> as following:
>>
>> String stringValue = "10.8";
>> BigDecimal propertyValue = new BigDecimal(stringValue, new
>> MathContext(10));
>>
>> (I also tried to use default precision settings by creating the BigDecimal
>> value as:
>> BigDecimal propertyValue = new BigDecimal(stringValue);
>> )
>>
>> When I insert this fact into the rule engine - the rule does not get
>> fired, so the fact does not match.
>>
>> One note: if the values are integeres (like, propertyValue == 100) - the
>> rule gets fired. So, it is only the floating point numbers that do not
>> match.
>>
>> I generate the DRL in my Java code, using freemaker, and I specify the
>> value that will be used in the rule for matching by calling toString()
>> method on a BigDecimal object that I get from my business code. The
>> toString() representation ends up to be the "10.8" value (for example).
>> According to the BigDecimal documentation, marshalling from/to the same
>> string representation shoudl still produce BigDecimal objects that will
>> return TRUE from the equals() method when compared.
>>
>>
>> any ideas why this is not working here?
>> How does Drools compare values of objects like BigDecimal?
>>
>> thanks,
>> Marina
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss, a division of Red Hat @ www.jboss.com
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081106/0b0a7027/attachment.html 


More information about the rules-users mailing list