[rules-users] newbie question on "when" condition syntax

Anstis, Michael (M.) manstis1 at ford.com
Fri May 2 05:05:20 EDT 2008


Hi Richard,
 
The "when" section matches fact (object) patterns, so your requirement could
be written as:-
 
when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.....
 
This would become:-
 
rule "Rule 1"
when
    Test( $y : y )
    Test( x == ($y + 1) )
then
    System.out.println("Rule 1 matches");
end
      
By default both patterns can match the same object, so test data:-
 
A : x = 1, y = 1
B : x = 2, y = 1
 
Will cause the rule to activate twice:-
 
A and B
B and B
 
With kind regards,
 
Mike



  _____  

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Richard Bremner
Sent: 02 May 2008 08:53
To: rules-users at lists.jboss.org
Subject: [rules-users] newbie question on "when" condition syntax


Hi, 

say I have a class with two fields, x and y: 

public class Test { 
    int x = 1; 
    int y = 2; 

    getters/setters... 
} 


I would like a rule which fires when y = x + 1 

my initial thought would be something like: 

rule "Rule 1" 
        
        when 
                test : Test (y == x + 1) 
        then 
                System.out.println("Rule 1 matches."); 
                
end 


but this is invalid syntax and I can not find any examples of such a rule.
I'm doing my best but reading the manual etc. I'm struggling with the syntax
here and can't figure it out.

any help really appreciated! 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080502/6767b582/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 7206 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080502/6767b582/attachment.bin 


More information about the rules-users mailing list