简体   繁体   English

Groovy闭包-此代码中发生了什么?

[英]Groovy closure - what is happening in this code?

As a beginner groovy developer, I am trying to understand the following lines of groovy code I've inherited: 作为一个入门的groovy开发人员,我试图了解我继承的以下groovy代码行:

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> . skillsDist对象是对类型为Set<CalculationResult>的Java对象的引用。 Each CalculationResult has an int field mValue . 每个CalculationResult都有一个int字段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 . findAll遍历该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. 它创建一个新set并添加所有值大于或等于0的元素。max操作遍历子集并搜索最大值。

The same in the second line (expect it looks for the min value). 在第二行中相同(期望它寻找最小值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM