Class EnumOrderedSet

All Implemented Interfaces:
Arrangeable, EnhancedCollection<Enum<?>>, Ordered<Enum<?>>, Iterable<Enum<?>>, Collection<Enum<?>>, Set<Enum<?>>

public class EnumOrderedSet extends EnumSet implements Ordered<Enum<?>>
An 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.
  • Field Details

  • Constructor Details

    • EnumOrderedSet

      public EnumOrderedSet(OrderType type)
      Only specifies an OrderType; using this will postpone allocating any internal arrays until add(Enum) is first called (potentially indirectly).
      Parameters:
      type - either OrderType.BAG to 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(Enum<?>[] universe, boolean ignoredToDistinguish, OrderType type)
      Initializes this set so that it has exactly enough capacity as needed to contain each Enum constant defined in universe, assuming universe stores every possible constant in one Enum type. You almost always obtain universe from calling values() 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 the boolean parameter here is easy to forget, you may want to prefer calling noneOf(Enum[]) instead of using this directly.
      Parameters:
      universe - almost always, the result of calling values() on an Enum type; used directly, not copied
      ignoredToDistinguish - an ignored boolean that differentiates this constructor, which defined a key universe, from one that takes contents
      type - either OrderType.BAG to 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(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 Class universeClass, assuming universeClass is non-null. This simply calls EnumOrderedSet(Enum[], boolean) for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you use EnumOrderedSet(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
      type - either OrderType.BAG to 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(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 in contents.
      Parameters:
      contents - a Collection of Enum items to place into this set
      type - either OrderType.BAG to 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(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 in contents.
      Parameters:
      contents - a Collection of Enum items to place into this set
      type - either OrderType.BAG to 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(EnumSet other, OrderType type)
      Copy constructor; uses a direct reference to the enum values that may be cached in other, but copies other fields.
      Parameters:
      other - another EnumSet that will have most of its data copied, but its cached values() results will be used directly
      type - either OrderType.BAG to 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(EnumOrderedSet other, OrderType type)
      Copies other but allows specifying an OrderType independently of other's ordering.
      Parameters:
      other - another EnumOrderedSet that will have its contents copied
      type - either OrderType.BAG to 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(Enum<?>[] array, int offset, int length, OrderType type)
      Creates a new set using length items from the given array, starting at offset (inclusive).
      Parameters:
      array - an array to draw items from
      offset - the first index in array to draw an item from
      length - how many items to take from array; bounds-checking is the responsibility of the using code
      type - either OrderType.BAG to 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(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 in contents.
      This is different from EnumOrderedSet(Enum[], boolean) in that this takes constants and puts them in the set, while the other constructor takes all possible Enum constants, usually from calling values(). You can also specify the contents of a new EnumSet conveniently using with(Enum[]), which allows passing items as varargs.
      Parameters:
      contents - an array of Enum items to place into this set
      type - either OrderType.BAG to 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(Ordered<Enum<?>> other, int offset, int count, OrderType type)
      Creates a new set by copying count items from the given Ordered, starting at offset in that Ordered, into this.
      Parameters:
      other - another Ordered of the same type
      offset - the first index in other's ordering to draw an item from
      count - how many items to copy from other
      type - either OrderType.BAG to 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 until add(Enum) is first called (potentially indirectly).
    • EnumOrderedSet

      public EnumOrderedSet(Enum<?>[] universe, boolean ignoredToDistinguish)
      Initializes this set so that it has exactly enough capacity as needed to contain each Enum constant defined in universe, assuming universe stores every possible constant in one Enum type. You almost always obtain universe from calling values() 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 the boolean parameter here is easy to forget, you may want to prefer calling noneOf(Enum[]) instead of using this directly.
      Parameters:
      universe - almost always, the result of calling values() on an Enum type; used directly, not copied
      ignoredToDistinguish - an ignored boolean that differentiates this constructor, which defined a key universe, from one that takes contents
    • EnumOrderedSet

      public 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 Class universeClass, assuming universeClass is non-null. This simply calls EnumOrderedSet(Enum[], boolean) for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you use EnumOrderedSet(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

      public 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 in contents.
      Parameters:
      contents - a Collection of Enum items to place into this set
    • EnumOrderedSet

      public 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 in contents.
      Parameters:
      contents - a Collection of Enum items to place into this set
    • EnumOrderedSet

      public EnumOrderedSet(EnumSet other)
      Copy constructor; uses a direct reference to the enum values that may be cached in other, but copies other fields.
      Parameters:
      other - another EnumSet that will have most of its data copied, but its cached values() results will be used directly
    • EnumOrderedSet

      public EnumOrderedSet(EnumOrderedSet other)
      Copies the entirety of other, including using the same OrderType.
      Parameters:
      other - another EnumOrderedSet that will have its contents and ordering copied
    • EnumOrderedSet

      public EnumOrderedSet(Enum<?>[] array, int offset, int length)
      Creates a new set using length items from the given array, starting at offset (inclusive).
      Parameters:
      array - an array to draw items from
      offset - the first index in array to draw an item from
      length - how many items to take from array; bounds-checking is the responsibility of the using code
    • EnumOrderedSet

      public 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 in contents.
      This is different from EnumOrderedSet(Enum[], boolean) in that this takes constants and puts them in the set, while the other constructor takes all possible Enum constants, usually from calling values(). You can also specify the contents of a new EnumSet conveniently using with(Enum[]), which allows passing items as varargs.
      Parameters:
      contents - an array of Enum items to place into this set
    • EnumOrderedSet

      public EnumOrderedSet(Ordered<Enum<?>> other, int offset, int count)
      Creates a new set by copying count items from the given Ordered, starting at offset in that Ordered, into this.
      Parameters:
      other - another Ordered of the same type
      offset - the first index in other's ordering to draw an item from
      count - how many items to copy from other
  • Method Details

    • add

      public boolean add(Enum<?> key)
      Description copied from class: EnumSet
      Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the set unchanged and returns false. 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 for Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

      Specified by:
      add in interface Collection<Enum<?>>
      Specified by:
      add in interface Set<Enum<?>>
      Overrides:
      add in class EnumSet
      Parameters:
      key - element to be added to this set
      Returns:
      true if this set did not already contain the specified element
    • add

      public boolean add(int index, Enum<?> key)
      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 in ObjectList and 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 present
      key - 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

      public boolean addAll(Ordered<Enum<?>> other, int offset, int count)
      Adds up to count items, starting from offset, in the Ordered other to this set, inserting at the end of the iteration order.
      Parameters:
      other - a non-null Ordered of Enum
      offset - the first index in other to use
      count - how many indices in other to use
      Returns:
      true if this is modified by this call, as EnumSet.addAll(Collection) does
    • addAll

      public boolean addAll(int insertionIndex, Ordered<Enum<?>> other, int offset, int count)
      Adds up to count items, starting from offset, in the Ordered other to this set, inserting starting at insertionIndex in the iteration order.
      Parameters:
      insertionIndex - where to insert into the iteration order
      other - a non-null Ordered of Enum
      offset - the first index in other to use
      count - how many indices in other to use
      Returns:
      true if this is modified by this call, as EnumSet.addAll(Collection) does
    • addAll

      public boolean addAll(Enum<?>[] other, int offset, int count)
      Adds up to count items, starting from offset, in the Ordered other to this set, inserting at the end of the iteration order.
      Specified by:
      addAll in interface EnhancedCollection<Enum<?>>
      Parameters:
      other - a non-null Ordered of Enum
      offset - the first index in other to use
      count - how many indices in other to use
      Returns:
      true if this is modified by this call, as EnumSet.addAll(Collection) does
    • addAll

      public boolean addAll(int insertionIndex, Enum<?>[] other, int offset, int count)
      Adds up to count items, starting from offset, in the Ordered other to this set, inserting starting at insertionIndex in the iteration order.
      Parameters:
      insertionIndex - where to insert into the iteration order
      other - a non-null Ordered of Enum
      offset - the first index in other to use
      count - how many indices in other to use
      Returns:
      true if this is modified by this call, as EnumSet.addAll(Collection) does
    • remove

      public boolean remove(Object key)
      Description copied from class: EnumSet
      Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that Objects.equals(item, e), if this set contains such an element. Returns true if 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:
      remove in interface Collection<Enum<?>>
      Specified by:
      remove in interface Set<Enum<?>>
      Overrides:
      remove in class EnumSet
      Parameters:
      key - object to be removed from this set, if present
      Returns:
      true if this set contained the specified element
    • removeAt

      public Enum<?> removeAt(int index)
      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

      public boolean alter(Enum<?> before, Enum<?> after)
      Changes the item before to after without changing its position in the order. Returns true if after has been added to the EnumOrderedSet and before has been removed; returns false if after is already present or before is not present. If you are iterating over an EnumOrderedSet and have an index, you should prefer alterAt(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 succeed
      after - an item that must not be in this set for this to succeed
      Returns:
      true if before was removed and after was added, false otherwise
    • alterAt

      public boolean alterAt(int index, Enum<?> after)
      Changes the item at the given index in the order to after, without changing the ordering of other items. If after is already present, this returns false; it will also return false if index is invalid for the size of this set. Otherwise, it returns true. Unlike alter(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 than EnumSet.size
      after - the item that will replace the contents at index; this item must not be present for this to succeed
      Returns:
      true if after successfully replaced the contents at index, false otherwise
    • getAt

      public Enum<?> getAt(int index)
      Gets the Enum item at the given index in the insertion order. The index should be between 0 (inclusive) and EnumSet.size() (exclusive).
      Parameters:
      index - an index in the insertion order, between 0 (inclusive) and EnumSet.size() (exclusive)
      Returns:
      the item at the given index
    • first

      public Enum<?> first()
      Description copied from interface: EnhancedCollection
      Attempts 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 like List.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 uses Collection.iterator(), tries to get the first item, or throws an IllegalStateException if this is empty.
      Specified by:
      first in interface EnhancedCollection<Enum<?>>
      Returns:
      the first item in this EnhancedCollection, as produced by Collection.iterator()
    • clear

      public void clear()
      Description copied from class: EnumSet
      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:
      clear in interface Collection<Enum<?>>
      Specified by:
      clear in interface Set<Enum<?>>
      Overrides:
      clear in class EnumSet
    • clearToUniverse

      public void clearToUniverse(Enum<?>[] universe)
      Description copied from class: EnumSet
      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 universe. If universe is null, this resets this set to the state it would have after EnumSet() was called. If the table this would need is the same size as or smaller than the current table (such as if universe is 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 uses universe directly, without copying.
      This can be useful to allow an EnumSet that was created with EnumSet() to share a universe with other EnumSets.
      Overrides:
      clearToUniverse in class EnumSet
      Parameters:
      universe - the universe of possible Enum items this can hold; almost always produced by values() on an Enum
    • clearToUniverse

      public void clearToUniverse(Class<? extends Enum<?>> universe)
      Description copied from class: EnumSet
      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 in universe. If universe is null, this resets this set to the state it would have after EnumSet() was called. If the table this would need is the same size as or smaller than the current table (such as if universe is 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 calls Class.getEnumConstants() if universe is non-null, which allocates a new array.
      You may want to prefer calling EnumSet.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 call Class.getEnumConstants() and thus allocate a new array each time this is called.
      Overrides:
      clearToUniverse in class EnumSet
      Parameters:
      universe - the Class of an Enum type that stores the universe of possible Enum items this can hold
    • order

      public ObjectList<Enum<?>> 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.
      Specified by:
      order in interface Ordered<Enum<?>>
      Returns:
      the ObjectList of keys, in iteration order (usually insertion-order), that this uses
    • sort

      public void sort()
      Sorts this EnumOrderedMap in-place by the keys' natural ordering.
    • sort

      public void sort(Comparator<? super Enum<?>> comp)
      Sorts this EnumOrderedMap in-place by the given Comparator used on the keys. If comp is null, then this will sort by the natural ordering of the keys.
      Specified by:
      sort in interface Ordered<Enum<?>>
      Parameters:
      comp - a Comparator that can compare two Enum keys, or null to use the keys' natural ordering
    • 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:
      removeRange in interface Ordered<Enum<?>>
      Parameters:
      start - the first index to remove, inclusive
      end - 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.
      Overrides:
      truncate in class EnumSet
      Parameters:
      newSize - the target size to try to reach by removing items, if smaller than the current size
    • iterator

      public EnumSet.EnumSetIterator iterator()
      Iterates through items in the same order as order(). Reuses one of two iterators, and does not permit nested iteration; use EnumOrderedSetIterator(EnumOrderedSet) to nest iterators.
      Specified by:
      iterator in interface Collection<Enum<?>>
      Specified by:
      iterator in interface Iterable<Enum<?>>
      Specified by:
      iterator in interface Set<Enum<?>>
      Overrides:
      iterator in class EnumSet
      Returns:
      an Iterator over the Enum items in this, in order
    • toString

      public String toString(String itemSeparator)
      Description copied from interface: EnhancedCollection
      Delegates to EnhancedCollection.toString(String, boolean) with the given itemSeparator and without surrounding brackets.
      Specified by:
      toString in interface EnhancedCollection<Enum<?>>
      Parameters:
      itemSeparator - how to separate items, such as ", "
      Returns:
      a new String representing this map
    • toString

      public String toString()
      Overrides:
      toString in class EnumSet
    • with

      public static EnumOrderedSet 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

      public static EnumOrderedSet with(Enum<?> item)
      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

      public static EnumOrderedSet with(Enum<?> item0, Enum<?> item1)
      Creates a new EnumOrderedSet that holds only the given items, but can be resized.
      Parameters:
      item0 - an Enum item
      item1 - an Enum item
      Returns:
      a new EnumOrderedSet that holds the given items
    • with

      public static EnumOrderedSet with(Enum<?> item0, Enum<?> item1, Enum<?> item2)
      Creates a new EnumOrderedSet that holds only the given items, but can be resized.
      Parameters:
      item0 - an Enum item
      item1 - an Enum item
      item2 - 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)
      Creates a new EnumOrderedSet that holds only the given items, but can be resized.
      Parameters:
      item0 - an Enum item
      item1 - an Enum item
      item2 - an Enum item
      item3 - 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 item
      item1 - an Enum item
      item2 - an Enum item
      item3 - an Enum item
      item4 - 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 item
      item1 - an Enum item
      item2 - an Enum item
      item3 - an Enum item
      item4 - an Enum item
      item5 - 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 item
      item1 - an Enum item
      item2 - an Enum item
      item3 - an Enum item
      item4 - an Enum item
      item5 - an Enum item
      item6 - 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 item
      item1 - an Enum item
      item2 - an Enum item
      item3 - an Enum item
      item4 - an Enum item
      item5 - an Enum item
      item6 - an Enum item
      Returns:
      a new EnumOrderedSet that holds the given items
    • with

      public static EnumOrderedSet with(Enum<?>... varargs)
      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

      public static EnumOrderedSet parse(String str, String delimiter, PartialParser<Enum<?>> parser)
      Calls parse(String, String, PartialParser, boolean) with brackets set to false.
      The parser is often produced by PartialParser.enumParser(ObjToObjFunction).
      Parameters:
      str - a String that will be parsed in full
      delimiter - the delimiter between items in str
      parser - a PartialParser that returns an Enum item from a section of str
      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 calling EnhancedCollection.addLegible(String, String, PartialParser, int, int) on either all of str (if brackets is false) or str without its first and last chars (if brackets is true). Each item is expected to be separated by delimiter.
      The parser is often produced by PartialParser.enumParser(ObjToObjFunction).
      Parameters:
      str - a String that will be parsed in full (depending on brackets)
      delimiter - the delimiter between items in str
      parser - a PartialParser that returns an Enum item from a section of str
      brackets - 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 calling EnhancedCollection.addLegible(String, String, PartialParser, int, int) with the given five parameters as-is.
      The parser is often produced by PartialParser.enumParser(ObjToObjFunction).
      Parameters:
      str - a String that will have the given section parsed
      delimiter - the delimiter between items in str
      parser - a PartialParser that returns an Enum item from a section of str
      offset - the first position to parse in str, inclusive
      length - how many chars to parse, starting from offset
      Returns:
      a new collection parsed from str
    • of

      public static EnumOrderedSet of(Enum<?> item)
      Alias of with(Enum) for compatibility.
      Parameters:
      item - the one item to initialize the EnumSet with
      Returns:
      a new EnumOrderedSet containing item
    • of

      public static EnumOrderedSet of(Enum<?>... array)
      Alias of with(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

      public static EnumOrderedSet noneOf(Enum<?>[] universe)
      Creates a new EnumOrderedSet using the given result of calling values() 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 calling EnumOrderedSet(Enum[], boolean).
      Parameters:
      universe - almost always, the result of calling values() 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

      public static EnumOrderedSet allOf(Enum<?>[] universe)
      Creates a new EnumOrderedSet using the given result of calling values() 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 calling values() 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

      public static EnumOrderedSet noneOf(Class<? extends Enum<?>> clazz)
      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 calling EnumOrderedSet(Class).
      Parameters:
      clazz - the Class of any Enum type; you can get this from a constant with Enum.getDeclaringClass()
      Returns:
      a new EnumOrderedSet with the specified universe of possible items, but none present in the set
    • allOf

      public static EnumOrderedSet allOf(Class<? extends Enum<?>> clazz)
      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 with Enum.getDeclaringClass()
      Returns:
      a new EnumOrderedSet with the specified universe of possible items, and all of them present in the set
    • complementOf

      public static EnumOrderedSet complementOf(EnumOrderedSet other)
      Given another EnumOrderedSet, this creates a new EnumOrderedSet with the same universe as other, 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

      public static EnumOrderedSet copyOf(Collection<? extends Enum<?>> contents)
      Creates an EnumOrderedSet holding any Enum items in the given contents, 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

      public static <E extends Enum<E>> EnumOrderedSet range(Enum<E> start, Enum<E> end)
      Creates an EnumOrderedSet holding Enum items between the ordinals of start and end. If the ordinal of end is less than the ordinal of start, this throws an IllegalArgumentException. 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 insert
      end - the ending inclusive Enum to insert
      Returns:
      a new EnumOrderedSet containing start, end, and any Enum constants with ordinals between them
      Throws:
      IllegalArgumentException - if the ordinal of end is less than the ordinal of start