我有一个POJO实现:
public class Product{
String name;
String brand;
String company;
}
我的问题::
需要根据名称和公司从worldOfProductList获取目标产品(两个字段都已知,以便可以应用过滤器)。 从该列表中获取一个特定产品后,需要将“品牌”值存储到某个变量(可以是全局)以供将来使用。
注意::截至目前,只使用该过滤器获取唯一的产品。
我的方法是:
[condition][]Get intended Product from list = $productList: java.util.LinkedList() from collect(Products(name="abc",company="com") from worldOfProductList)
此语句正常工作,能够在sysout语句中获取我的值:
System.out.println("Brand is "+((Product)($productList.get(0)).getBrand());
但我需要在DSL中使用这个品牌价值并存储到变量中。我试过以下组合,但没有成功。
1.[condition][] Store Brand into variable=$brandVar: $productList[0].brand
2.[condition][] Store Brand into variable=Product($brandVar: $productList[0].brand)
3.[condition][] Store Brand into variable=$brandVar: ((Product)$productList.get(0)).getBrand()
答案 0 :(得分:0)
如果您希望将其作为DSL中的2个单独条目,那么您可以执行以下操作:
[condition][] Store Brand into variable= Product($brandVar: brand) from $productList
这将导致您在$productList
中拥有的每个不同产品的规则激活。在规则的RHS中,您将可以访问$brandVar
。
如果您只对品牌感兴趣而不是产品本身,那么您也可以尝试这样的事情:
[condition][]Get Brands from intended Product from list = $productList: java.util.Set() from accumulate(Products(name="abc",company="com", $brandVar: brand) from worldOfProductList, collectSet($brand))
希望有所帮助,