Class EnumUtils


  • public final class EnumUtils
    extends Object
    Enumeration utilities.
    Author:
    aherscu
    • Field Detail

      • DEFAULT_ENUM_PREFIX

        public static final EnumUtils.Separator DEFAULT_ENUM_PREFIX
        Default prefix to use for mapping members to their textual representation and vice-versa. This prefix is required in order to allow mapping member names beginning with a digit.
      • DEFAULT_ENUM_SEPARATOR

        public static final EnumUtils.Separator DEFAULT_ENUM_SEPARATOR
        Default word separator to use for prettifying.
    • Method Detail

      • fromString

        public static <E extends Enum<E>> E fromString​(Class<E> enumType,
                                                       String name,
                                                       EnumUtils.Separator prefix)
        Maps a name to an enumeration member.
        Parameters:
        enumType - type of enumeration, not null
        name - the member name, null returns null
        prefix - a prefix to add in order to map the name to a member
        Returns:
        the referenced member
        Throws:
        EnumUtils.NoSuchMemberException - if the member was not found
      • prettify

        public static <E extends Enum<E>> String prettify​(E e)
        Prettifies an enumeration member; uses DEFAULT_ENUM_SEPARATOR as a separator.
        Parameters:
        e - the enumeration member
        Returns:
        the pretiffied name
      • prettify

        public static <E extends Enum<E>> String prettify​(@NotNull
                                                          E e,
                                                          @NotNull
                                                          @NotNull EnumUtils.Separator separator)
        Prettifies an enumeration member.

        Example: SOME_ENUM_MEMBER will be prettified as Some Enum Member

        Parameters:
        e - the enumeration member
        separator - the separator to use for separating words
        Returns:
        the pretiffied name
      • toString

        public static <E extends Enum<E>> String toString​(E e)
        Maps an enumeration member to its textual representation; uses DEFAULT_ENUM_PREFIX as the prefix.
        Parameters:
        e - the enumeration member
        Returns:
        its textual representation
      • toString

        public static <E extends Enum<E>> String toString​(E e,
                                                          EnumUtils.Separator prefix)
        Maps an enumeration member to its textual representation.
        Parameters:
        e - the enumeration member
        prefix - the prefix to be prepended to the referenced member name
        Returns:
        its textual representation