The following java code gives a rather high Cyclomatic Complexity. I would like to find a way to properly reduce it. How would I best do this?
To be clear, the code gets the corresponding result of a value, based on whether the value is in between two limits. The value itself could be any integer between -10000 to +200000 The problem lies mostly with the "Less Than or Equal" operators, which prevent the simple use of a library. The range between two limits can be different and we're talking ranges in the 10000s, an example interval would be [<0...10000....25000...32500...]. The ranges are rather arbitrary numbers, decided upon by the business.
You can assume that the LIMIT values are constants, defined at the beginning of the class. The same goes for the set result values. Changing them from a constant to something else is possible.
Any ideas?
private int function getBasedOnInterval(int value){
int result;
if(value <= 0){
result = RESULT1;
}else if(value <= LIMIT1){
result = RESULT2;
}else if(value <= LIMIT2){
result = RESULT3;
}else if(value <= LIMIT3){
result = RESULT4;
}else if(value <= LIMIT4){
result = RESULT5;
}else if(value <= LIMIT5){
result = RESULT6;
}else if(value <= LIMIT6){
result = RESULT7;
}else if(value <= LIMIT7){
result = RESULT8;
}else if(value <= LIMIT8){
result = RESULT9;
}else if(value <= LIMIT9){
result = RESULT10;
}else if(value <= LIMIT10){
result = RESULT11;
}else if(value <= LIMIT11){
result = RESULT12;
}else if(value <= LIMIT12){
result = RESULT13;
}else if(value <= LIMIT13){
result = RESULT14;
}else{
result = RESULT15;
}
return result;
}