[rules-users] Double Handling

Ade Timi adeyinka.timi at nathean.com
Mon Apr 12 11:24:22 EDT 2010


Thanks guys for your responses. This should be as simple as it gets, which
adds to my frustration. See the following code below:

Java classes:

Individual - 

            public class Individual {

private double assetCost;

 

public void setAssetCost(double assetCost) {

            this.assetCost = assetCost;

            }

 

            public double getAssetCost() {

                  return assetCost;

}

}

IndividualDecision - 

            public class IndividualDecision {

private double loanToValue;

 

public void setLoanToValue(double LoanToValue) {

                  this.loanToValue = LoanToValue;

            }

            public double getLoanToValue() {

                  return loanToValue;

      }

            public void calcValues(Individual ind){

            this.loanToValue = ind.getAssetCost();

      }

}

 

Rule Resourse - 

            import com...Individual

import com...IndividualDecision

 

rule "G2 Equity in Asset"

      when

            $d : IndividualDecision(loanToValue() < 85.0)

      then

            System.out.println("loanToValue: " + ($d.getLoanToValue()));

End

 

Hope this helps! Many Thanks again

  _____  

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: 12 April 2010 15:46
To: Rules Users List
Subject: Re: [rules-users] Double Handling

 


    Ade,

    All these errors you are seeing are totally strange, as this is one of
the simplest things the rules engine does. Are you able to isolate that into
a test case that I can run myself to take a look?

    Edson

2010/4/12 Ade Timi <adeyinka.timi at nathean.com>

This is precisely how I expect it to be expressed. When I express in this
way I get this error message:

 

BuildError: Unable to create Field Extractor for 'loanToValue' of
'[ClassObjectType class=com.nathean.rules.IndividualDecision]' in rule 'G2
Equity in Asset'

 

even though it is a variable in my IndividualDecision class. I have 3 other
rule files that have expression in this simple manner and they produce no
errors and are fine.

But for this, It only lets me use eval or have something like this:

rule "G2 Equity in Asset"

      ruleflow-group "goods"

      when

            $d : IndividualDecision()

            Individual($d.loanToValue < 85.0)

      then

            .

            //System.out.println((Double.valueOf("85")).doubleValue());

            System.out.println("loanToValue: " + ($d.getLoanToValue()));

End

 

I understand that it is pointless having that 2nd line in the when section,
but it's the only way it picks up the variables in the IndividualDecision
class with no errors. I don't know why I can't do this with this particular
rules file. I am using Eclipse. Could there be some drools configuration
issue with this file?

 

-A

 

  _____  

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 12 April 2010 14:30


To: Rules Users List
Subject: Re: [rules-users] Double Handling

 

Well, then drop the
  dialect "mvel"
and write the pattern as
   $d : IndividualDecision( loanToVal < 85.0 )

There's no visible need to use mvel. 

Or eval: the simplest form for constraints is always best.

-W

 

2010/4/12 Ade Timi <adeyinka.timi at nathean.com>

Many thanks for the response!

Yes it fires when I use 85.0 instead, but it obviously shouldn't as the
condition is false. My code now looks like this:

 

rule "G2 Equity in Asset"

      ruleflow-group "goods"

      dialect "mvel"

      when

            $d : IndividualDecision(eval($d.getLoanToValue() < 85.0))

      then

            $d.setGoodCount($d.incGoodCount());

            $d.setMessage("0065: G2: Good: Good Equity in Deal");

            //System.out.println((Double.valueOf("85")).doubleValue());

            System.out.println("loanToValue: " + ($d.getLoanToValue()));

end

 

I still get the print output of 92000.0, which is as I expect but I don't
expect the rule to be fired at all. The weird thing is that when I change
the condition to '>' which is the true condition it never fires! I'm at a
loss as to why this is happening.

 

- Ade

 

  _____  

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 11 April 2010 09:11
To: Rules Users List
Subject: Re: [rules-users] Double Handling

 

You are comparing a double to a String ("85"). Although MVEL might convert
strings to numbers, I wouldn't use this without some cogent reason.

Do you have this unexpected firing also when you use a double literal, i.e.,
85.0 ?

-W

2010/4/9 Ade Timi <adeyinka.timi at nathean.com>

Hi,

 

I am new to Drools. I am having a problem comparing 2 double values. I have
a Java class with a double attribute called loanToValue. The loanToValue is
been read from an XML file and the value is 92000.0. Based on this value I
do not expect this rule to be fired, but for some reason it does. And the
print statement returns 92000.0. Does anyone know what I'm doing wrong? My
rule looks as follows:

 

rule "G2 Equity in Asset"

      ruleflow-group "goods"

      dialect "mvel"

      when

            $d : IndividualDecision()

            Individual(eval($d.getLoanToValue() < "85"))

      then

            System.out.println("loanToValue: " + ($d.getLoanToValue()));

end

 

Thanks,

Ade

 

Adeyinka Timi | Technical Supprt | Nathean Technologies Ltd

Registered Office 3 Lyncon Court, IDA Science & Technology Park, Snugborough
Road, Blanchardstown, Dublin 15, Ireland
T +353 1 685 3001 | VOIP 076 615 1117 | E adeyinka.timi at nathean.com |
<http://www.nathean.com/>  <http://www.nathean.com> www.nathean.com

Incorporated in Ireland, No. 339972

The information appearing in this email and any files transmitted with it is
confidential and may not be reproduced, modified, distributed, transmitted,
displayed, published or broadcast without the prior written permission of
Nathean Technologies Ltd. It is intended solely for the use of the
addressee(s). Nathean Technologies Ltd, its directors, officers and
employees do not accept liability for any loss or damage of any nature
howsoever arising pertaining to the use of information appearing in this
email and/or any files transmitted with it. Whilst this email has been
checked for the presence of computer viruses, Nathean Technologies Ltd does
not, except as required by law, represent, warrant and/or guarantee that the
integrity of this communication has been maintained nor that the
communication is free of errors, viruses, interception or interference.

 


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

 


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

 


_______________________________________________
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 by Red Hat @ www.jboss.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100412/d84fd7ab/attachment.html 


More information about the rules-users mailing list