tags:

views:

84

answers:

2

I have the following switch statement

    switch (points) {
       case 0: name = "new"; break;
       case 1..14: badgeName = "bronze-coin"; break;
       case 15..29: badgeName = "silver-coin"; break;
       default: badgeName = "ruby";
    }

I'd like the first case (case 0) to include points less than or equal to 0. How can I do this in Groovy?

+1  A: 
case { it instanceof Integer && it < 0 }:
UltraVi01
it <= 0 surely?
tim_yates
@Tim - that doesn't work
Don
Doh! Missed the first case :-/
tim_yates
A: 
switch(points)
{
    case Integer.MIN_VALUE..0: badgeName = "new"; break;
    case 1..14: badgeName = "bronze-coin"; break;
    case 15..29: badgeName = "silver-coin"; break;
    default: badgeName = "ruby";
}
J. Skeen