In apps with ecuacion library the extended enum format is used.
The format of enums created by code-generator are also that kind.
It has following features:
- To have
codeproperty which is used for saving the value in database, identifing html dropdown menu elements and others. - To have
display namefor each enum value, which is obtained byPropertyFFileUtil.getEnumName().
Since enums have these features, EnumUtils from apache-commons-lang is not used in the library (which does not mean its use is banned.)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classContains Enum Class info.static classContains Enum value info. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TgetEnumFromCode(Class<T> enumClass, String code) Obtains the enum value from the code.static <T> TgetEnumFromCodeOrNullIfCodeIsNull(Class<T> enumClass, String code) Obtains the enum value from the code.static <T> EnumUtil.EnumClassInfo<T> getEnumInfo(Class<T> enumClass) Returns enum class info.static <T> EnumUtil.EnumClassInfo<T> getEnumInfo(Class<T> enumClass, Locale locale) Returns enum class info.getListForHtmlSelect(Class<T> enumClass, Locale locale, String optionsString) Returns paires of a code and a display name.static <T> booleanhasEnumFromCode(Class<T> enumClass, String code) Returns true if the argument code exists in the enum class.
-
Constructor Details
-
EnumUtil
public EnumUtil()
-
-
Method Details
-
getEnumFromCode
@Nonnull public static <T> T getEnumFromCode(@Nonnull Class<T> enumClass, @RequireNonnull String code) Obtains the enum value from the code.The return value may be null when the code is null.
When the code is not null and the enum value corresponding to the code is not found, throw RuntimeExceptionWithMessageId.- Type Parameters:
T- any enum class- Parameters:
enumClass- enum classcode- code- Returns:
- the enum value
-
getEnumFromCodeOrNullIfCodeIsNull
@Nullable public static <T> T getEnumFromCodeOrNullIfCodeIsNull(@Nonnull Class<T> enumClass, @Nullable String code) Obtains the enum value from the code.The return value may be null when the code is null.
When the code is not null and the enum value corresponding to the code is not found, throw RuntimeExceptionWithMessageId.- Type Parameters:
T- any enum class- Parameters:
enumClass- enum classcode- code, may be null.- Returns:
- the enum value, may be null when argument code is null.
-
hasEnumFromCode
Returns true if the argument code exists in the enum class.- Type Parameters:
T- any enum class- Parameters:
enumClass- enum classcode- code- Returns:
- enum value
-
getListForHtmlSelect
@Nonnull public <T> List<String[]> getListForHtmlSelect(@Nonnull Class<T> enumClass, @Nullable Locale locale, @Nullable String optionsString) Returns paires of a code and a display name. This is mainly used for the dropdown item in html or other UI windows.You can designate an option to filter the elements in the enum class.
You can set options as follows:kinds of options option description including=value1|value2 "value1", "value2" are names of the elements of the enum. Multiple selections of values available excluding=value1|value2 Multiple selections of values available firstCharOfCodeEqualTo=3|4 "3", "4" is codes of the elements of the enum. Multiple selections of values available firstCharOfCodeLessThanOrEqualTo=3 "3", "4" are the first character of codes of the elements of the enum. Multiple selections of values available firstCharOfCodeGreaterThanOrEqualTo=3 "3", "4" are the first character of codes of the elements of the enum. Multiple selections of values available You can use only 1 option from the above. you cannot use multiple options at once. "|" is the separator of values.
-
getEnumInfo
Returns enum class info.Locale.getDefault()is used for display name of the enum.- Type Parameters:
T- any enum- Parameters:
enumClass- enum class- Returns:
- EnumClassInfo
-
getEnumInfo
Returns enum class info.- Type Parameters:
T- any enum- Parameters:
enumClass- enum classlocale- locale- Returns:
- EnumClassInfo
-