如何在drool中将字符串变量设置为某个值

时间:2015-04-22 02:38:34

标签: java eclipse debugging drools

public class Policy{
    String accntCode;
    String currency;
    String flag;
} 
为每个人生成

和getter setter。

现在,如果flag不是"Y"currency"INR"开头,我需要将accntCode的值设置为"P" 。请帮助我,因为我是Drool的新手。

我使用

创建了类Policy的对象策略
Policy policy = new Policy();

还请告诉我是否有任何方法可以在eclipse中调试Drool,就像我们对java代码一样。

2 个答案:

答案 0 :(得分:0)

在Drools中你需要:

rule "Raise flag if currency isn't INR"
  when
    $p : Policy ( getCurrency() != "INR" )
  then
    $p.setFlag("Y")

您需要在Java端创建适当的getter和setter。

答案 1 :(得分:0)

以下规则应该有效:

rule "Set flag \"Y\" when accntCode starts with 'P' and currency is not \"INR\""
    when
        a : Applicant(currency != "INR", accntCode str[startsWith] "P" )
    then
        a.setFlag("Y");
        System.out.println(a.getAccntCode() + "\t" + a.getCurrency() + "\t" + a.getFlag());
end

rule "Set flag \"N\" when accntCode doesn't start with 'P' and currency is not \"INR\""
    when
        a : Applicant(currency != "INR")
        not Applicant(accntCode str[startsWith] "P" )
    then
        a.setFlag("N");
        System.out.println(a.getAccntCode() + "\t" + a.getCurrency() + "\t" + a.getFlag());
end

所以,当事实是

app.setAccntCode("PHD");
app.setCurrency("EURO");

你会得到

PHD EURO    Y

事实是

app2.setAccntCode("HD");
app2.setCurrency("EURO");

你会得到

HD  EURO    N