Posted: 21 Dec 2010, 17:36
I could see you do something slightly different that makes the code a little cleaner, but no less lengthy:
It makes it a little easier to add new profile types in the future. I would also recommend that this be made its own function and placed in another class so that you can call it, pass it an int and have it return an IPermissionProfile so that you can call it from places and never repeat the code, but otherwise I don't see how you could optimize it further.
Code: Select all
IPermissionProfile profile = null;
switch(Short.parseShort((userData.getUtfString("PRIVILEGE")).trim()))
{
case 1:
profile = DefaultPermissionProfile.STANDARD;
break;
case 2:
profile = DefaultPermissionProfile.MODERATOR;
break;
case 3:
profile = DefaultPermissionProfile.ADMINISTRATOR;
break;
case 0:
default:
profile = DefaultPermissionProfile.GUEST;
}
session.setProperty($permission, profile);