Drools - 提取嵌入在地图中的地图

Drools - extract Map embedded inside a Map

这是我的数据结构:

public class Premium{

    private Map<String,Map<String,String>> valuesMap = new HashMap<String,Map<String,String>>();
    
    public Map<String, Map<String, String>> getValuesMap() {
       return valuesMap;
    }
}

将出现在此 'valuesMap' 中的示例值:

Map<String,String> m1= new HashMap<String,String>();
m1.put("death","100");
m1.put("income","50");

valuesMap.put("Male",m1);
valuesMap.put("Female",m2);
....

所以我苦苦挣扎的地方是如何提取嵌入在 'valuesMap' 中的地图 'm1' 以显示“男性”? 一旦我能做到这一点,我就会考虑从 'm1'

中提取值

这是我尝试过的方法,但似乎没有任何效果...

rule "rule#7 testing me 001 "
when
    // below line extracts 'valuesMap' from Premium object
    $pr:Premium($masterMap:valuesMap) 

    // no error but does not go into 'then' and print SOP
    //$map :Map(this["Male"]);
    //$map :Map(this["Male"] != null);
    
    // error : java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.Boolean
    //$map : Map(this["Male"] ) from $masterMap
    
    // prints Values Map and not the embedded map for both the below attempts
    //$map : Map(this["Male"] != "") from $masterMap
    //$map : Map(this["Male"] != null ) from $masterMap
    
    // tried java way but getting error : Unable to resolve ObjectType '$masterMap.get' : [Rule name='rule#7 testing me 001 ']
    //$map :  $masterMap.get("Male");
    
    // no error but did not fire then condition and print sop 
    //$map :  Map($masterMap.get("Male"));

    // error : Unable to resolve ObjectType '$masterMap.getGet' : [Rule name='rule#7 testing me 001 ']
    //$map :  $masterMap.getGet("Male");

    //error : Unable to resolve ObjectType '$masterMap.get' : [Rule name='rule#7 testing me 001 ']
    //$map :  $masterMap.get("Male")  from $masterMap
then   
    System.out.println("rule#7 map " + $map);
end
$pr: Premium( $masterMap: valuesMap )
Map( $male: this["Male"] ) from $masterMap

您真的应该尽量避免在您的规则中使用地图。坦率地说,嵌套地图结构通常是不好的做法。在规则中,地图的性能极差——很多年前 (10+) 是 s.o.p。将地图传递给规则,但后来我们发现它有多糟糕。 ;)