Package com.jeff_media.jefflib
Class EnumUtils
java.lang.Object
com.jeff_media.jefflib.EnumUtils
Enum related methods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Enum<E>,
C extends Collection<E>>
CgetEnumsFromList
(Class<E> enumClazz, List<String> list, Collector<? super E, ?, C> collector) Gets a Collection of the given Enum constants by their names.getEnumsFromListAsEnumSet
(Class<E> enumClazz, List<String> list) Gets an EnumSet of the given Enum constants by their names.getEnumsFromListAsSet
(Class<E> enumClazz, List<String> list) Gets a Set of the given Enum constants by their names.getEnumsFromRegexList
(Class<E> enumClazz, List<String> list) Gets an EnumSet of the given Enum constants by a list of regex patterns.getIfPresent
(Class<E> enumClazz, String value) Gets anOptional
of a given Enum by its namestatic <E extends Enum<E>>
EgetNextElement
(E e) Gets the next element of the given enum class by its ordinal.static <E extends Enum<E>>
EgetRandomElement
(Class<E> enumClazz) Gets a random value of the given Enum class.Returns all elements of the given enum class.
-
Constructor Details
-
EnumUtils
public EnumUtils()
-
-
Method Details
-
getEnumsFromListAsEnumSet
public static <E extends Enum<E>> EnumSet<E> getEnumsFromListAsEnumSet(Class<E> enumClazz, List<String> list) Gets an EnumSet of the given Enum constants by their names. Enum constants that aren't found will print a warning. Case is ignored for Bukkit enums. -
getEnumsFromListAsSet
public static <E extends Enum<E>> Set<E> getEnumsFromListAsSet(Class<E> enumClazz, List<String> list) Gets a Set of the given Enum constants by their names. Enum constants that aren't found will print a warning. Case is ignored for Bukkit enums. -
getEnumsFromList
public static <E extends Enum<E>,C extends Collection<E>> C getEnumsFromList(Class<E> enumClazz, List<String> list, Collector<? super E, ?, C> collector) Gets a Collection of the given Enum constants by their names. Enums constants that aren't found will print a warning. Case is ignored for Bukkit enums. -
getIfPresent
Gets anOptional
of a given Enum by its name -
getEnumsFromRegexList
public static <E extends Enum<E>> EnumSet<E> getEnumsFromRegexList(Class<E> enumClazz, List<String> list) Gets an EnumSet of the given Enum constants by a list of regex patterns. Example:materials: - "^((.+)_)*CHEST$" # matches CHEST, TRAPPED_CHEST, etc - "^((.+)_)*SHULKER_BOX$" # matches SHULKER_BOX, RED_SHULKER_BOX, etc - "^BARREL$" # matches only BARREL
-
getRandomElement
Gets a random value of the given Enum class. Values are cached, so it doesn't have to call values() all the time. -
getValues
Returns all elements of the given enum class. Unlike calling values() on an element instance, or calling getEnumConstants() on an enum class, this will cache the delivered array and doesn't have to create a new one everytime. The returned list is unmodifiable. -
getNextElement
Gets the next element of the given enum class by its ordinal. For example, if your enum class has three declared values A, B and C, then calling this method with A will return B, calling it with B will return C, and calling it with C will return A. The next element of each element is cached and does not require to call values() all the time.
-