Drools可以使用以下代码返回匹配的规则列表,但是它可以返回没有匹配规则或没有匹配规则的规则集吗?如果是,怎么办?在代码中,我想知道是否没有规则在特定规则集中匹配或执行。
import java.util.ArrayList;
import java.util.List;
import org.kie.api.event.rule.AfterMatchFiredEvent;
import org.kie.api.event.rule.DefaultAgendaEventListener;
import org.kie.api.runtime.rule.Match;
/**
* Wrapper to log matched rules for input request.
*
*/
public class DroolsResponseReader extends DefaultAgendaEventListener {
private List<Match> matchList = new ArrayList<Match>();
boolean isRuleFired() {
return matchList.size() > 0;
}
@Override
public void afterMatchFired(final AfterMatchFiredEvent event) {
matchList.add(event.getMatch());
}
public String rulesFiredToString() {
if(matchList.size() == 0) {
return "No Rule Fired!";
} else {
StringBuilder matches = new StringBuilder("Rule Fired : ");
for (Match match : matchList) {
matches.append("\nRule: ").append(match.getRule().getName());
}
return matches.toString();
}
}