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 findAll
iterater over the set
. It creates a new set
and 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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.