Class EnumSet<E extends java.lang.Enum<E>>

  • Type Parameters:
    E - The enum type contained in this set.
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, Collection<E>, Group<E>, Set<E>

    public class EnumSet<E extends java.lang.Enum<E>>
    extends java.lang.Object
    implements Set<E>, java.io.Serializable
    Implementation of the Set interface that is backed by an array of enum values.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      EnumSet​(java.lang.Class<E> enumClass)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E element)
      Adds an element to the group.
      boolean addAll​(Collection<E> c)
      Adds all the elements of the given collection of this enum to this set.
      static <E extends java.lang.Enum<E>>
      EnumSet<E>
      allOf​(java.lang.Class<E> elementClass)
      Creates an enum set initially containing all the elements of the backing enum.
      void clear()
      Removes all elements from the collection.
      boolean contains​(E element)
      Tests the existence of an element in the group.
      java.util.Comparator<E> getComparator()
      Returns the collection's sort order.
      int getCount()  
      java.lang.Class<E> getEnumClass()  
      ListenerList<SetListener<E>> getSetListeners()  
      boolean isEmpty()
      Tests the emptiness of the collection.
      java.util.Iterator<E> iterator()  
      static <E extends java.lang.Enum<E>>
      EnumSet<E>
      noneOf​(java.lang.Class<E> elementClass)
      Creates an empty enum set.
      static <E extends java.lang.Enum<E>>
      EnumSet<E>
      of​(E e)
      Creates an enum set containing the given element.
      static <E extends java.lang.Enum<E>>
      EnumSet<E>
      of​(E e1, E e2)
      Creates an enum set containing the given elements.
      static <E extends java.lang.Enum<E>>
      EnumSet<E>
      of​(E e1, E e2, E e3)
      Creates an enum set containing the given elements.
      static <E extends java.lang.Enum<E>>
      EnumSet<E>
      of​(E e1, E e2, E e3, E e4)
      Creates an enum set containing the given elements.
      boolean remove​(E element)
      Removes an element from the group.
      void setComparator​(java.util.Comparator<E> comparator)
      Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • EnumSet

        public EnumSet​(java.lang.Class<E> enumClass)
    • Method Detail

      • getEnumClass

        public java.lang.Class<E> getEnumClass()
      • add

        public boolean add​(E element)
        Description copied from interface: Group
        Adds an element to the group.
        Specified by:
        add in interface Group<E extends java.lang.Enum<E>>
        Specified by:
        add in interface Set<E extends java.lang.Enum<E>>
        Parameters:
        element - The element to add to the group.
        Returns:
        true if the element was added to the group; false, otherwise.
        See Also:
        SetListener.elementAdded(Set, Object)
      • remove

        public boolean remove​(E element)
        Description copied from interface: Group
        Removes an element from the group.
        Specified by:
        remove in interface Group<E extends java.lang.Enum<E>>
        Specified by:
        remove in interface Set<E extends java.lang.Enum<E>>
        Parameters:
        element - The element to remove from the set.
        Returns:
        true if the element was removed from the group; false, otherwise.
        See Also:
        SetListener.elementRemoved(Set, Object)
      • contains

        public boolean contains​(E element)
        Description copied from interface: Group
        Tests the existence of an element in the group.
        Specified by:
        contains in interface Group<E extends java.lang.Enum<E>>
        Parameters:
        element - The element whose presence in the group is to be tested.
        Returns:
        true if the element exists in the group; false, otherwise.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Collection
        Tests the emptiness of the collection.
        Specified by:
        isEmpty in interface Collection<E extends java.lang.Enum<E>>
        Returns:
        true if the collection contains no elements; false, otherwise.
      • getCount

        public int getCount()
        Specified by:
        getCount in interface Set<E extends java.lang.Enum<E>>
        Returns:
        The number of elements in the set.
      • getComparator

        public java.util.Comparator<E> getComparator()
        Description copied from interface: Collection
        Returns the collection's sort order.
        Specified by:
        getComparator in interface Collection<E extends java.lang.Enum<E>>
        Returns:
        The comparator used to order elements in the collection, or null if the sort order is undefined.
        See Also:
        Collection.setComparator(Comparator)
      • setComparator

        @UnsupportedOperation
        public void setComparator​(java.util.Comparator<E> comparator)
        Description copied from interface: Collection
        Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

        Calling this method more than once with the same comparator will re-sort the collection.

        Specified by:
        setComparator in interface Collection<E extends java.lang.Enum<E>>
        Specified by:
        setComparator in interface Set<E extends java.lang.Enum<E>>
        Parameters:
        comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.
        See Also:
        SetListener.setCleared(Set)
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<E extends java.lang.Enum<E>>
      • noneOf

        public static <E extends java.lang.Enum<E>> EnumSet<E> noneOf​(java.lang.Class<E> elementClass)
        Creates an empty enum set.
        Type Parameters:
        E - The enum type of the set.
        Parameters:
        elementClass - The class of the individual elements to be used in this set.
        Returns:
        The new empty set.
      • allOf

        public static <E extends java.lang.Enum<E>> EnumSet<E> allOf​(java.lang.Class<E> elementClass)
        Creates an enum set initially containing all the elements of the backing enum.
        Type Parameters:
        E - The enum type of the set.
        Parameters:
        elementClass - The class of the individual elements to be used in this set.
        Returns:
        The new complete set.
      • of

        public static <E extends java.lang.Enum<E>> EnumSet<E> of​(E e)
        Creates an enum set containing the given element.
        Type Parameters:
        E - The enum type of the set.
        Parameters:
        e - The only element to assign to the new set.
        Returns:
        The new set containing the single element.
      • of

        public static <E extends java.lang.Enum<E>> EnumSet<E> of​(E e1,
                                                                  E e2)
        Creates an enum set containing the given elements.
        Type Parameters:
        E - The enum type of the set.
        Parameters:
        e1 - The first element to add to the new set.
        e2 - The second element to add.
        Returns:
        The new set containing only these two elements.
      • of

        public static <E extends java.lang.Enum<E>> EnumSet<E> of​(E e1,
                                                                  E e2,
                                                                  E e3)
        Creates an enum set containing the given elements.
        Type Parameters:
        E - The enum type of the set.
        Parameters:
        e1 - The first element to add to the new set.
        e2 - The second element to add.
        e3 - The third element to add.
        Returns:
        The new set containing only these three elements.
      • of

        public static <E extends java.lang.Enum<E>> EnumSet<E> of​(E e1,
                                                                  E e2,
                                                                  E e3,
                                                                  E e4)
        Creates an enum set containing the given elements.
        Type Parameters:
        E - The enum type of the set.
        Parameters:
        e1 - The first element to add to the new set.
        e2 - The second element to add.
        e3 - The third element to add.
        e4 - The fourth element to add.
        Returns:
        The new set containing only these four elements.
      • addAll

        public boolean addAll​(Collection<E> c)
        Adds all the elements of the given collection of this enum to this set.
        Parameters:
        c - The other collection to add to this set.
        Returns:
        Whether or not the enum set changed as a result.