A possible design pattern to consider:
Facing a similar problem (range testing ICAO Squawk values with sparseness), I too was confounded by the rather messy look of the code.
My solution was a static function that performed a range test, then simply called that to compute the 'between' test (if there is a Java between function, I don't know it...). Here are snippets of how I solved this; not a good pattern for everything but maybe this sparks an idea for another solution.
/**
* Range test shorthand
*
* @param value - value to test
* @param min - lower bound
* @param max - upper bound
*
* @return true | false
*/
private static boolean inRange(int value, int min, int max){
return min <= value && value <= max;
}
This is how I used it:
// not a pre-defined code... run some range tests next to quess
if (inRange(squawk,41,57)) {
message = "test";
}
else if (inRange(squawk,100,400)){
message = "Unique Purpose and Experimental activities"; // ud 17-OCT
}
else if (inRange(squawk,100,700)){ // Note! this is an overlap defined IN Order 7110.66E
message = "Oceanic Airspace"; // ud 17-OCT
}
else if (inRange(squawk,1207,1272)){
message = "DVFR Aircraft (USA)"; // ud 17-OCT
}
else if (inRange(squawk,1273,1275)){
message = "Calibration Performance Monitoring Equipment";
}
[...]
Using simple cascading would not work for me since it's a sparse set, and there is also a map involved... (here is part of that, for reference):
private static final Map<Integer,String> codes;
static {
codes = new HashMap<Integer,String>();
/* unremarkable codes */
codes.put(0, "");
codes.put(0000, ""); // there message defined for 0000 in 7110.66E spec, but I'm using an empty string
codes.put(0021, "VFR below 5000ft.");
codes.put(0022, "VFR above 5000ft.");
codes.put(0033, "Parachute Drop Operations");
codes.put(0100, "Airport Flight Operations");
codes.put(0500, "External ARTCC subsets");
codes.put(0600, "External ARTCC subsets");
codes.put(0700, "External ARTCC subsets");