Class EnumUtils

java.lang.Object
com.jeff_media.jefflib.EnumUtils

public class EnumUtils extends Object
Enum related methods
  • Constructor Details

  • 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

      public static <E extends Enum<E>> Optional<E> getIfPresent(Class<E> enumClazz, String value)
      Gets an Optional 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

      public static <E extends Enum<E>> E getRandomElement(Class<E> enumClazz)
      Gets a random value of the given Enum class. Values are cached, so it doesn't have to call values() all the time.
    • getValues

      public static <E extends Enum<E>> List<E> getValues(Class<E> enumClazz)
      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

      public static <E extends Enum<E>> E getNextElement(E e)
      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.