尝试将累积函数 (intValue) 的结果插入到 hashmap<String, Integer>() 时出错
Error when trying to insert the result of a accumulate function(intValue) into a hashmap<String, Integer>()
我试图将一个值插入到 Hashmap() 中,但是当我试图将累积函数的结果(drl 文件中的 $totals)作为 Hashmap 的值时,我的测试用例失败了。我也试过 Integer.valueOf($totals) 而不是 $totals 没有运气。
我的 drl 文件包含:
rule "calculate total per item"
no-loop
when
$o : Order( $lines : orderLines)
$ol : OrderLine(this memberOf $lines.values() , quantity > 0)
$totals : Number(intValue > 0) from accumulate (
OrderLine($qty : quantity, item.barcode == $ol.getItem().getBarcode()) from $lines.values(),
sum($qty)
)
then
System.out.println("total: " + $totals); //prints out total: 7.0
modify($o){
getPerItems().put($ol.getItem().getBarcode(), $totals); //this line throws an error
//getPerItems().put($ol.getItem().getBarcode(), 1 ); // If I replace $totals with a number, it works
}
end
我的订单class
public class Order {
private HashMap<Integer, OrderLine> orderLines = new HashMap<Integer, OrderLine>();
private HashMap<String, Integer> perItems = new HashMap<String, Integer>();
...
public HashMap<String, Integer> getPerItems() {
return perItems;
}
}
有什么解决这个问题的建议吗?
试试这个绑定:
Number($totals : intValue > 0)
如果您将错误消息逐字添加到您的问题中,将会有所帮助。
"Throws an error" - 是指 "throws an exception" 还是 "reports an error"。何时何地...?
我试图将一个值插入到 Hashmap() 中,但是当我试图将累积函数的结果(drl 文件中的 $totals)作为 Hashmap 的值时,我的测试用例失败了。我也试过 Integer.valueOf($totals) 而不是 $totals 没有运气。
我的 drl 文件包含:
rule "calculate total per item"
no-loop
when
$o : Order( $lines : orderLines)
$ol : OrderLine(this memberOf $lines.values() , quantity > 0)
$totals : Number(intValue > 0) from accumulate (
OrderLine($qty : quantity, item.barcode == $ol.getItem().getBarcode()) from $lines.values(),
sum($qty)
)
then
System.out.println("total: " + $totals); //prints out total: 7.0
modify($o){
getPerItems().put($ol.getItem().getBarcode(), $totals); //this line throws an error
//getPerItems().put($ol.getItem().getBarcode(), 1 ); // If I replace $totals with a number, it works
}
end
我的订单class
public class Order {
private HashMap<Integer, OrderLine> orderLines = new HashMap<Integer, OrderLine>();
private HashMap<String, Integer> perItems = new HashMap<String, Integer>();
...
public HashMap<String, Integer> getPerItems() {
return perItems;
}
}
有什么解决这个问题的建议吗?
试试这个绑定:
Number($totals : intValue > 0)
如果您将错误消息逐字添加到您的问题中,将会有所帮助。
"Throws an error" - 是指 "throws an exception" 还是 "reports an error"。何时何地...?