Java 如何将When语句中的数据存储在Drools中?
我需要导致从规则“Then”部分的“When”部分触发规则的数据。例如,如果我想记下一家商店里50个以上的坏苹果,我就是这样做的Java 如何将When语句中的数据存储在Drools中?,java,drools,Java,Drools,我需要导致从规则“Then”部分的“When”部分触发规则的数据。例如,如果我想记下一家商店里50个以上的坏苹果,我就是这样做的 Rule "Detect Bad Apples" When s : Store( numberOfBadApples() > 50 ) Then // Print out a list of the bad apples 为了让它更复杂一点,我有多条规则可以覆盖。否则,我会将数据存储到store类中的一个变量中 有更好的方法吗?我一直在
Rule "Detect Bad Apples"
When
s : Store( numberOfBadApples() > 50 )
Then
// Print out a list of the bad apples
为了让它更复杂一点,我有多条规则可以覆盖。否则,我会将数据存储到store类中的一个变量中
有更好的方法吗?我一直在通读这本书,但我还是很困惑
---编辑----
Java中的Store类如下所示:
public class Store {
private ArrayList<Apple> appleList;
// The appleList would be filled in another method
public int numberOfBadApples() {
int badAppleCount = 0;
for (Apple apple : appleList) {
if (apple.isBad()) {
badAppleCount++;
}
}
return badAppleCount;
}
}
公共类存储{
私人ArrayList应用程序列表;
//appleList将用另一种方法填充
公共int numberOfBadApples(){
int-badAppleCount=0;
for(苹果:苹果列表){
if(apple.isBad()){
badAppleCount++;
}
}
返回badAppleCount;
}
}
因此,在Drools中的“Then”语句中,我想返回一个导致规则被取消的苹果列表(在本例中为坏苹果)。请添加Store和numberOfBadApples声明,以便您可以了解“坏苹果列表”的含义。当然,商店里有一张单子吗?如何访问?您可以通过变量
s
访问存储
,那么s.getBadApples()如何?