绑定到地图条目
Binding to Map entry
我有这样的规则maxNumConsecutiveCubicCustomersPerLocation
:
Customer(..., $location: location, $consecAndWaitingMap: consecAndWaitingMap)
我想做的就是用键 $location
(这是一个枚举类型)检索 $consecAndWaitingMap
的 entry
。
在规则的 then
部分,我可以轻松打印条目 System.out.println($location+": "+$consecAndWaitingMap.get($location));
,但我可能不会绑定到它:
$consec: $consecAndWaitingMap.get($location)
给出的编译时错误:
Unable to resolve ObjectType '$consecAndWaitingMap.get'
我已经导入了所有必要的 类 (import java.util.Map; import ...Customer;
),所以这不是问题所在。其他解决方法,例如修复 $location
,或通过 []
访问,或首先绑定到 Customer
,然后使用 consecAndWaitingMap: HashMap() from $customer.getConsecAndWaitingMap()
检索我的地图,会产生类似的错误。
如何绑定到 $consecAndWaitingMap.get($location)
?如果那不可能,有什么解决方法吗?
您可以将您的条目绑定在与其他变量相同的行中。以下代码应该有效:
Customer(..., $location: location, $consecAndWaitingMap: consecAndWaitingMap, $mapEntry : consecAndWaitingMap.get(location))
注意绑定新变量时不能使用其他变量,需要使用实际的"location"字段。 (用“$location”替换"location"会报错)
我有这样的规则maxNumConsecutiveCubicCustomersPerLocation
:
Customer(..., $location: location, $consecAndWaitingMap: consecAndWaitingMap)
我想做的就是用键 $location
(这是一个枚举类型)检索 $consecAndWaitingMap
的 entry
。
在规则的 then
部分,我可以轻松打印条目 System.out.println($location+": "+$consecAndWaitingMap.get($location));
,但我可能不会绑定到它:
$consec: $consecAndWaitingMap.get($location)
给出的编译时错误:
Unable to resolve ObjectType '$consecAndWaitingMap.get'
我已经导入了所有必要的 类 (import java.util.Map; import ...Customer;
),所以这不是问题所在。其他解决方法,例如修复 $location
,或通过 []
访问,或首先绑定到 Customer
,然后使用 consecAndWaitingMap: HashMap() from $customer.getConsecAndWaitingMap()
检索我的地图,会产生类似的错误。
如何绑定到 $consecAndWaitingMap.get($location)
?如果那不可能,有什么解决方法吗?
您可以将您的条目绑定在与其他变量相同的行中。以下代码应该有效:
Customer(..., $location: location, $consecAndWaitingMap: consecAndWaitingMap, $mapEntry : consecAndWaitingMap.get(location))
注意绑定新变量时不能使用其他变量,需要使用实际的"location"字段。 (用“$location”替换"location"会报错)