Package java.util

Class EnumSet<E extends Enum<E>>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public abstract class EnumSet<E extends Enum<E>>
extends AbstractSet<E>
implements Cloneable, Serializable
An EnumSet is a specialized Set to be used with enums as keys.
See Also:
Serialized Form
  • Method Details

    • noneOf

      public static <E extends Enum<E>> EnumSet<E> noneOf​(Class<E> elementType)
      Creates an empty enum set. The permitted elements are of type Class<E>.
      Parameters:
      elementType - the class object for the elements contained.
      Returns:
      an empty enum set, with permitted elements of type elementType.
      Throws:
      ClassCastException - if the specified element type is not and enum type.
    • allOf

      public static <E extends Enum<E>> EnumSet<E> allOf​(Class<E> elementType)
      Creates an enum set filled with all the enum elements of the specified elementType.
      Parameters:
      elementType - the class object for the elements contained.
      Returns:
      an enum set with elements solely from the specified element type.
      Throws:
      ClassCastException - if the specified element type is not and enum type.
    • copyOf

      public static <E extends Enum<E>> EnumSet<E> copyOf​(EnumSet<E> s)
      Creates an enum set. All the contained elements are of type Class<E>, and the contained elements are the same as those contained in s.
      Parameters:
      s - the enum set from which to copy.
      Returns:
      an enum set with all the elements from the specified enum set.
      Throws:
      ClassCastException - if the specified element type is not and enum type.
    • copyOf

      public static <E extends Enum<E>> EnumSet<E> copyOf​(Collection<E> c)
      Creates an enum set. The contained elements are the same as those contained in collection c. If c is an enum set, invoking this method is the same as invoking copyOf(EnumSet).
      Parameters:
      c - the collection from which to copy. if it is not an enum set, it must not be empty.
      Returns:
      an enum set with all the elements from the specified collection.
      Throws:
      IllegalArgumentException - if c is not an enum set and contains no elements at all.
      NullPointerException - if c is null.
    • complementOf

      public static <E extends Enum<E>> EnumSet<E> complementOf​(EnumSet<E> s)
      Creates an enum set. All the contained elements complement those from the specified enum set.
      Parameters:
      s - the specified enum set.
      Returns:
      an enum set with all the elements complementary to those from the specified enum set.
      Throws:
      NullPointerException - if s is null.
    • of

      public static <E extends Enum<E>> EnumSet<E> of​(E e)
      Creates a new enum set, containing only the specified element. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.
      Parameters:
      e - the element to be initially contained.
      Returns:
      an enum set containing the specified element.
      Throws:
      NullPointerException - if e is null.
    • of

      public static <E extends Enum<E>> EnumSet<E> of​(E e1, E e2)
      Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.
      Parameters:
      e1 - the initially contained element.
      e2 - another initially contained element.
      Returns:
      an enum set containing the specified elements.
      Throws:
      NullPointerException - if any of the specified elements is null.
    • of

      public static <E extends Enum<E>> EnumSet<E> of​(E e1, E e2, E e3)
      Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.
      Parameters:
      e1 - the initially contained element.
      e2 - another initially contained element.
      e3 - another initially contained element.
      Returns:
      an enum set containing the specified elements.
      Throws:
      NullPointerException - if any of the specified elements is null.
    • of

      public static <E extends Enum<E>> EnumSet<E> of​(E e1, E e2, E e3, E e4)
      Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.
      Parameters:
      e1 - the initially contained element.
      e2 - another initially contained element.
      e3 - another initially contained element.
      e4 - another initially contained element.
      Returns:
      an enum set containing the specified elements.
      Throws:
      NullPointerException - if any of the specified elements is null.
    • of

      public static <E extends Enum<E>> EnumSet<E> of​(E e1, E e2, E e3, E e4, E e5)
      Creates a new enum set, containing only the specified elements. There are six overloadings of the method. They accept from one to five elements respectively. The sixth one receives an arbitrary number of elements, and runs slower than those that only receive a fixed number of elements.
      Parameters:
      e1 - the initially contained element.
      e2 - another initially contained element.
      e3 - another initially contained element.
      e4 - another initially contained element.
      e5 - another initially contained element.
      Returns:
      an enum set containing the specified elements.
      Throws:
      NullPointerException - if any of the specified elements is null.
    • of

      @SafeVarargs public static <E extends Enum<E>> EnumSet<E> of​(E start, E... others)
      Creates a new enum set, containing only the specified elements. It can receive an arbitrary number of elements, and runs slower than those only receiving a fixed number of elements.
      Parameters:
      start - the first initially contained element.
      others - the other initially contained elements.
      Returns:
      an enum set containing the specified elements.
      Throws:
      NullPointerException - if any of the specified elements is null.
    • range

      public static <E extends Enum<E>> EnumSet<E> range​(E start, E end)
      Creates an enum set containing all the elements within the range defined by start and end (inclusive). All the elements must be in order.
      Parameters:
      start - the element used to define the beginning of the range.
      end - the element used to define the end of the range.
      Returns:
      an enum set with elements in the range from start to end.
      Throws:
      NullPointerException - if any one of start or end is null.
      IllegalArgumentException - if start is behind end.
    • clone

      public EnumSet<E> clone()
      Creates a new enum set with the same elements as those contained in this enum set.
      Overrides:
      clone in class Object
      Returns:
      a new enum set with the same elements as those contained in this enum set.