Class EnumUtil

java.lang.Object
jp.ecuacion.lib.core.util.EnumUtil

public class EnumUtil extends Object
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:

  1. To have code property which is used for saving the value in database, identifing html dropdown menu elements and others.
  2. To have display name for each enum value, which is obtained by PropertyFFileUtil.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.)

  • 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 class
      code - 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 class
      code - 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|value2Multiple 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 class
      locale - locale
      Returns:
      EnumClassInfo