java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.EnumSet<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 Summary
Modifier and Type Method Description static <E extends Enum<E>>
EnumSet<E>allOf(Class<E> elementType)Creates an enum set filled with all the enum elements of the specifiedelementType.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(Collection<E> c)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>noneOf(Class<E> elementType)Creates an empty enum set.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)Creates a new enum set, containing only the specified elements.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 e1, E e2, E e3)Creates a new enum set, containing only the specified elements.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.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.static <E extends Enum<E>>
EnumSet<E>range(E start, E end)Creates an enum set containing all the elements within the range defined bystartandend(inclusive).Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toString
-
Method Details
-
noneOf
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
Creates an enum set filled with all the enum elements of the specifiedelementType.- 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
Creates an enum set. All the contained elements are of type Class<E>, and the contained elements are the same as those contained ins.- 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
Creates an enum set. The contained elements are the same as those contained in collectionc. If c is an enum set, invoking this method is the same as invokingcopyOf(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- ifcisnull.
-
complementOf
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- ifsisnull.
-
of
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- ifeisnull.
-
of
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 isnull.
-
of
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 isnull.
-
of
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 isnull.
-
of
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 isnull.
-
of
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 isnull.
-
range
Creates an enum set containing all the elements within the range defined bystartandend(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 ofstartorendisnull.IllegalArgumentException- ifstartis behindend.
-
clone
Creates a new enum set with the same elements as those contained in this enum set.
-