我想检查一下学生身份是否存在于公司班级的emp id中。如果在空列表中存在学生,那么我应该抛出错误。
我试过两种不同的方法:
第一个
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.在运行它时,我得到了以下错误:无法使用.contains()。
第二位
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;
}发布于 2018-01-04 05:48:10
至于功能,请使用
function boolean isStudentidExists(List stds, List emps ){
for( Object s : stds) {
if( emps.contains( s ) ) return true;
}
return false;
}要使用逻辑,建议将“学生”和“雇员”对象作为事实插入。
rule check
when
Company( $el: emplist, $sl: stdlist )
Student( $sid: stdid, this memberOf $sl )
Employee( empid == $sid, this memberOf $el )
then
// error
endhttps://stackoverflow.com/questions/48084148
复制相似问题