0
我想访问地图键并与包含或不包含的值进行比较。检查Drools中的地图中的特定元素
//属性类包含键和多个值
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值。它显示不符合任何规则。所以请帮助找到价值。
我没有得到结果先生。它显示不符合规则。 – Ashish
我的不好。见编辑的答案。 – laune
谢谢,它工作... – Ashish