@Test public void testEnum() { Assertions.assertThat(EnumUtils.getValue(100000, CountryCodeEnum.class)).isNull(); Assertions.assertThat(EnumUtils.getValue(250, CountryCodeEnum.class)).isEqualTo(CountryCodeEnum.FR); }
@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; }
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; } }
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(); }
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); }
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);  }