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
}
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
}
params.max = [10, 20, 30].contains(params.max)) ? params.max : 10;
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