Class EnumUtil
java.lang.Object
jp.ecuacion.lib.core.util.EnumUtil
Provivdes utility methods for ecuacion library enums.
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. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TgetEnumFromCode(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.
-
Method Details
-
getEnumFromCode
@Nonnull public static <T> T getEnumFromCode(@RequireNonnull Class<T> enumClass, @RequireNonnull String code) Obtains the enum value from the code.When the enum value corresponding to the code is not found, throw RuntimeException.
- Type Parameters:
T- any enum class- Parameters:
enumClass- enum classcode- code- Returns:
- the enum value
-
hasEnumFromCode
public static <T> boolean hasEnumFromCode(@RequireNonnull Class<T> enumClass, @RequireNonnull String code) 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 static <T> List<String[]> getListForHtmlSelect(@RequireNonnull 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
@Nonnull public static <T> EnumUtil.EnumClassInfo<T> getEnumInfo(@RequireNonnull Class<T> enumClass) 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
@Nonnull public static <T> EnumUtil.EnumClassInfo<T> getEnumInfo(@RequireNonnull Class<T> enumClass, @Nullable Locale locale) Returns enum class info.- Type Parameters:
T- any enum- Parameters:
enumClass- enum classlocale- locale- Returns:
- EnumClassInfo
-