ilog规则中的ArrayList

时间:2014-09-05 13:35:45

标签: rule-engine ilog jrules

我正在使用ilog规则。我想验证一个数组对象列表中的字段。

喜欢,

class Company {
    List<Employee> employee;
}

class Employee {
    String Name;
    int age;
}

这里我要验证年龄字段是否为负数。我将公司对象作为输入参数传递,

definitions
    set 'Company' to 'The Company to validate' ;
    set 'Employees' to employee working for 'Company'

现在我如何迭代员工,这是一个arraylist并检查年龄验证。请帮帮我。

1 个答案:

答案 0 :(得分:0)

使用&#39; in&#39; BAL构造将您的集合中的单个员工绑定到 definitions 语句中的变量,然后为该员工编写验证规则。

有关您的IBM ODM版本,请参阅知识中心/信息中心,例如:

IBM Operational Decision Manager 8.6.0>Operational Decision Manager version 8.6>Decision Server Rules>Reference>Rule Designer reference>Rule languages>Business Action Language (BAL)>BAL constructs>in

您可以尝试以下方式:

definitions 
    set 'employee' to an employee in the employees of 'the company' ; 
if
    the age of employee is less than 0
then
    print "Age of employee " + the name of employee + "' is negative: " + the age of employee ; 
else
    print "Age of employee " + the name of employee + "' is OK: " + the age of employee ;