Package dev.aherscu.qa.testing.utils
Class EnumUtils
- java.lang.Object
-
- dev.aherscu.qa.testing.utils.EnumUtils
-
public final class EnumUtils extends Object
Enumeration utilities.- Author:
- aherscu
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EnumUtils.NoSuchMemberException
If no matching enum member found.static class
EnumUtils.Separator
Allowed separators to be used in enumeration member names in order to allow mapping to/from textual representations and to allow prettifying.
-
Field Summary
Fields Modifier and Type Field Description static EnumUtils.Separator
DEFAULT_ENUM_PREFIX
Default prefix to use for mapping members to their textual representation and vice-versa.static EnumUtils.Separator
DEFAULT_ENUM_SEPARATOR
Default word separator to use for prettifying.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E extends Enum<E>>
EfromString(Class<E> enumType, String name)
Maps a name to an enumeration member; usesDEFAULT_ENUM_PREFIX
as a prefix.static <E extends Enum<E>>
EfromString(Class<E> enumType, String name, EnumUtils.Separator prefix)
Maps a name to an enumeration member.static <E extends Enum<E>>
Stringprettify(E e)
Prettifies an enumeration member; usesDEFAULT_ENUM_SEPARATOR
as a separator.static <E extends Enum<E>>
Stringprettify(E e, @NotNull EnumUtils.Separator separator)
Prettifies an enumeration member.static <E extends Enum<E>>
StringtoString(E e)
Maps an enumeration member to its textual representation; usesDEFAULT_ENUM_PREFIX
as the prefix.static <E extends Enum<E>>
StringtoString(E e, EnumUtils.Separator prefix)
Maps an enumeration member to its textual representation.
-
-
-
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)
Maps a name to an enumeration member; usesDEFAULT_ENUM_PREFIX
as a prefix.- Parameters:
enumType
- type of enumeration, not nullname
- the member name, null returns null- Returns:
- the referenced member
- Throws:
EnumUtils.NoSuchMemberException
- if the member was not found- See Also:
fromString(Class, String, Separator)
-
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 nullname
- the member name, null returns nullprefix
- 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; usesDEFAULT_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 memberseparator
- 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; usesDEFAULT_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 memberprefix
- the prefix to be prepended to the referenced member name- Returns:
- its textual representation
-
-