我想检查公司班级的emp id中是否存在学生ID 。如果 empidlist 中存在 studentid,那么我应该抛出错误。
我以两种不同的方式尝试过:
第一
rule :"check the student id is present in empid"
when
$company : Company()
accumulate(Employee(empid !=null, empid : empid) from $company.emplist;
empidlist: collectList(empid))
accumulate(Student(stdid !=null, empidlist.contains(stdid),stdid : stdid) from $company.stdlist; stdidlist: collectList(stdid);stdidlist.size()>0)
then
//throw error.
运行它时,我收到以下错误:cannot use .contains() from accumulate。
第二
function boolean isStudentidExists(List<String> stdidlist, List<String> empidlist){
for (String s : stdidlist) {
for (String res : empidlist) {
if (res.equals(s))
return true;
}
}
return false;
}
rule :"check the student id is present in empid"
when
$company : Company()
accumulate(Employee(empid !=null, empid : empid) from $company.emplist; empidlist: collectList(empid))
accumulate(Student(stdid !=null,stdid : stdid) from $company.stdlist; stdidlist: collectList(stdid))
eval(isStudentidExists(stdidlist,empidlist))
then
//throw error.
这里不是在阅读列表。我尝试在我的函数中仅将类型指定为 List<> ,但这仍然不起作用。
Class Company {
private List<Employee> emplist;
private List<Student> stdlist;
}
Class Employee {
private String empid;
}
Class Student {
private String stdid;
}