Class Enums

java.lang.Object
eu.bandm.tools.util.java.Enums

public final class Enums extends Object
Library of constants and operations for working with enumeration classes.
See Also:
  • Method Details

    • valueMap

      public static <E extends Enum<E>> Map<String,E> valueMap(Class<E> cls)
      Creates a map of all values of the given enumeration class indexed by their name.
      Type Parameters:
      E - the enumeration type
      Parameters:
      cls - an enumeration class
      Returns:
      a complete map of names to values
    • valueMap

      @SafeVarargs public static <E extends Enum<E>> Map<String,E> valueMap(E... items)
      Creates a map of the given enumeration values indexed by their name.
      Type Parameters:
      E - the enumeration type
      Parameters:
      items - an array of enumeration values
      Returns:
      a map of names to the given values
    • containsSingleEnumElements

      public static boolean containsSingleEnumElements(Collection<?> elems)
      Checks whether the given collection is known to contain only elements of a single enum type.

      Passing the given collection to EnumSet.copyOf(java.util.EnumSet<E>) (with a raw type) will succeed if and only if this method returns true.

      Returns:
      true if elems is an EnumSet, or contains one or more elements of a single enum type; false if elems not a EnumSet and contains no elements, non-enum elements or elements of distinct enum types.
      Since:
      1.3
      See Also: