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 theSetinterface 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 booleanadd(E element)Adds an element to the group.booleanaddAll(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.voidclear()Removes all elements from the collection.booleancontains(E element)Tests the existence of an element in the group.java.util.Comparator<E>getComparator()Returns the collection's sort order.intgetCount()java.lang.Class<E>getEnumClass()ListenerList<SetListener<E>>getSetListeners()booleanisEmpty()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.booleanremove(E element)Removes an element from the group.voidsetComparator(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:GroupAdds an element to the group.- Specified by:
addin interfaceGroup<E extends java.lang.Enum<E>>- Specified by:
addin interfaceSet<E extends java.lang.Enum<E>>- Parameters:
element- The element to add to the group.- Returns:
trueif 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:GroupRemoves an element from the group.- Specified by:
removein interfaceGroup<E extends java.lang.Enum<E>>- Specified by:
removein interfaceSet<E extends java.lang.Enum<E>>- Parameters:
element- The element to remove from the set.- Returns:
trueif the element was removed from the group;false, otherwise.- See Also:
SetListener.elementRemoved(Set, Object)
-
clear
public void clear()
Description copied from interface:CollectionRemoves all elements from the collection.- Specified by:
clearin interfaceCollection<E extends java.lang.Enum<E>>- Specified by:
clearin interfaceSet<E extends java.lang.Enum<E>>- See Also:
SetListener.setCleared(Set)
-
contains
public boolean contains(E element)
Description copied from interface:GroupTests the existence of an element in the group.
-
isEmpty
public boolean isEmpty()
Description copied from interface:CollectionTests the emptiness of the collection.- Specified by:
isEmptyin interfaceCollection<E extends java.lang.Enum<E>>- Returns:
trueif the collection contains no elements;false, otherwise.
-
getCount
public int getCount()
-
getComparator
public java.util.Comparator<E> getComparator()
Description copied from interface:CollectionReturns the collection's sort order.- Specified by:
getComparatorin interfaceCollection<E extends java.lang.Enum<E>>- Returns:
- The comparator used to order elements in the collection, or
nullif the sort order is undefined. - See Also:
Collection.setComparator(Comparator)
-
setComparator
@UnsupportedOperation public void setComparator(java.util.Comparator<E> comparator)
Description copied from interface:CollectionSets 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:
setComparatorin interfaceCollection<E extends java.lang.Enum<E>>- Specified by:
setComparatorin 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:
getSetListenersin 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.
-
-