EnumUtils { @SuppressWarnings("unchecked") public static <T extends IKeyEnum> T getValue(final int pKey, final Class<T> pClass) { for (IKeyEnum val : pClass.getEnumConstants()) { if (val.getKey() == pKey) { return (T) val; } } LOGGER.error("Unknow value:" + pKey + " for Enum:" + pClass.getName()); return null; } private  EnumUtils(); @SuppressWarnings("unchecked") static T getValue(final int pKey, final Class<T> pClass);  }
@Test public void testEnum() { Assertions.assertThat(EnumUtils.getValue(100000, CountryCodeEnum.class)).isNull(); Assertions.assertThat(EnumUtils.getValue(250, CountryCodeEnum.class)).isEqualTo(CountryCodeEnum.FR); }