Package com.github.tommyettinger.ds
Class EnumOrderedSet
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<Enum<?>>
com.github.tommyettinger.ds.EnumSet
com.github.tommyettinger.ds.EnumOrderedSet
- All Implemented Interfaces:
Arrangeable,EnhancedCollection<Enum<?>>,Ordered<Enum<?>>,Iterable<Enum<?>>,Collection<Enum<?>>,Set<Enum<?>>
An
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 that also stores keys in an ObjectList using the insertion order.
Unlike 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. You can change
the ordering of the Enum items using methods like sort(Comparator) and Ordered.shuffle(Random). You can also
access enums via their index in the ordering, using methods such as getAt(int), alterAt(int, Enum),
and removeAt(int).
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.
Iteration is ordered and faster than an unordered set. Keys can also be accessed and the order changed
using order(). There is some additional overhead for put and remove.
This class tries to be as compatible as possible with
EnumSet, though this expands on that where possible.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.github.tommyettinger.ds.EnumSet
EnumSet.EnumSetIteratorNested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T>Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Ordered
Ordered.OfBoolean, Ordered.OfByte, Ordered.OfChar, Ordered.OfDouble, Ordered.OfFloat, Ordered.OfInt, Ordered.OfLong, Ordered.OfShort -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor; using this will postpone allocating any internal arrays untiladd(Enum)is first called (potentially indirectly).EnumOrderedSet(EnumOrderedSet other) Copies the entirety ofother, including using the same OrderType.EnumOrderedSet(EnumOrderedSet other, OrderType type) Copiesotherbut allows specifying an OrderType independently ofother's ordering.EnumOrderedSet(EnumSet other) Copy constructor; uses a direct reference to the enum values that may be cached inother, but copies other fields.EnumOrderedSet(EnumSet other, OrderType type) Copy constructor; uses a direct reference to the enum values that may be cached inother, but copies other fields.EnumOrderedSet(Ordered<Enum<?>> other, int offset, int count) Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.EnumOrderedSet(Ordered<Enum<?>> other, int offset, int count, OrderType type) Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.EnumOrderedSet(OrderType type) Only specifies an OrderType; using this will postpone allocating any internal arrays untiladd(Enum)is first called (potentially indirectly).EnumOrderedSet(Class<? extends Enum<?>> universeClass) 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.EnumOrderedSet(Class<? extends Enum<?>> universeClass, OrderType type) 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.EnumOrderedSet(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.EnumOrderedSet(Enum<?>[] universe, boolean ignoredToDistinguish) 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.EnumOrderedSet(Enum<?>[] universe, boolean ignoredToDistinguish, OrderType type) 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.EnumOrderedSet(Enum<?>[] array, int offset, int length) Creates a new set usinglengthitems from the givenarray, starting at offset (inclusive).EnumOrderedSet(Enum<?>[] array, int offset, int length, OrderType type) Creates a new set usinglengthitems from the givenarray, starting at offset (inclusive).EnumOrderedSet(Enum<?>[] contents, OrderType type) 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.EnumOrderedSet(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.EnumOrderedSet(Collection<? extends Enum<?>> contents, OrderType type) 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.EnumOrderedSet(Iterator<? 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.EnumOrderedSet(Iterator<? extends Enum<?>> contents, OrderType type) 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 TypeMethodDescriptionbooleanSets the key at the specified index.booleanAdds the specified element to this set if it is not already present (optional operation).booleanAdds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting starting atinsertionIndexin the iteration order.booleanAdds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting starting atinsertionIndexin the iteration order.booleanAdds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting at the end of the iteration order.booleanAdds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting at the end of the iteration order.static EnumOrderedSetCreates a new EnumOrderedSet using the constants from the given Class (of an Enum type), and with all possible items initially stored in the set.static EnumOrderedSetCreates a new EnumOrderedSet using the given result of callingvalues()on an Enum type (the universe), and with all possible items initially stored in the set.booleanChanges the itembeforetoafterwithout changing its position in the order.booleanChanges the item at the givenindexin the order toafter, without changing the ordering of other items.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 EnumOrderedSetcomplementOf(EnumOrderedSet other) Given another EnumOrderedSet, this creates a new EnumOrderedSet 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.static EnumOrderedSetcopyOf(Collection<? extends Enum<?>> contents) Creates an EnumOrderedSet holding any Enum items in the givencontents, which may be any Collection of Enum, including another EnumOrderedSet.Enum<?>first()Attempts to get the first item in this EnhancedCollection, where "first" is only defined meaningfully if this type is ordered.Enum<?>getAt(int index) Gets the Enum item at the givenindexin the insertion order.iterator()Iterates through items in the same order asorder().static EnumOrderedSetCreates a new EnumOrderedSet using the constants from the given Class (of an Enum type), but with no items initially stored in the set.static EnumOrderedSetCreates a new EnumOrderedSet using the given result of callingvalues()on an Enum type (the universe), but with no items initially stored in the set.static EnumOrderedSetAlias ofwith(Enum)for compatibility.static EnumOrderedSetAlias ofwith(Enum[])for compatibility.ObjectList<Enum<?>>order()Gets the ObjectList of keys in the order this class will iterate through them.static EnumOrderedSetparse(String str, String delimiter, PartialParser<Enum<?>> parser) Callsparse(String, String, PartialParser, boolean)with brackets set to false.static EnumOrderedSetparse(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 EnumOrderedSetparse(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.static <E extends Enum<E>>
EnumOrderedSetCreates an EnumOrderedSet holding Enum items between the ordinals ofstartandend.booleanRemoves the specified element from this set if it is present (optional operation).Enum<?>removeAt(int index) Removes and returns the item at the given index in this set's order.voidremoveRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive.voidsort()Sorts this EnumOrderedMap in-place by the keys' natural ordering.voidsort(Comparator<? super Enum<?>> comp) Sorts this EnumOrderedMap in-place by the given Comparator used on the keys.toString()Delegates toEnhancedCollection.toString(String, boolean)with the given itemSeparator and without surrounding brackets.voidtruncate(int newSize) Reduces the size of the set to the specified size.static EnumOrderedSetwith()Constructs an empty set given the type as a generic type argument.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given item, but can be resized.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetCreates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetwith(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6) Creates a new EnumOrderedSet that holds only the given items, but can be resized.static EnumOrderedSetwith(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6, Enum<?> item7) Creates a new EnumOrderedSet that holds only the given items, but can be resized.Methods inherited from class com.github.tommyettinger.ds.EnumSet
addAll, addAll, complementOf, contains, containsAll, getUniverse, isEmpty, nextEnum, nextEnum, nextOrdinal, removeAll, retainAll, sizeMethods 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 com.github.tommyettinger.ds.Arrangeable
rearrange, shuffle, sizeMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface com.github.tommyettinger.ds.EnhancedCollection
add, add, add, addAll, addAllIterable, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAll, containsAll, containsAllIterable, containsAny, containsAny, containsAny, containsAnyIterable, removeAll, removeAll, removeAll, removeAllIterable, removeEach, removeEach, removeEach, removeEachIterable, toString, toStringMethods inherited from interface com.github.tommyettinger.ds.Ordered
getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap
-
Field Details
-
ordering
-
-
Constructor Details
-
EnumOrderedSet
Only specifies an OrderType; using this will postpone allocating any internal arrays untiladd(Enum)is first called (potentially indirectly).- Parameters:
type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
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 contentstype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
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 callsEnumOrderedSet(Enum[], boolean)for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you useEnumOrderedSet(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 holdtype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
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 settype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
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 settype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
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 directlytype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
Copiesotherbut allows specifying an OrderType independently ofother's ordering.- Parameters:
other- another EnumOrderedSet that will have its contents copiedtype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
Creates a new set usinglengthitems from the givenarray, starting at offset (inclusive).- Parameters:
array- an array to draw items fromoffset- the first index in array to draw an item fromlength- how many items to take from array; bounds-checking is the responsibility of the using codetype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
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 fromEnumOrderedSet(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 settype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.- Parameters:
other- another Ordered of the same typeoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from othertype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumOrderedSet
public EnumOrderedSet()Empty constructor; using this will postpone allocating any internal arrays untiladd(Enum)is first called (potentially indirectly). -
EnumOrderedSet
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
-
EnumOrderedSet
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 callsEnumOrderedSet(Enum[], boolean)for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you useEnumOrderedSet(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
-
EnumOrderedSet
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
-
EnumOrderedSet
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
-
EnumOrderedSet
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
-
EnumOrderedSet
Copies the entirety ofother, including using the same OrderType.- Parameters:
other- another EnumOrderedSet that will have its contents and ordering copied
-
EnumOrderedSet
Creates a new set usinglengthitems from the givenarray, starting at offset (inclusive).- Parameters:
array- an array to draw items fromoffset- the first index in array to draw an item fromlength- how many items to take from array; bounds-checking is the responsibility of the using code
-
EnumOrderedSet
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 fromEnumOrderedSet(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
-
EnumOrderedSet
Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.- Parameters:
other- another Ordered of the same typeoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from other
-
-
Method Details
-
add
Description copied from class:EnumSetAdds 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. -
add
Sets the key at the specified index. Returns true if the key was not already in the set. If this set already contains the key, the existing key's index is changed if needed and false is returned. Note, the order of the parameters matches the order inObjectListand the rest of the JDK, not OrderedSet in libGDX.- Parameters:
index- where in the iteration order to add the given key, or to move it if already presentkey- what Enum item to try to add, if not already present- Returns:
- true if the key was added for the first time, or false if the key was already present (even if moved)
-
addAll
Adds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting at the end of the iteration order.- Parameters:
other- a non-nullOrderedofEnumoffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
EnumSet.addAll(Collection)does
-
addAll
Adds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting starting atinsertionIndexin the iteration order.- Parameters:
insertionIndex- where to insert into the iteration orderother- a non-nullOrderedofEnumoffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
EnumSet.addAll(Collection)does
-
addAll
Adds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting at the end of the iteration order.- Specified by:
addAllin interfaceEnhancedCollection<Enum<?>>- Parameters:
other- a non-nullOrderedofEnumoffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
EnumSet.addAll(Collection)does
-
addAll
Adds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting starting atinsertionIndexin the iteration order.- Parameters:
insertionIndex- where to insert into the iteration orderother- a non-nullOrderedofEnumoffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
EnumSet.addAll(Collection)does
-
remove
Description copied from class:EnumSetRemoves 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.) -
removeAt
Removes and returns the item at the given index in this set's order.- Parameters:
index- the index of the item to remove- Returns:
- the removed item
-
alter
Changes the itembeforetoafterwithout changing its position in the order. Returns true ifafterhas been added to the EnumOrderedSet andbeforehas been removed; returns false ifafteris already present orbeforeis not present. If you are iterating over an EnumOrderedSet and have an index, you should preferalterAt(int, Enum), which doesn't need to search for an index like this does and so can be faster.- Parameters:
before- an item that must be present for this to succeedafter- an item that must not be in this set for this to succeed- Returns:
- true if
beforewas removed andafterwas added, false otherwise
-
alterAt
Changes the item at the givenindexin the order toafter, without changing the ordering of other items. Ifafteris already present, this returns false; it will also return false ifindexis invalid for the size of this set. Otherwise, it returns true. Unlikealter(Enum, Enum), this operates in constant time.- Parameters:
index- the index in the order of the item to change; must be non-negative and less thanEnumSet.sizeafter- the item that will replace the contents atindex; this item must not be present for this to succeed- Returns:
- true if
aftersuccessfully replaced the contents atindex, false otherwise
-
getAt
Gets the Enum item at the givenindexin the insertion order. The index should be between 0 (inclusive) andEnumSet.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andEnumSet.size()(exclusive)- Returns:
- the item at the given index
-
first
Description copied from interface:EnhancedCollectionAttempts to get the first item in this EnhancedCollection, where "first" is only defined meaningfully if this type is ordered. Many times, this applies to a class that is not ordered, and in those cases it can get an arbitrary item, and that item is permitted to be different for different calls to first().
This is useful for cases where you would normally be able to call something likeList.get(int)to get an item, any item, from a collection, but whatever class you're using doesn't necessarily provide a get(), first(), peek(), or similar method.
The default implementation usesCollection.iterator(), tries to get the first item, or throws an IllegalStateException if this is empty.- Specified by:
firstin interfaceEnhancedCollection<Enum<?>>- Returns:
- the first item in this EnhancedCollection, as produced by
Collection.iterator()
-
clear
public void clear()Description copied from class:EnumSetRemoves 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. -
clearToUniverse
Description copied from class:EnumSetRemoves 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.- Overrides:
clearToUniversein classEnumSet- Parameters:
universe- the universe of possible Enum items this can hold; almost always produced byvalues()on an Enum
-
clearToUniverse
Description copied from class:EnumSetRemoves 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 callingEnumSet.clearToUniverse(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.- Overrides:
clearToUniversein classEnumSet- Parameters:
universe- the Class of an Enum type that stores the universe of possible Enum items this can hold
-
order
Gets the ObjectList of keys in the order this class will iterate through them. Returns a direct reference to the same ObjectList this uses, so changes to the returned list will also change the iteration order here. -
sort
public void sort()Sorts this EnumOrderedMap in-place by the keys' natural ordering. -
sort
Sorts this EnumOrderedMap in-place by the given Comparator used on the keys. Ifcompis null, then this will sort by the natural ordering of the keys. -
removeRange
public void removeRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive. Note that this takes different arguments than some other range-related methods; this needs a start index and an end index, rather than a count of items. This matches the behavior in the JDK collections.- Specified by:
removeRangein interfaceOrdered<Enum<?>>- Parameters:
start- the first index to remove, inclusiveend- the last index (after what should be removed), exclusive
-
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. -
iterator
Iterates through items in the same order asorder(). Reuses one of two iterators, and does not permit nested iteration; useEnumOrderedSetIterator(EnumOrderedSet)to nest iterators. -
toString
Description copied from interface:EnhancedCollectionDelegates toEnhancedCollection.toString(String, boolean)with the given itemSeparator and without surrounding brackets.- Specified by:
toStringin interfaceEnhancedCollection<Enum<?>>- Parameters:
itemSeparator- how to separate items, such as", "- Returns:
- a new String representing this map
-
toString
-
with
Constructs an empty set given the type as a generic type argument. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new set containing nothing
-
with
Creates a new EnumOrderedSet that holds only the given item, but can be resized.- Parameters:
item- one Enum item- Returns:
- a new EnumOrderedSet that holds the given item
-
with
Creates a new EnumOrderedSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum item- Returns:
- a new EnumOrderedSet that holds the given items
-
with
Creates a new EnumOrderedSet that holds only the given items, but can be resized.- Parameters:
item0- an Enum itemitem1- an Enum itemitem2- an Enum item- Returns:
- a new EnumOrderedSet that holds the given items
-
with
Creates a new EnumOrderedSet 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 EnumOrderedSet that holds the given items
-
with
public static EnumOrderedSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4) Creates a new EnumOrderedSet 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 EnumOrderedSet that holds the given items
-
with
public static EnumOrderedSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5) Creates a new EnumOrderedSet 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 EnumOrderedSet that holds the given items
-
with
public static EnumOrderedSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6) Creates a new EnumOrderedSet 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 EnumOrderedSet that holds the given items
-
with
public static EnumOrderedSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2, Enum<?> item3, Enum<?> item4, Enum<?> item5, Enum<?> item6, Enum<?> item7) Creates a new EnumOrderedSet 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 EnumOrderedSet that holds the given items
-
with
Creates a new EnumOrderedSet that holds only the given items, but can be resized. This overload will only be used when an array is supplied and the type of the items requested is the component type of the array, or if varargs are used and there are 9 or more arguments.- Parameters:
varargs- an Enum varargs or Enum array; remember that varargs allocate- Returns:
- a new EnumOrderedSet that holds the given items
-
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 EnumOrderedSet 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 EnumOrderedSet 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 EnumOrderedSet 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 EnumOrderedSet containing each unique item from
array
-
noneOf
Creates a new EnumOrderedSet 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 EnumOrderedSet instances as long as it is not modified.
This is the same as callingEnumOrderedSet(Enum[], boolean).- Parameters:
universe- almost always, the result of callingvalues()on an Enum type; used directly, not copied- Returns:
- a new EnumOrderedSet with the specified universe of possible items, but none present in the set
-
allOf
Creates a new EnumOrderedSet 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 EnumOrderedSet 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 EnumOrderedSet with the specified universe of possible items, and all of them present in the set
-
noneOf
Creates a new EnumOrderedSet 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 callingEnumOrderedSet(Class).- Parameters:
clazz- the Class of any Enum type; you can get this from a constant withEnum.getDeclaringClass()- Returns:
- a new EnumOrderedSet with the specified universe of possible items, but none present in the set
-
allOf
Creates a new EnumOrderedSet 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 EnumOrderedSet with the specified universe of possible items, and all of them present in the set
-
complementOf
Given another EnumOrderedSet, this creates a new EnumOrderedSet 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 EnumOrderedSet that this will copy- Returns:
- a complemented copy of
other
-
copyOf
Creates an EnumOrderedSet holding any Enum items in the givencontents, which may be any Collection of Enum, including another EnumOrderedSet. If given an EnumOrderedSet, 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 EnumOrderedSet- Returns:
- a new EnumOrderedSet containing the unique items in contents
-
range
Creates an EnumOrderedSet 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 EnumOrderedSet containing start, end, and any Enum constants with ordinals between them
- Throws:
IllegalArgumentException- if theordinalof end is less than the ordinal of start
-