I have different roles in my system.HODStaffNon staffI am having a form at the front end and fields shall be visible to only users with specific roles.The ShowInGui levels are like this:Show to AllShow to staff/HODShow to HODAny other do not showI am planning to write a method which will take the user role and decides the access.Could this method be better written?public boolean canBeShownInGUI(Role role, int showInGui) {    if (showInGui == 1) {        return true;    } else if (showInGui == 2 && (role == Role.HOD || role == Role.STAFF)) {        return true;    } else if (showInGui == 3 && role == Role.HOD) {        return true;    } else       return false;   }
Rewrite method to decide the ShowLevel based on roles
java
I presume Role is an enum (if it is not, it should be). An enum is a great candidate for a switch statement, and it also makes the conditions very clear:switch (role) {    case HOD:        return showInGui >= 1;    case STAFF:        return showInGui == 1 || showInGui == 2;}return showInGui == 1;Note that, if you want you can embed that logic in to the enum itself, and have a simple call to an enum method:return role.isVisible(showInGui);Additionally, if you reverse the values of the showInGui to be:0 -> nobody1 -> HOD only2 -> HOD & STAFF3 -> everyonethen your logic is simplified further to:switch (role) {    case HOD:        return showInGui >= 1;    case STAFF:        return showInGui >= 2;}return showInGui >= 3;