public abstract class

EnumSet

extends AbstractSet<E>
implements Serializable Cloneable
java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.AbstractSet<E>
       ↳ java.util.EnumSet<E extends java.lang.Enum<E>>

Class Overview

An EnumSet is a specialized Set to be used with enums as keys.

Summary

Public Methods
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.
EnumSet<E> clone()
Creates a new enum set with the same elements as those contained in this enum set.
static <E extends Enum<E>> EnumSet<E> complementOf(EnumSet<E> s)
Creates an enum set.
static <E extends Enum<E>> EnumSet<E> copyOf(EnumSet<E> s)
Creates an enum set.
static <E extends Enum<E>> EnumSet<E> copyOf(Collection<E> c)
Creates an enum set.
static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
Creates an empty enum set.
static <E extends Enum<E>> EnumSet<E> of(E start, E... others)
Creates a new enum set, containing only the specified elements.
static <E extends Enum<E>> EnumSet<E> of(E e)
Creates a new enum set, containing only the specified element.
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 element.
static <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3)
Creates a new enum set, containing only the specified element.
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 element.
static <E extends Enum<E>> EnumSet<E> of(E e1, E e2)
Creates a new enum set, containing only the specified element.
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).
[Expand]
Inherited Methods
From class java.util.AbstractSet
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface java.util.Set

Public Methods

public static 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.

public EnumSet<E> clone ()

Creates a new enum set with the same elements as those contained in this enum set.

Returns
  • a new enum set with the same elements as those contained in this enum set.

public static 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.

public static 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.

public static 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.

public static 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.

public static 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.

public static 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.

public static EnumSet<E> of (E e1, E e2, E e3, E e4, E e5)

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
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 element.

public static EnumSet<E> of (E e1, E e2, E e3)

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
e1 the initially contained element.
e2 another initially contained element.
e3 another initially contained element.
Returns
  • an enum set containing the specified element.

public static EnumSet<E> of (E e1, E e2, E e3, E e4)

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
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 element.

public static EnumSet<E> of (E e1, E e2)

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
e1 the initially contained element.
e2 another initially contained element.
Returns
  • an enum set containing the specified element.

public static 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
IllegalArgumentException if start is behind end.