Drools Expert - mvel - LHS - advanced part 2
Jump to navigation
Jump to search
Drools Expert - mvel - RHS - advanced Training Materials
Copyright Notice
Copyright © 2004-2023 by NobleProg Limited All rights reserved.
This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise.
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
打印出所有雇员,并按照工资排序