Drools Expert - mvel - LHS - advanced part 2

From Training Material
Jump to navigation Jump to search
title
Drools Expert - mvel - RHS - advanced part 2
author
Bernard Szlachta (NobleProg Ltd)

Drools Expert - mvel - RHS - advanced Training Materials


Collect Functions 3 ⌘

Find departments employing more than 3 people.
寻找雇员多于3人的部门

rule "Sample"
when 
 $d : Dept()
 $emps : ArrayList (size > 3)
       from collect (Emp(deptno == $d.deptno))
then    
  System.out.println($d.dname )
end

Exercise 1⌘

Find job posts having more than 2 employees.
寻找雇员多于2人的职位

Exercise 2 ⌘

Rewrite the exercise 1 using accumulate function
使用accumulate函数重写练习1

Custom Accumulate Function | 自定义 Accumulate 函数 。⌘

rule "Sample custom sum function"
when
d : Dept()
$total : Number( doubleValue > 100 )
  from accumulate( Emp( deptno == d.deptno, $value : sal ),
  init( double total = 0; ),
  action( total += $value; ),
  reverse( total -= $value; ),
  result( total ) )
then
  System.out.println(d.dname + " department has sum of salaries " + $total);
end


Exercise 3

Following the example, write variance function and calculate variance of the salaries
参照例子,书写方差(variance)函数并计算工资的方差

Exercise 4

Print employees order by their salary
打印出所有雇员,并按照工资排序

Next Module

Drools Expert - mvel - LHS - advanced part 3