public enum NumbeRollers { Min(4), Mid(5), Max(6); private final int NumbeRollersCode; private NumbeRollers(int NumbeRollersCode) { this.NumbeRollersCode = NumbeRollersCode; } public int getNumbeRollersCode() { return this.NumbeRollersCode; } public static NumbeRollers fromNumberToEnum(int number) { try{ for (NumbeRollers numbeRoller : NumbeRollers.values()) { if (numbeRoller.getNumbeRollersCode() == number) { return numbeRoller; } } }catch(NumberFormatException e){ } return Min; } }