Тьфу, петли и петли ... взгляните на методы коллекции Groovy.
// poor emp3 has no salaryData
def employeeNames = ['emp1', 'emp2', 'emp3']
def salaryData = [[name: 'emp1', sal: 1000], [name: 'emp2', sal: 5000], [name: 'emp1', sal: 6000], [name:'emp1', sal: 7000]]
// here's our output array variable
def output = []
// for each employee
// find all the salaryData elements where salaryData.name == employeeName
// using that list, collect just the salary value
// using that list, sum it, adding to an initial value of 0
// append a new entry in output containing the name, and total salary
employeeNames.each { employeeName ->
output << [name: employeeName, totalSalary: salaryData.findAll { sal -> sal.name == employeeName }.collect { sal -> sal.sal }.sum(0)]
}
println output
groovyconsole дает:
[[name: emp1, totalSalary: 14000], [name: emp2, totalSalary: 5000], [name: emp3, totalSalary: 0]]