Wednesday 20 June 2007

Constant++


// FYI: Constants is a class (not an interface)

if (ts != null && ts.getTs().intValue() == 1){
nbPc = Constants.CONST1A;
Constants.CONST1A = Constants.CONST1A + 1;

nbPs = Constants.CONST1B;
Constants.CONST1B = Constants.CONST1B + 1;
} else if (ts != null && ts.getTs().intValue() == 2){
nbPc = Constants.CONST2A;
Constants.CONST2A = Constants.CONST2A + 1;

nbPs = Constants.CONST2B;
Constants.CONST2B = Constants.CONST2B + 1;
} else if (ts != null && ts.getTs().intValue() == 3){
nbPc = Constants.CONST3A;
Constants.CONST3A = Constants.CONST3A + 1;

nbPs = Constants.CONST3B;
Constants.CONST3B = Constants.CONST3B + 1;
} else if (ts != null && ts.getTs().intValue() == 4){
nbPc = Constants.CONST4A;
Constants.CONST4A = Constants.CONST4A + 1;

nbPs = Constants.CONST4B;
Constants.CONST4B = Constants.CONST4B + 1;
}

Oh that ignominious code.
First, it appears that if some fields were in a Class named Constants, they will be final.
The ts variable can be tested different from null only once.
Use myVariable++ instead of myVariable = myVariable + 1
At last, the use of if-statement to compare ts.getTs().intValue() to an int is not the best technic.

No comments: