[英]Compare two same object value which is present in HashMap in drools rule
包含鍵和值的屬性類:
public class Attribute {
private String key;
private String value;
//setter and getter method
}
主班
public class DroolsMain {
public static HashMap<String , Attribute> hashMapAttribute = new HashMap<String , Attribute>();
public static void main(String[] args) throws DroolsParserException, IOException {
String Keys[] = {"From" , "To" , "Subject" };
String attributesValues[] = { "Sathish" ,"aranjan" , "email" };
for(int i =0;i<Keys.length;i++)
{
Attribute attribute = new Attribute();
attribute.setKey(Keys[i]);
attribute.setValue(attributesValues[i]);
hashMapAttribute.put("" + i, attribute);
}
//...
workingMemory.insert(hashMapAttribute);
}
}
在rule.drl文件中,我想將一個對象的鍵值與HashMap中存在的另一種相似類型的對象進行比較。
rule.drl
rule "Rule 1:"
when
$mapAttribute : Map()
$entry : Entry() from $mapAttribute.entrySet()
$attribute : Attribute() from $entry.getValue()
$attribute1 : Attribute(this != $attribute) from $entry.getValue()
Boolean(booleanValue == true) from (($attribute.getKey contains("From") && $attribute.getValue contains("Sathish")) && ($attribute1.getKey contains("Subject") && $attribute1.getValue contains("email")))
then
System.out.println("Rule 1 run successfully ");
end
我如何比較兩個對象的值。 請幫助我找到解決方案。
我從更改rule.drl文件中獲得了解決方案:
rule "Rule 1:"
when
$mapAttribute : Map()
$entry : Entry() from $mapAttribute.entrySet()
$attribute : Attribute() from $entry.getValue()
$mapAttribute1 : Map()
$entry1 : Entry() from $mapAttribute1.entrySet()
$attribute1 : Attribute() from $entry1.getValue()
Boolean(booleanValue == true) from (($attribute.getKey contains("From") && $attribute.getValue contains("Sathish")) && ($attribute1.getKey contains("Subject") && $attribute1.getValue contains("email")))
then
System.out.println("Rule 1 run successfully ");
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.