tags:

views:

80

answers:

2

Just wonder groovy way to do value matching with default like this?

if(params.max != 10 && params.max != 20 && params.max != 30){
    params.max = 10
}
+4  A: 

params.max = [10, 20, 30].contains(params.max)) ? params.max : 10;

M. Utku ALTINKAYA
A: 

You can also use the Elvis operator (?:) which is useful in this kind of situation. It returns the 2nd value if the first value is null:

params.max = [10, 20, 30].find{ it == params.max } ?: 10
Ted Naleid