Package com.github.tommyettinger.ds
Class EnumSet
- All Implemented Interfaces:
EnhancedCollection<Enum<?>>,Iterable<Enum<?>>,Collection<Enum<?>>,Set<Enum<?>>
- Direct Known Subclasses:
EnumFloatMap.Keys,EnumIntMap.Keys,EnumLongMap.Keys,EnumOrderedSet
public class EnumSet
extends AbstractSet<Enum<?>>
implements Set<Enum<?>>, Iterable<Enum<?>>, EnhancedCollection<Enum<?>>
A naturally-ordered Set of Enum items. Unlike
The key universe is an important concept here; it is simply an array of all possible Enum values the EnumSet can use as keys, in the specific order they are declared. You almost always get a key universe by calling
This class tries to be as compatible as possible with
EnumSet, this does not require a Class at construction time, which can be
useful for serialization purposes. Instead of storing a Class, this holds a "key universe" (which is almost always the
same as an array returned by calling values() on an Enum type), and key universes are ideally shared between
compatible EnumSets. No allocation is done unless this is changing its table size and/or key universe. The natural order
of Enum items is in ascending order of their Enum.ordinal() values.
The key universe is an important concept here; it is simply an array of all possible Enum values the EnumSet can use as keys, in the specific order they are declared. You almost always get a key universe by calling
MyEnum.values(), but you
can also use Class.getEnumConstants() for an Enum class. You can and generally should reuse key universes in order to
avoid allocations and/or save memory; the method noneOf(Enum[]) creates an empty EnumSet with
a given key universe. If you need to use the zero-argument constructor, you can, and the key universe will be obtained from the
first key placed into the EnumSet, though it won't be shared at first. You can also set the key universe with
clearToUniverse(Enum[]), in the process of clearing the map.
This class tries to be as compatible as possible with
EnumSet, though this expands on that where possible.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected EnumSet.EnumSetIteratorprotected EnumSet.EnumSetIteratorprotected intprotected int[]protected Enum<?>[] -
Constructor Summary
ConstructorsConstructorDescriptionEnumSet()Empty constructor; using this will postpone allocating any internal arrays untiladd(Enum)is first called (potentially indirectly).Copy constructor; uses a direct reference to the enum values that may be cached inother, but copies other fields.Initializes this set so that it has exactly enough capacity as needed to contain each Enum constant defined by the ClassuniverseClass, assuming universeClass is non-null.Initializes this set so that it holds the given Enum values, with the universe of possible Enum constants this can hold determined by the type of the first Enum incontents.Initializes this set so that it has exactly enough capacity as needed to contain each Enum constant defined inuniverse, assuming universe stores every possible constant in one Enum type.EnumSet(Collection<? extends Enum<?>> contents) Initializes this set so that it holds the given Enum values, with the universe of possible Enum constants this can hold determined by the type of the first Enum incontents.Initializes this set so that it holds the given Enum values, with the universe of possible Enum constants this can hold determined by the type of the first Enum incontents. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified element to this set if it is not already present (optional operation).booleanAdds all Enum items in the given array to this set.booleanaddAll(Collection<? extends Enum<?>> c) Adds all the elements in the specified collection to this collection.static EnumSetCreates a new EnumSet using the constants from the given Class (of an Enum type), and with all possible items initially stored in the set.static EnumSetCreates a new EnumSet using the given result of callingvalues()on an Enum type (the universe), and with all possible items initially stored in the set.voidclear()Removes all the elements from this set.voidclearToUniverse(Class<? extends Enum<?>> universe) Removes all the elements from this set and can reset the universe of possible Enum items this can hold.voidclearToUniverse(Enum<?>[] universe) Removes all the elements from this set and can reset the universe of possible Enum items this can hold.static EnumSetcomplementOf(EnumSet other) Given another EnumSet, this creates a new EnumSet with the same universe asother, but with any elements present in other absent in the new set, and any elements absent in other present in the new set.booleanReturnstrueif this set contains the specified element.booleancontainsAll(Collection<?> c) Returns true if this EnumSet contains all items in the given Collection, or false otherwise.static EnumSetcopyOf(Collection<? extends Enum<?>> contents) Creates an EnumSet holding any Enum items in the givencontents, which may be any Collection of Enum, including another EnumSet.Enum<?>[]Gets the current key universe; this is a technically-mutable array, but should never be modified.booleanisEmpty()Returnstrueif this set contains no elements.iterator()Returns an iterator for the items in the set.Enum<?>nextEnum(int minOrdinal) Returns the first Enum contained in the set with an ordinal equal to or greater thanminOrdinal.Enum<?>Returns the first Enum contained in the set on or after the point where the given Enumfromwould occur.intnextOrdinal(int minOrdinal) Returns the first ordinal equal to or greater than theminOrdinalof an Enum contained in the set.static EnumSetCreates a new EnumSet using the constants from the given Class (of an Enum type), but with no items initially stored in the set.static EnumSetCreates a new EnumSet using the given result of callingvalues()on an Enum type (the universe), but with no items initially stored in the set.static EnumSetAlias ofwith(Enum)for compatibility.static EnumSetAlias ofwith(Enum[])for compatibility.static EnumSetparse(String str, String delimiter, PartialParser<Enum<?>> parser) Callsparse(String, String, PartialParser, boolean)with brackets set to false.static EnumSetparse(String str, String delimiter, PartialParser<Enum<?>> parser, boolean brackets) Creates a new collection and fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true).static EnumSetparse(String str, String delimiter, PartialParser<Enum<?>> parser, int offset, int length) Creates a new collection and fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)with the given five parameters as-is.Creates an EnumSet holding Enum items between the ordinals ofstartandend.booleanRemoves the specified element from this set if it is present (optional operation).booleanremoveAll(Collection<?> c) Removes from this EnumSet every element in the given Collection.booleanretainAll(Collection<?> c) Removes all items from this unless they are also in the given Collectionc.intsize()Returns the number of elements in this set (its cardinality).toString()voidtruncate(int newSize) Reduces the size of the set to the specified size.static EnumSetBuilds an EnumSet that contains only the given element.static EnumSetBuilds an EnumSet that contains the unique elements from the givenarrayor varargs.static EnumSetCreates a new EnumSet that holds only the given items, but can be resized.static EnumSetCreates a new EnumSet that holds only the given items, but can be resized.static EnumSetCreates a new EnumSet that holds only the given items, but can be resized.static EnumSetCreates a new EnumSet that holds only the given items, but can be resized.static EnumSetCreates a new EnumSet that holds only the given items, but can be resized.static EnumSetwith(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6) Creates a new EnumSet that holds only the given items, but can be resized.static EnumSetwith(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6, Enum<?> item7) Creates a new EnumSet that holds only the given items, but can be resized.Methods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface com.github.tommyettinger.ds.EnhancedCollection
add, add, add, addAll, addAll, addAllIterable, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAll, containsAll, containsAllIterable, containsAny, containsAny, containsAny, containsAnyIterable, first, removeAll, removeAll, removeAll, removeAllIterable, removeEach, removeEach, removeEach, removeEachIterable, toString, toString, toString
-
Field Details
-
size
protected int size -
table
protected int[] table -
universe
-
iterator1
-
iterator2
-
-
Constructor Details
-
EnumSet
public EnumSet()Empty constructor; using this will postpone allocating any internal arrays untiladd(Enum)is first called (potentially indirectly). -
EnumSet
Initializes this set so that it has exactly enough capacity as needed to contain each Enum constant defined inuniverse, assuming universe stores every possible constant in one Enum type. You almost always obtain universe from callingvalues()on an Enum type, and you can share one reference to one Enum array across many EnumSet instances if you don't modify the shared array. Sharing the same universe helps save some memory if you have (very) many EnumSet instances.
Because thebooleanparameter here is easy to forget, you may want to prefer callingnoneOf(Enum[])instead of using this directly.- Parameters:
universe- almost always, the result of callingvalues()on an Enum type; used directly, not copiedignoredToDistinguish- an ignored boolean that differentiates this constructor, which defined a key universe, from one that takes contents
-
EnumSet
Initializes this set so that it has exactly enough capacity as needed to contain each Enum constant defined by the ClassuniverseClass, assuming universeClass is non-null. This simply callsEnumSet(Enum[], boolean)for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you useEnumSet(Enum[], boolean)(or its equivalent,noneOf(Enum[])), you can reuse an unmodified array to reduce allocations.- Parameters:
universeClass- the Class of an Enum type that defines the universe of valid Enum items this can hold
-
EnumSet
Initializes this set so that it holds the given Enum values, with the universe of possible Enum constants this can hold determined by the type of the first Enum incontents.
This is different fromEnumSet(Enum[], boolean)in that this takes constants and puts them in the set, while the other constructor takes all possible Enum constants, usually from callingvalues(). You can also specify the contents of a new EnumSet conveniently usingwith(Enum[]), which allows passing items as varargs.- Parameters:
contents- an array of Enum items to place into this set
-
EnumSet
Initializes this set so that it holds the given Enum values, with the universe of possible Enum constants this can hold determined by the type of the first Enum incontents.- Parameters:
contents- a Collection of Enum items to place into this set
-
EnumSet
Initializes this set so that it holds the given Enum values, with the universe of possible Enum constants this can hold determined by the type of the first Enum incontents.- Parameters:
contents- a Collection of Enum items to place into this set
-
EnumSet
Copy constructor; uses a direct reference to the enum values that may be cached inother, but copies other fields.- Parameters:
other- another EnumSet that will have most of its data copied, but its cachedvalues()results will be used directly
-
-
Method Details
-
size
public int size()Returns the number of elements in this set (its cardinality). If this set contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceCollection<Enum<?>>- Specified by:
sizein interfaceSet<Enum<?>>- Specified by:
sizein classAbstractCollection<Enum<?>>- Returns:
- the number of elements in this set (its cardinality)
-
isEmpty
public boolean isEmpty()Returnstrueif this set contains no elements.- Specified by:
isEmptyin interfaceCollection<Enum<?>>- Specified by:
isEmptyin interfaceSet<Enum<?>>- Overrides:
isEmptyin classAbstractCollection<Enum<?>>- Returns:
trueif this set contains no elements
-
contains
Returnstrueif this set contains the specified element. More formally, returnstrueif and only if this set contains an elementesuch thatObjects.equals(item, e).- Specified by:
containsin interfaceCollection<Enum<?>>- Specified by:
containsin interfaceSet<Enum<?>>- Overrides:
containsin classAbstractCollection<Enum<?>>- Parameters:
item- element whose presence in this set is to be tested- Returns:
trueif this set contains the specified element
-
iterator
Returns an iterator for the items in the set. The elements are returned in the order of theirEnum.ordinal()values. Remove is supported.Use the
EnumSet.EnumSetIteratorconstructor for nested or multithreaded iteration. -
add
Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified elementeto this set if the set contains no elemente2such thatObjects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returnsfalse. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including
null, and throw an exception, as described in the specification forCollection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.- Specified by:
addin interfaceCollection<Enum<?>>- Specified by:
addin interfaceSet<Enum<?>>- Overrides:
addin classAbstractCollection<Enum<?>>- Parameters:
item- element to be added to this set- Returns:
trueif this set did not already contain the specified element
-
remove
Removes the specified element from this set if it is present (optional operation). More formally, removes an elementesuch thatObjects.equals(item, e), if this set contains such an element. Returnstrueif this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)- Specified by:
removein interfaceCollection<Enum<?>>- Specified by:
removein interfaceSet<Enum<?>>- Overrides:
removein classAbstractCollection<Enum<?>>- Parameters:
item- object to be removed from this set, if present- Returns:
trueif this set contained the specified element- Throws:
ClassCastException- if the type of the specified element is incompatible with this set (optional)NullPointerException- if the specified element is null and this set does not permit null elements (optional)UnsupportedOperationException- if theremoveoperation is not supported by this set
-
retainAll
Removes all items from this unless they are also in the given Collectionc.- Specified by:
retainAllin interfaceCollection<Enum<?>>- Specified by:
retainAllin interfaceSet<Enum<?>>- Overrides:
retainAllin classAbstractCollection<Enum<?>>- Parameters:
c- usually another EnumSet, but not required to be
-
addAll
Adds all the elements in the specified collection to this collection.- Specified by:
addAllin interfaceCollection<Enum<?>>- Specified by:
addAllin interfaceSet<Enum<?>>- Overrides:
addAllin classAbstractCollection<Enum<?>>- Parameters:
c- usually another EnumSet, but not required to be
-
containsAll
Returns true if this EnumSet contains all items in the given Collection, or false otherwise.- Specified by:
containsAllin interfaceCollection<Enum<?>>- Specified by:
containsAllin interfaceSet<Enum<?>>- Overrides:
containsAllin classAbstractCollection<Enum<?>>- Parameters:
c- usually another EnumSet, but not required to be
-
removeAll
Removes from this EnumSet every element in the given Collection.- Specified by:
removeAllin interfaceCollection<Enum<?>>- Specified by:
removeAllin interfaceSet<Enum<?>>- Overrides:
removeAllin classAbstractSet<Enum<?>>- Parameters:
c- usually another EnumSet, but not required to be- Returns:
trueif this set changed as a result of the call
-
addAll
Adds all Enum items in the given array to this set. Returns true if this set was modified at all in the process (that is, if any items incwere not already present in this set).- Specified by:
addAllin interfaceEnhancedCollection<Enum<?>>- See Also:
-
clear
public void clear()Removes all the elements from this set. The set will be empty after this call returns. This does not change the universe of possible Enum items this can hold.- Specified by:
clearin interfaceCollection<Enum<?>>- Specified by:
clearin interfaceSet<Enum<?>>- Overrides:
clearin classAbstractCollection<Enum<?>>
-
clearToUniverse
Removes all the elements from this set and can reset the universe of possible Enum items this can hold. The set will be empty after this call returns. This changes the universe of possible Enum items this can hold to matchuniverse. Ifuniverseis null, this resets this set to the state it would have afterEnumSet()was called. If the table this would need is the same size as or smaller than the current table (such as ifuniverseis the same as the universe here), this will not allocate, but will still clear any items this holds and will set the universe to the given one. Otherwise, this allocates and uses a new table of a larger size, with nothing in it, and uses the given universe. This always usesuniversedirectly, without copying.
This can be useful to allow an EnumSet that was created withEnumSet()to share a universe with other EnumSets.- Parameters:
universe- the universe of possible Enum items this can hold; almost always produced byvalues()on an Enum
-
clearToUniverse
Removes all the elements from this set and can reset the universe of possible Enum items this can hold. The set will be empty after this call returns. This changes the universe of possible Enum items this can hold to match the Enum constants inuniverse. Ifuniverseis null, this resets this set to the state it would have afterEnumSet()was called. If the table this would need is the same size as or smaller than the current table (such as ifuniverseis the same as the universe here), this will not allocate, but will still clear any items this holds and will set the universe to the given one. Otherwise, this allocates and uses a new table of a larger size, with nothing in it, and uses the given universe. This callsClass.getEnumConstants()if universe is non-null, which allocates a new array.
You may want to prefer callingclearToUniverse(Enum[])(the overload that takes an array), because it can be used to share one universe array between many EnumSet instances. This overload, given a Class, has to callClass.getEnumConstants()and thus allocate a new array each time this is called.- Parameters:
universe- the Class of an Enum type that stores the universe of possible Enum items this can hold
-
getUniverse
Gets the current key universe; this is a technically-mutable array, but should never be modified. To set the universe on an existing EnumSet (with existing contents), you can useclearToUniverse(Enum[]). If an EnumSet has not been initialized, just adding an item will set its key universe to match the given item.- Returns:
- the current key universe
-
nextOrdinal
public int nextOrdinal(int minOrdinal) Returns the first ordinal equal to or greater than theminOrdinalof an Enum contained in the set. If no such Enum exists, or if minOrdinal is invalid (such as if it is negative or greater than the highest ordinal in the Enum type this holds), then-1is returned.- Parameters:
minOrdinal- the index to start looking at; does not need to have an Enum present there, but must be non-negative- Returns:
- the first ordinal of an Enum contained in the set on or after the specified starting point, or
-1if none can be found
-
truncate
public void truncate(int newSize) Reduces the size of the set to the specified size. If the set is already smaller than the specified size, no action is taken. This indiscriminately removes items from the set until the requested newSize is reached, or until the set is empty.
Because the iteration order is not guaranteed by an unordered set, this can remove essentially any item(s) from the set if it is larger than newSize. Most commonly, it removes from the start of the iteration order.- Parameters:
newSize- the target size to try to reach by removing items, if smaller than the current size
-
nextEnum
Returns the first Enum contained in the set with an ordinal equal to or greater thanminOrdinal. If no such Enum exists, or if minOrdinal is invalid (such as if it is negative or greater than the highest ordinal in the Enum type this holds), thennullis returned.- Parameters:
minOrdinal- the index to start looking at; does not need to have an Enum present there, but must be non-negative- Returns:
- the first Enum contained in the set on or after the specified starting point, or null if none can be found
-
nextEnum
Returns the first Enum contained in the set on or after the point where the given Enumfromwould occur. If no such Enum exists thennullis returned.- Parameters:
from- the Enum to start looking at; does not need to be present in the set- Returns:
- the first Enum contained in the set on or after the specified starting point, or null if none can be found
-
toString
- Overrides:
toStringin classAbstractCollection<Enum<?>>
-
with
Builds an EnumSet that contains only the given element.- Parameters:
item- the one item to initialize the EnumSet with- Returns:
- a new EnumSet containing
item
-
with
Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum itemitem3- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
public static EnumSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4) Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum itemitem3- an Enum itemitem4- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
public static EnumSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5) Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum itemitem3- an Enum itemitem4- an Enum itemitem5- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
public static EnumSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6) Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum itemitem3- an Enum itemitem4- an Enum itemitem5- an Enum itemitem6- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
public static EnumSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6, Enum<?> item7) Creates a new EnumSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum itemitem3- an Enum itemitem4- an Enum itemitem5- an Enum itemitem6- an Enum item- Returns:
- a new EnumSet that holds the given items
-
with
Builds an EnumSet that contains the unique elements from the givenarrayor varargs.- Parameters:
array- an array or varargs of Enum constants, which should all have the same Enum type- Returns:
- a new EnumSet containing each unique item from
array
-
parse
Callsparse(String, String, PartialParser, boolean)with brackets set to false.
Theparseris often produced byPartialParser.enumParser(ObjToObjFunction).- Parameters:
str- a String that will be parsed in fulldelimiter- the delimiter between items in strparser- a PartialParser that returns anEnumitem from a section ofstr- Returns:
- a new collection parsed from str
-
parse
public static EnumSet parse(String str, String delimiter, PartialParser<Enum<?>> parser, boolean brackets) Creates a new collection and fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true). Each item is expected to be separated bydelimiter.
Theparseris often produced byPartialParser.enumParser(ObjToObjFunction).- Parameters:
str- a String that will be parsed in full (depending on brackets)delimiter- the delimiter between items in strparser- a PartialParser that returns anEnumitem from a section ofstrbrackets- if true, the first and last chars in str will be ignored- Returns:
- a new collection parsed from str
-
parse
public static EnumSet parse(String str, String delimiter, PartialParser<Enum<?>> parser, int offset, int length) Creates a new collection and fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)with the given five parameters as-is.
Theparseris often produced byPartialParser.enumParser(ObjToObjFunction).- Parameters:
str- a String that will have the given section parseddelimiter- the delimiter between items in strparser- a PartialParser that returns anEnumitem from a section ofstroffset- the first position to parse in str, inclusivelength- how many chars to parse, starting from offset- Returns:
- a new collection parsed from str
-
of
Alias ofwith(Enum)for compatibility.- Parameters:
item- the one item to initialize the EnumSet with- Returns:
- a new EnumSet containing
item
-
of
Alias ofwith(Enum[])for compatibility.- Parameters:
array- an array or varargs of Enum constants, which should all have the same Enum type- Returns:
- a new EnumSet containing each unique item from
array
-
noneOf
Creates a new EnumSet using the given result of callingvalues()on an Enum type (the universe), but with no items initially stored in the set. You can reuse the universe between EnumSet instances as long as it is not modified.
This is the same as callingEnumSet(Enum[], boolean).- Parameters:
universe- almost always, the result of callingvalues()on an Enum type; used directly, not copied- Returns:
- a new EnumSet with the specified universe of possible items, but none present in the set
-
allOf
Creates a new EnumSet using the given result of callingvalues()on an Enum type (the universe), and with all possible items initially stored in the set. You can reuse the universe between EnumSet instances as long as it is not modified.- Parameters:
universe- almost always, the result of callingvalues()on an Enum type; used directly, not copied- Returns:
- a new EnumSet with the specified universe of possible items, and all of them present in the set
-
noneOf
Creates a new EnumSet using the constants from the given Class (of an Enum type), but with no items initially stored in the set.
This is the same as callingEnumSet(Class).- Parameters:
clazz- the Class of any Enum type; you can get this from a constant withEnum.getDeclaringClass()- Returns:
- a new EnumSet with the specified universe of possible items, but none present in the set
-
allOf
Creates a new EnumSet using the constants from the given Class (of an Enum type), and with all possible items initially stored in the set.- Parameters:
clazz- the Class of any Enum type; you can get this from a constant withEnum.getDeclaringClass()- Returns:
- a new EnumSet with the specified universe of possible items, and all of them present in the set
-
complementOf
Given another EnumSet, this creates a new EnumSet with the same universe asother, but with any elements present in other absent in the new set, and any elements absent in other present in the new set.- Parameters:
other- another EnumSet that this will copy- Returns:
- a complemented copy of
other
-
copyOf
Creates an EnumSet holding any Enum items in the givencontents, which may be any Collection of Enum, including another EnumSet. If given an EnumSet, this will copy its Enum universe and other information even if it is empty.- Parameters:
contents- a Collection of Enum values, which may be another EnumSet- Returns:
- a new EnumSet containing the unique items in contents
-
range
Creates an EnumSet holding Enum items between the ordinals ofstartandend. If the ordinal of end is less than the ordinal of start, this throws anIllegalArgumentException. If start and end are the same, this just inserts that one Enum.- Type Parameters:
E- the shared Enum type of both start and end- Parameters:
start- the starting inclusive Enum to insertend- the ending inclusive Enum to insert- Returns:
- a new EnumSet containing start, end, and any Enum constants with ordinals between them
- Throws:
IllegalArgumentException- if theordinalof end is less than the ordinal of start
-