< prev index next >
src/java.base/share/classes/java/util/EnumSet.java
Print this page
*** 32,46 ****
* the elements in an enum set must come from a single enum type that is
* specified, explicitly or implicitly, when the set is created. Enum sets
* are represented internally as bit vectors. This representation is
* extremely compact and efficient. The space and time performance of this
* class should be good enough to allow its use as a high-quality, typesafe
! * alternative to traditional <tt>int</tt>-based "bit flags." Even bulk
! * operations (such as <tt>containsAll</tt> and <tt>retainAll</tt>) should
* run very quickly if their argument is also an enum set.
*
! * <p>The iterator returned by the <tt>iterator</tt> method traverses the
* elements in their <i>natural order</i> (the order in which the enum
* constants are declared). The returned iterator is <i>weakly
* consistent</i>: it will never throw {@link ConcurrentModificationException}
* and it may or may not show the effects of any modifications to the set that
* occur while the iteration is in progress.
--- 32,46 ----
* the elements in an enum set must come from a single enum type that is
* specified, explicitly or implicitly, when the set is created. Enum sets
* are represented internally as bit vectors. This representation is
* extremely compact and efficient. The space and time performance of this
* class should be good enough to allow its use as a high-quality, typesafe
! * alternative to traditional {@code int}-based "bit flags." Even bulk
! * operations (such as {@code containsAll} and {@code retainAll}) should
* run very quickly if their argument is also an enum set.
*
! * <p>The iterator returned by the {@code iterator} method traverses the
* elements in their <i>natural order</i> (the order in which the enum
* constants are declared). The returned iterator is <i>weakly
* consistent</i>: it will never throw {@link ConcurrentModificationException}
* and it may or may not show the effects of any modifications to the set that
* occur while the iteration is in progress.
*** 48,58 ****
* <p>Null elements are not permitted. Attempts to insert a null element
* will throw {@link NullPointerException}. Attempts to test for the
* presence of a null element or to remove one will, however, function
* properly.
*
! * <P>Like most collection implementations, <tt>EnumSet</tt> is not
* synchronized. If multiple threads access an enum set concurrently, and at
* least one of the threads modifies the set, it should be synchronized
* externally. This is typically accomplished by synchronizing on some
* object that naturally encapsulates the enum set. If no such object exists,
* the set should be "wrapped" using the {@link Collections#synchronizedSet}
--- 48,58 ----
* <p>Null elements are not permitted. Attempts to insert a null element
* will throw {@link NullPointerException}. Attempts to test for the
* presence of a null element or to remove one will, however, function
* properly.
*
! * <P>Like most collection implementations, {@code EnumSet} is not
* synchronized. If multiple threads access an enum set concurrently, and at
* least one of the threads modifies the set, it should be synchronized
* externally. This is typically accomplished by synchronizing on some
* object that naturally encapsulates the enum set. If no such object exists,
* the set should be "wrapped" using the {@link Collections#synchronizedSet}
*** 104,114 ****
*
* @param <E> The class of the elements in the set
* @param elementType the class object of the element type for this enum
* set
* @return An empty enum set of the specified type.
! * @throws NullPointerException if <tt>elementType</tt> is null
*/
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
Enum<?>[] universe = getUniverse(elementType);
if (universe == null)
throw new ClassCastException(elementType + " not an enum");
--- 104,114 ----
*
* @param <E> The class of the elements in the set
* @param elementType the class object of the element type for this enum
* set
* @return An empty enum set of the specified type.
! * @throws NullPointerException if {@code elementType} is null
*/
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
Enum<?>[] universe = getUniverse(elementType);
if (universe == null)
throw new ClassCastException(elementType + " not an enum");
*** 125,135 ****
*
* @param <E> The class of the elements in the set
* @param elementType the class object of the element type for this enum
* set
* @return An enum set containing all the elements in the specified type.
! * @throws NullPointerException if <tt>elementType</tt> is null
*/
public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType) {
EnumSet<E> result = noneOf(elementType);
result.addAll();
return result;
--- 125,135 ----
*
* @param <E> The class of the elements in the set
* @param elementType the class object of the element type for this enum
* set
* @return An enum set containing all the elements in the specified type.
! * @throws NullPointerException if {@code elementType} is null
*/
public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType) {
EnumSet<E> result = noneOf(elementType);
result.addAll();
return result;
*** 146,174 ****
* set, initially containing the same elements (if any).
*
* @param <E> The class of the elements in the set
* @param s the enum set from which to initialize this enum set
* @return A copy of the specified enum set.
! * @throws NullPointerException if <tt>s</tt> is null
*/
public static <E extends Enum<E>> EnumSet<E> copyOf(EnumSet<E> s) {
return s.clone();
}
/**
* Creates an enum set initialized from the specified collection. If
! * the specified collection is an <tt>EnumSet</tt> instance, this static
* factory method behaves identically to {@link #copyOf(EnumSet)}.
* Otherwise, the specified collection must contain at least one element
* (in order to determine the new enum set's element type).
*
* @param <E> The class of the elements in the collection
* @param c the collection from which to initialize this enum set
* @return An enum set initialized from the given collection.
! * @throws IllegalArgumentException if <tt>c</tt> is not an
! * <tt>EnumSet</tt> instance and contains no elements
! * @throws NullPointerException if <tt>c</tt> is null
*/
public static <E extends Enum<E>> EnumSet<E> copyOf(Collection<E> c) {
if (c instanceof EnumSet) {
return ((EnumSet<E>)c).clone();
} else {
--- 146,174 ----
* set, initially containing the same elements (if any).
*
* @param <E> The class of the elements in the set
* @param s the enum set from which to initialize this enum set
* @return A copy of the specified enum set.
! * @throws NullPointerException if {@code s} is null
*/
public static <E extends Enum<E>> EnumSet<E> copyOf(EnumSet<E> s) {
return s.clone();
}
/**
* Creates an enum set initialized from the specified collection. If
! * the specified collection is an {@code EnumSet} instance, this static
* factory method behaves identically to {@link #copyOf(EnumSet)}.
* Otherwise, the specified collection must contain at least one element
* (in order to determine the new enum set's element type).
*
* @param <E> The class of the elements in the collection
* @param c the collection from which to initialize this enum set
* @return An enum set initialized from the given collection.
! * @throws IllegalArgumentException if {@code c} is not an
! * {@code EnumSet} instance and contains no elements
! * @throws NullPointerException if {@code c} is null
*/
public static <E extends Enum<E>> EnumSet<E> copyOf(Collection<E> c) {
if (c instanceof EnumSet) {
return ((EnumSet<E>)c).clone();
} else {
*** 189,199 ****
* <i>not</i> contained in the specified set.
*
* @param <E> The class of the elements in the enum set
* @param s the enum set from whose complement to initialize this enum set
* @return The complement of the specified set in this set
! * @throws NullPointerException if <tt>s</tt> is null
*/
public static <E extends Enum<E>> EnumSet<E> complementOf(EnumSet<E> s) {
EnumSet<E> result = copyOf(s);
result.complement();
return result;
--- 189,199 ----
* <i>not</i> contained in the specified set.
*
* @param <E> The class of the elements in the enum set
* @param s the enum set from whose complement to initialize this enum set
* @return The complement of the specified set in this set
! * @throws NullPointerException if {@code s} is null
*/
public static <E extends Enum<E>> EnumSet<E> complementOf(EnumSet<E> s) {
EnumSet<E> result = copyOf(s);
result.complement();
return result;
*** 208,218 ****
* an enum set initially containing an arbitrary number of elements, but
* is likely to run slower than the overloadings that do not use varargs.
*
* @param <E> The class of the specified element and of the set
* @param e the element that this set is to contain initially
! * @throws NullPointerException if <tt>e</tt> is null
* @return an enum set initially containing the specified element
*/
public static <E extends Enum<E>> EnumSet<E> of(E e) {
EnumSet<E> result = noneOf(e.getDeclaringClass());
result.add(e);
--- 208,218 ----
* an enum set initially containing an arbitrary number of elements, but
* is likely to run slower than the overloadings that do not use varargs.
*
* @param <E> The class of the specified element and of the set
* @param e the element that this set is to contain initially
! * @throws NullPointerException if {@code e} is null
* @return an enum set initially containing the specified element
*/
public static <E extends Enum<E>> EnumSet<E> of(E e) {
EnumSet<E> result = noneOf(e.getDeclaringClass());
result.add(e);
*** 330,340 ****
*
* @param <E> The class of the parameter elements and of the set
* @param first an element that the set is to contain initially
* @param rest the remaining elements the set is to contain initially
* @throws NullPointerException if any of the specified elements are null,
! * or if <tt>rest</tt> is null
* @return an enum set initially containing the specified elements
*/
@SafeVarargs
public static <E extends Enum<E>> EnumSet<E> of(E first, E... rest) {
EnumSet<E> result = noneOf(first.getDeclaringClass());
--- 330,340 ----
*
* @param <E> The class of the parameter elements and of the set
* @param first an element that the set is to contain initially
* @param rest the remaining elements the set is to contain initially
* @throws NullPointerException if any of the specified elements are null,
! * or if {@code rest} is null
* @return an enum set initially containing the specified elements
*/
@SafeVarargs
public static <E extends Enum<E>> EnumSet<E> of(E first, E... rest) {
EnumSet<E> result = noneOf(first.getDeclaringClass());
< prev index next >