As a beginner groovy developer, I am trying to understand the following lines of groovy code I’ve inherited:
maxCount = skillsDist.findAll {it.mValue.value >= 0 }.max { it.mValue.value }.mValue.value
minCount = skillsDist.findAll { it.mValue.value >= 0 }.min { it.mValue.value }.mValue.value
The skillsDist object is a reference to a Java object of type Set<CalculationResult>. Each CalculationResult has an int field mValue.
The part I am struggling with is the closures after the max and min. Obviously, I am guessing it finds the min and max values out of the set but I need to modify this and am uncomfortable not understanding this.
Thanks!
The
findAlliterater over theset. It creates a newsetand adds all elements with a value bigger or equals than 0. The max operation iterates trough the subset and searches the maximum value.The same in the second line (expect it looks for the min value).