i have a question for call management.
I get a message with a payload of 3 bytes in a byte[]. Different bits in there leads to calling another method. I did it with a logical AND between the byte and a shiftet 1 to get the value of the bit. I used if elseif etc. to call the specific method. Is there another possibilty to realise it, maybe a HashMap or something?
At least im forced to use max. Java 1.4
Greetings,
fnobbi
It depends on how many different methods you are calling. If it’s less than (I’m guessing here) 20, I would use simple bit-mask tests on a
int(which is 4 bytes – use the lower 3) withif().For example:
If you’re only calling one method then stopping, you’ll want to use
elsesbetween theifs, and may also want to order the tests in order of most-frequently expected first.Using a hashmap wouldn’t be that much faster than these extremely fast operations IMHO even if you have lots of tests, and this is easier to read, debug and maintain.