/** * Get the enum value with the passed name * * @param <ENUMTYPE> The enum type * @param aClass The enum class * @param sName The name to search * @param aDefault The default value to be returned, if the name was not found. * @return The default parameter if no enum item with the given name is present. */ @Nullable public static <ENUMTYPE extends Enum<ENUMTYPE> & IHasName> ENUMTYPE getFromNameOrDefault( @Nonnull final Class<ENUMTYPE> aClass, @Nullable final String sName, @Nullable final ENUMTYPE aDefault) { ValueEnforcer.notNull(aClass, "Class"); if (StringHelper.hasText(sName)) for (final ENUMTYPE aElement : aClass.getEnumConstants()) if (aElement.getName().equals(sName)) return aElement; return aDefault; }