Class EnumUtils
java.lang.Object
com.blackrook.gloop.opengl.struct.EnumUtils
Some utility methods for Enums.
- Author:
- Matthew Tropiano
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K, E extends Enum<E>>
voidaddToMap(Map<K, ? super E> map, Class<E> enumClass, BiFunction<Integer, E, K> keyProviderFunc) Adds all values in an enum to an existing ordinal map.static <E extends Enum<E>>
voidaddToNameMap(Map<String, ? super E> map, Class<E> enumClass) Adds all values in an enum to an existing name map.static <E extends Enum<E>>
voidaddToOrdinalMap(Map<Integer, ? super E> map, Class<E> enumClass) Adds all values in an enum to an existing ordinal map.static <E extends Enum<E>>
voidaddToOrdinalMap(Map<Integer, ? super E> map, Class<E> enumClass, int offset) Adds all values in an enum to an existing ordinal map.createCaseInsensitiveEnumMap(Class<E> enumClass, BiFunction<Integer, E, String> nameProviderFunc) Turns a set of enums into a map of case-insensitive-resolving Strings to enum value.createCaseInsensitiveNameMap(Class<E> enumClass) Turns a set of enums into a map of case-insensitive-resolving Strings to enum value.createIntegerMap(Class<E> enumClass, BiFunction<Integer, E, Integer> idProviderFunc) Turns a set of enums into a map of integer id to enum.static <C extends Comparable<C>, E extends Enum<E>>
SortedMap<C, E> createMap(Class<E> enumClass, BiFunction<Integer, E, C> keyProviderFunc) Turns a set of enums into a map of some kind of key to enum.createNameMap(Class<E> enumClass) Turns a set of enums into a map of String to enum value.createOrdinalMap(Class<E> enumClass) Turns a set of enums into a map of ordinal to enum value.createOrdinalMap(Class<E> enumClass, int offset) Turns a set of enums into a map of ordinal to enum value.static <T extends Enum<T>>
TgetEnumInstance(String value, Class<T> enumClass) Returns the enum instance of a class given class and name, or null if not a valid name.
-
Constructor Details
-
EnumUtils
public EnumUtils()
-
-
Method Details
-
getEnumInstance
Returns the enum instance of a class given class and name, or null if not a valid name. If value is null, this returns null.- Type Parameters:
T- the Enum object type.- Parameters:
value- the value to search for.enumClass- the Enum class to inspect.- Returns:
- the enum value or null if the target does not exist.
-
addToMap
public static <K, E extends Enum<E>> void addToMap(Map<K, ? super E> map, Class<E> enumClass, BiFunction<Integer, E, K> keyProviderFunc) Adds all values in an enum to an existing ordinal map.- Type Parameters:
K- the key type.E- an Enum type.- Parameters:
map- the target map.enumClass- the Enum class.keyProviderFunc- the function that fetches the corresponding id to use for the provided enum value. First parameter is the ordinal fromEnum.ordinal().
-
addToOrdinalMap
-
addToOrdinalMap
public static <E extends Enum<E>> void addToOrdinalMap(Map<Integer, ? super E> map, Class<E> enumClass, int offset) Adds all values in an enum to an existing ordinal map.- Type Parameters:
E- an Enum type.- Parameters:
map- the target map.enumClass- the Enum class.offset- the offset to add to each ordinal.
-
addToNameMap
-
createMap
public static <C extends Comparable<C>, E extends Enum<E>> SortedMap<C,E> createMap(Class<E> enumClass, BiFunction<Integer, E, C> keyProviderFunc) Turns a set of enums into a map of some kind of key to enum.- Type Parameters:
C- the key type; must beComparable.E- an Enum type.- Parameters:
enumClass- the Enum class.keyProviderFunc- the function that fetches the corresponding id to use for the provided enum value. First parameter is the ordinal fromEnum.ordinal().- Returns:
- the resultant, unmodifiable map.
-
createIntegerMap
public static <E extends Enum<E>> SortedMap<Integer,E> createIntegerMap(Class<E> enumClass, BiFunction<Integer, E, Integer> idProviderFunc) Turns a set of enums into a map of integer id to enum.- Type Parameters:
E- an Enum type.- Parameters:
enumClass- the Enum class.idProviderFunc- the function that fetches the corresponding id to use for the provided enum value. First parameter is the ordinal fromEnum.ordinal().- Returns:
- the resultant, unmodifiable map.
-
createOrdinalMap
-
createOrdinalMap
public static <E extends Enum<E>> SortedMap<Integer,E> createOrdinalMap(Class<E> enumClass, int offset) Turns a set of enums into a map of ordinal to enum value.Can optionally have an offset to add to them (if offset is 1, each enum maps to
enum.ordinal() + 1).- Type Parameters:
E- an Enum type.- Parameters:
enumClass- the Enum class.offset- the offset to add to each ordinal.- Returns:
- the resultant, unmodifiable map.
-
createNameMap
Turns a set of enums into a map of String to enum value. The Strings used are the enum'sEnum.name().- Type Parameters:
E- an Enum type.- Parameters:
enumClass- the Enum class.- Returns:
- the resultant, unmodifiable map.
-
createCaseInsensitiveNameMap
public static <E extends Enum<E>> SortedMap<String,E> createCaseInsensitiveNameMap(Class<E> enumClass) Turns a set of enums into a map of case-insensitive-resolving Strings to enum value. The Strings used are the enum'sEnum.name().- Type Parameters:
E- an Enum type.- Parameters:
enumClass- the Enum class.- Returns:
- the resultant, unmodifiable map.
-
createCaseInsensitiveEnumMap
public static <E extends Enum<E>> SortedMap<String,E> createCaseInsensitiveEnumMap(Class<E> enumClass, BiFunction<Integer, E, String> nameProviderFunc) Turns a set of enums into a map of case-insensitive-resolving Strings to enum value.- Type Parameters:
E- an Enum type.- Parameters:
enumClass- the Enum class.nameProviderFunc- the function that fetches the corresponding string to use for the provided enum value. First parameter is the ordinal fromEnum.ordinal().- Returns:
- the resultant, unmodifiable map.
-