December 16, 2010

Since Groovy 1.7.6 we can use the min() and max() methods on a Map. We use a closure to define the condition for a minimum or maximum value. If we use two parameters in the closure we must do a classic comparison. We return a negative value if the first parameters is less than the second, zero if they are both equal, or a positive value if the first parameter is greater than the second parameter. If we use a single parameter we can return a value that is used as Comparable for determining the maximum or minimum entry in the Map.