我想访问地图密钥并与包含或不包含的值进行比较。
// Attribute类包含一个以key和多个值形式的地图
public class Attribute {
private Map<String, List<String>> mapAttribute;
public Map<String, List<String>> getMapAttribute() {
return mapAttribute;
}
public void setMapAttribute(Map<String, List<String>> mapAttribute) {
this.mapAttribute = mapAttribute;
}
}
public class DroolsMain {
public static Attribute attribute = new Attribute();
public static void main(String[] args) throws DroolsParserException, IOException {
Map<String, List<String>> map = new HashMap<String, List<String>>();
List<String> listSubject = new ArrayList<String>();
listSubject.add("email1");
listSubject.add("email2");
map.put("Subject", listSubject);
List<String> listFrom = new ArrayList<String>();
listFrom.add("Sathish Kumar");
map.put("From", listFrom);
attribute.setMapAttribute(map);
}
//...
workingMemory.insert(attribute);
}
Rules.drl
rule "Get Subject key: with particular value"
when
attribute : Attribute($mapAttribute : mapAttribute)
//I want to compare value of **"Subject"**
List( this.contains( "email1")) from $mapAttribute.get("Subject")
then
System.out.println("Rule run successfully Getting key with particular value");
end
我没有在Rule.drl中获得该值。它显示不符合任何规则。所以请帮助找到价值。
答案 0 :(得分:1)
该列表包含&#34; email1&#34;和&#34; email2&#34;但是你正在检查&#34;电子邮件&#34;。
但规则必须写成
fc
如果&#39;来自&#39;是一个List,它是自动解开的。这很有用,但偶尔会令人惊讶。 (如果您需要整个列表怎么办?)