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.)

  • 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 class
      code - 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 class
      code - code, may be null.
      Returns:
      the enum value, may be null when argument code is null.
    • hasEnumFromCode

      public static <T> boolean hasEnumFromCode(@Nonnull Class<T> enumClass, @Nonnull 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 <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|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

      public static <T> EnumUtil.EnumClassInfo<T> getEnumInfo(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

      public static <T> EnumUtil.EnumClassInfo<T> getEnumInfo(Class<T> enumClass, Locale locale)
      Returns enum class info.
      Type Parameters:
      T - any enum
      Parameters:
      enumClass - enum class
      locale - locale
      Returns:
      EnumClassInfo