Package org.apache.pivot.collections
Class EnumSet<E extends java.lang.Enum<E>>
- java.lang.Object
-
- org.apache.pivot.collections.EnumSet<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 theSet
interface that is backed by an array of enum values.- See Also:
- Serialized Form
-
-
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.
-
-
-
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 interfaceGroup<E extends java.lang.Enum<E>>
- Specified by:
add
in interfaceSet<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 interfaceGroup<E extends java.lang.Enum<E>>
- Specified by:
remove
in interfaceSet<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)
-
clear
public void clear()
Description copied from interface:Collection
Removes all elements from the collection.- Specified by:
clear
in interfaceCollection<E extends java.lang.Enum<E>>
- Specified by:
clear
in interfaceSet<E extends java.lang.Enum<E>>
- See Also:
SetListener.setCleared(Set)
-
contains
public boolean contains(E element)
Description copied from interface:Group
Tests the existence of an element in the group.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Collection
Tests the emptiness of the collection.- Specified by:
isEmpty
in interfaceCollection<E extends java.lang.Enum<E>>
- Returns:
true
if the collection contains no elements;false
, otherwise.
-
getCount
public int getCount()
-
getComparator
public java.util.Comparator<E> getComparator()
Description copied from interface:Collection
Returns the collection's sort order.- Specified by:
getComparator
in interfaceCollection<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 interfaceCollection<E extends java.lang.Enum<E>>
- Specified by:
setComparator
in interfaceSet<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()
-
getSetListeners
public ListenerList<SetListener<E>> getSetListeners()
- Specified by:
getSetListeners
in interfaceSet<E extends java.lang.Enum<E>>
- Returns:
- The set listener list.
-
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.
-
-