Class NumberedSet<T>

java.lang.Object
com.github.tommyettinger.ds.NumberedSet<T>
Type Parameters:
T - the type of items; should implement Object.equals(Object) and Object.hashCode()
All Implemented Interfaces:
Arrangeable, EnhancedCollection<T>, Ordered<T>, Iterable<T>, Collection<T>, Set<T>

public class NumberedSet<T> extends Object implements Set<T>, Ordered<T>, EnhancedCollection<T>
An Ordered Set of T items where the indexOf(Object) operation runs in constant time, but any removal from the middle of the order runs in linear time. If you primarily append to a Set with add(Object), this will perform like ObjectIntOrderedMap, since it's backed internally by one of those Maps; indexOf() delegates to the map's ObjectIntMap.get(Object) method. This has to do some bookkeeping to make sure the index for each item is stored as the value for the key matching the item in the map. That bookkeeping will fail if you use the Iterator.remove() method on this class' iterator; you can correct the indices with renumber(), or renumber(int) if you know the first incorrect index.
  • Field Details

  • Constructor Details

    • NumberedSet

      public NumberedSet()
    • NumberedSet

      public NumberedSet(int initialCapacity, float loadFactor)
    • NumberedSet

      public NumberedSet(int initialCapacity)
    • NumberedSet

      public NumberedSet(NumberedSet<? extends T> other)
    • NumberedSet

      public NumberedSet(Ordered<? extends T> ordered)
      Can be used to make a NumberedSet from any Ordered map or set with Object keys or items, using the keys for a map and the items for a set.
      Parameters:
      ordered - any Ordered with the same type as this NumberSet
    • NumberedSet

      public NumberedSet(Iterator<? extends T> coll)
      Creates a new set that contains all distinct elements in coll.
      Parameters:
      coll - all distinct items in this Collection will become items in this NumberedSet
    • NumberedSet

      public NumberedSet(Collection<? extends T> coll)
      Creates a new set that contains all distinct elements in coll.
      Parameters:
      coll - all distinct items in this Collection will become items in this NumberedSet
    • NumberedSet

      public NumberedSet(T[] items)
      Creates a new set that contains all distinct elements in items.
      Parameters:
      items - all distinct elements in this array will become items in this NumberedSet
    • NumberedSet

      public NumberedSet(Ordered<T> 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

    • place

      protected int place(Object item)
      Returns an index >= 0 and <= ObjectIntMap.mask for the specified item, mixed.
      Parameters:
      item - a non-null Object; its hashCode() method should be used by most implementations
      Returns:
      an index between 0 and ObjectIntMap.mask (both inclusive)
    • equate

      protected boolean equate(Object left, Object right)
      Compares the objects left and right, which are usually keys, for equality, returning true if they are considered equal. This is used by the rest of this class to determine whether two keys are considered equal. Normally, this returns left.equals(right), but subclasses can override it to use reference equality, fuzzy equality, deep array equality, or any other custom definition of equality. Usually, place(Object) is also overridden if this method is.
      You can override this, which will affect the internal map that NumberedSet uses.
      Parameters:
      left - must be non-null; typically a key being compared, but not necessarily
      right - may be null; typically a key being compared, but can often be null for an empty key slot, or some other type
      Returns:
      true if left and right are considered equal for the purposes of this class
    • order

      public ObjectList<T> order()
      Description copied from interface: Ordered
      Gets the ObjectList of T items that this data structure holds, in the order it uses for iteration. This should usually return a direct reference to an ObjectList used inside this object, so changes to the list will affect this.
      Specified by:
      order in interface Ordered<T>
      Returns:
      the ObjectList of T items that this data structure holds
    • renumber

      public void renumber()
      Reassigns all index values to match order(). This should be called if you have removed any items using Iterator.remove() from this NumberedSet, since the iterator's remove() method doesn't update the numbering on its own. Use this method if you don't know the first incorrect index, or renumber(int) if you do. Note that you can remove multiple items using the iterator, and only need to renumber just before you need the indices (such as for indexOf(Object)).
    • renumber

      public void renumber(int start)
      Reassigns the index values for each index starting with start, and going to the end. This should be called if you have removed any items using Iterator.remove() from this NumberedSet, since the iterator's remove() method doesn't update the numbering on its own. Use renumber() with no argument if you don't know the first incorrect index, or this method if you do. Note that you can remove multiple items using the iterator, and only need to renumber just before you need the indices (such as for indexOf(Object)).
      Parameters:
      start - the first index to reassign, which must be non-negative
    • remove

      public boolean remove(Object item)
      Tries to remove an item from this set and calls renumber(int) if that item was removed
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface Set<T>
      Parameters:
      item - object to be removed from this set, if present
      Returns:
      true if this set was modified, or false if it wasn't
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<T>
      Specified by:
      containsAll in interface Set<T>
    • containsAll

      public boolean containsAll(Object[] values)
      Description copied from interface: EnhancedCollection
      Returns true if this collection contains all the elements in the specified array.
      Specified by:
      containsAll in interface EnhancedCollection<T>
      Parameters:
      values - a non-null array to have items checked for containment in this collection
      Returns:
      true if this collection contains all the elements in the specified collection
      See Also:
    • containsAll

      public boolean containsAll(Object[] values, int offset, int length)
      Description copied from interface: EnhancedCollection
      Returns true if this collection contains all the elements in the specified array starting from offset and using length items from the array.
      Specified by:
      containsAll in interface EnhancedCollection<T>
      Parameters:
      values - a non-null array to have items checked for containment in this collection
      offset - the first index in array to use
      length - how many items from array should be used
      Returns:
      true if this collection contains all the elements in the specified collection
      See Also:
    • containsAnyIterable

      public boolean containsAnyIterable(Iterable<?> c)
      Description copied from interface: EnhancedCollection
      Like Collection.containsAll(Collection), but returns true immediately if any item in the given Iterable other is present in this EnhancedCollection.
      Specified by:
      containsAnyIterable in interface EnhancedCollection<T>
      Parameters:
      c - a Collection or other Iterable of any type to look through
      Returns:
      true if any items from the Iterable are present in this EnhancedCollection
    • containsAny

      public boolean containsAny(Object[] values)
      Specified by:
      containsAny in interface EnhancedCollection<T>
    • containsAny

      public boolean containsAny(Object[] values, int offset, int length)
      Description copied from interface: EnhancedCollection
      Like Collection.containsAll(Collection), but returns true immediately if any item in the given array is present in this EnhancedCollection.
      Specified by:
      containsAny in interface EnhancedCollection<T>
      Parameters:
      values - an array to look through; will not be modified
      offset - the first index in array to check
      length - how many items in array to check
      Returns:
      true if any items from array are present in this EnhancedCollection
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Set<T>
    • addAll

      public boolean addAll(Ordered<T> 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 T
      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 addAll(Collection) does
    • addAll

      public boolean addAll(int insertionIndex, Ordered<T> 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 T
      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 addAll(Collection) does
    • addAll

      public boolean addAll(T[] array)
      Adds all items in the T array array to this set, inserting at the end of the iteration order.
      Specified by:
      addAll in interface EnhancedCollection<T>
      Parameters:
      array - a non-null array of T
      Returns:
      true if this is modified by this call, as addAll(Collection) does
    • addAll

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

      public boolean addAll(int insertionIndex, T[] array, int offset, int count)
      Adds up to count items, starting from offset, in the T array array to this set, inserting starting at insertionIndex in the iteration order.
      Parameters:
      insertionIndex - where to insert into the iteration order
      array - a non-null array of T
      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 addAll(Collection) does
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T>
      Specified by:
      retainAll in interface Set<T>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface Set<T>
    • removeAll

      public boolean removeAll(Object[] arr)
      Bulk-removes each item in the given array from this set. If an item appears more than once in arr, this will be able to quickly verify that it was removed the first time it appeared, and won't spend as long processing later items. This calls renumber() only after all removals were completed, and only if one or more items were actually removed.
      Specified by:
      removeAll in interface EnhancedCollection<T>
      Parameters:
      arr - a non-null array of items to remove from this set
      Returns:
      true if this had one or more items removed, or false if it is unchanged
    • removeAll

      public boolean removeAll(Object[] values, int offset, int length)
      Bulk-removes each item in the given array from this set. If an item appears more than once in values, this will be able to quickly verify that it was removed the first time it appeared, and won't spend as long processing later items. This calls renumber() only after all removals were completed, and only if one or more items were actually removed.
      Specified by:
      removeAll in interface EnhancedCollection<T>
      Parameters:
      values - a non-null array of items to remove from this set
      offset - the index of the first item in values to remove
      length - how many items, at most, to get from values and remove from this
      Returns:
      true if this had one or more items removed, or false if it is unchanged
    • removeAt

      public T 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
    • ensureCapacity

      public void ensureCapacity(int additionalCapacity)
      Increases the size of the backing array to accommodate the specified number of additional items / loadFactor. Useful before adding many items to avoid multiple backing array resizes.
      Parameters:
      additionalCapacity - how many more items this must be able to hold; the load factor increases the actual capacity change
    • getHashMultiplier

      public int getHashMultiplier()
      Gets the current hashMultiplier, used in place(Object) to mix hash codes. If setHashMultiplier(int) is never called, the hashMultiplier will always be drawn from Utilities.GOOD_MULTIPLIERS, with the index equal to 64 - shift.
      Returns:
      the current hashMultiplier
    • setHashMultiplier

      public void setHashMultiplier(int hashMultiplier)
      Sets the hashMultiplier to the given int, which will be made odd if even and always negative (by OR-ing with 0x80000001). This can be any negative, odd int, but should almost always be drawn from Utilities.GOOD_MULTIPLIERS or something like it.
      Parameters:
      hashMultiplier - any int; will be made odd if even.
    • getTableSize

      public int getTableSize()
      Gets the length of the internal array used to store all keys, as well as empty space awaiting more items to be entered. This length is equal to the length of the array used to store all values, and empty space for values, here. This is also called the capacity.
      Returns:
      the length of the internal array that holds all keys
    • alter

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

      public boolean alterAt(int index, T after)
      Changes the item at the given index in the order to after, without changing the ordering of other entries or any values. If after is already present, this returns false; it will also return false if index is invalid for the size of this map. Otherwise, it returns true. Unlike alter(Object, Object), this operates in constant time.
      Parameters:
      index - the index in the order of the item to change; must be non-negative and less than 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 item at index, false otherwise
    • getAt

      public T getAt(int index)
      Returns the item at the given index, which must be at least 0 and less than size().
      Parameters:
      index - the index to retrieve; must be between 0, inclusive, and size(), exclusive
      Returns:
      the item at index
    • clear

      public void clear(int maximumCapacity)
      Clears the map and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger.
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface Set<T>
    • indexOf

      public int indexOf(Object item)
      Gets the index of a given item in this set's ordering. Unlike most collections, this takes O(1) time here. This returns getDefaultValue() (usually -1) if the item was not present.
      Parameters:
      item - the item to retrieve the index for
      Returns:
      the index of the item, or getDefaultValue() (usually -1) if it was not found
    • indexOfOrDefault

      public int indexOfOrDefault(Object item, int defaultValue)
      Gets the index of a given item in this set's ordering. Unlike most collections, this takes O(1) time here. This returns defaultValue if the item was not present.
      Parameters:
      item - the item to retrieve the index for
      Returns:
      the index of the item, or defaultValue if it was not found
    • notEmpty

      public boolean notEmpty()
    • size

      public int size()
      Description copied from interface: Arrangeable
      Returns the number of elements in this Arrangeable. Often this is shared with Collection.size(), but isn't always.
      Specified by:
      size in interface Arrangeable
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface Set<T>
      Returns:
      the number of elements in this Arrangeable
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface Set<T>
    • getDefaultValue

      public int getDefaultValue()
      Gets the default value, a int which is returned by indexOf(Object) if the key is not found. If not changed, the default value is -1 .
      Returns:
      the current default value
    • setDefaultValue

      public void setDefaultValue(int defaultValue)
      Sets the default value, a int which is returned by indexOf(Object) if the key is not found. If not changed, the default value is -1 . Note that indexOfOrDefault(Object, int) is also available, which allows specifying a "not-found" value per-call.
      Parameters:
      defaultValue - may be any int; should usually be one that doesn't occur as a typical value
    • shrink

      public void shrink(int maximumCapacity)
    • contains

      public boolean contains(Object item)
      Returns true if this NumberedSet contains the given item, or false otherwise.
      Specified by:
      contains in interface Collection<T>
      Specified by:
      contains in interface Set<T>
      Parameters:
      item - element whose presence in this set is to be tested
      Returns:
      true if this set contains item, or false otherwise
    • 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.
      Parameters:
      newSize - the target size to try to reach by removing items, if smaller than the current size
    • iterator

      public NumberedSet.NumberedSetIterator<T> iterator()
      Returns a ListIterator starting at index 0. This caches the iterator to avoid repeated allocation, and so is not suitable for nested iteration. You can use NumberedSetIterator(NumberedSet) if you need nested iteration. This is equivalent to listIterator().
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>
      Returns:
      a ListIterator, or more specifically a NumberedSet.NumberedSetIterator over this set
    • listIterator

      public NumberedSet.NumberedSetIterator<T> listIterator()
      Returns a ListIterator starting at index 0. This caches the iterator to avoid repeated allocation, and so is not suitable for nested iteration. You can use NumberedSetIterator(NumberedSet) if you need nested iteration.
      Returns:
      a ListIterator, or more specifically a NumberedSet.NumberedSetIterator over this set
    • listIterator

      public NumberedSet.NumberedSetIterator<T> listIterator(int index)
      Returns a ListIterator starting at the specified index. This caches the iterator to avoid repeated allocation, and so is not suitable for nested iteration. You can use NumberedSetIterator(NumberedSet, int) if you need nested iteration. Giving an index of 0 is equivalent to calling listIterator(), and starts at the first item in the order.
      Parameters:
      index - the first index in this set's order to iterate from
      Returns:
      a ListIterator, or more specifically a NumberedSet.NumberedSetIterator over this set
    • 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<T>
      Parameters:
      start - the first index to remove, inclusive
      end - the last index (after what should be removed), exclusive
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
    • toArray

      public <T1> T1[] toArray(T1[] a)
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface Set<T>
    • add

      public boolean add(T t)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Set<T>
    • addOrIndex

      public int addOrIndex(T t)
      If the given item t is present, this returns its index without modifying the NumberedSet; otherwise, it adds t to the end of the collection and returns the index for it there.
      Parameters:
      t - an item to get the index of, adding it if not present
      Returns:
      the index of t in this Arrangement
    • add

      public boolean add(int index, T 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 T 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)
    • resize

      public void resize(int newSize)
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface Set<T>
      Overrides:
      equals in class Object
    • getLoadFactor

      public float getLoadFactor()
    • setLoadFactor

      public void setLoadFactor(float loadFactor)
    • first

      public T 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<T>
      Returns:
      the first item in this EnhancedCollection, as produced by Collection.iterator()
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<T>
      Specified by:
      hashCode in interface Set<T>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(String itemSeparator)
      Delegates to toString(String, boolean) with the given itemSeparator and without braces. This is different from toString(), which includes braces by default.
      Specified by:
      toString in interface EnhancedCollection<T>
      Parameters:
      itemSeparator - how to separate set items, such as ", "
      Returns:
      a new String representing this set
    • toString

      public String toString(String itemSeparator, boolean braces)
      Description copied from interface: EnhancedCollection
      Makes a String from the contents of this EnhancedCollection, using the Object.toString() method of each item, separating items with the given itemSeparator, and wrapping the result in square brackets if brackets is true.
      Delegates to EnhancedCollection.appendTo(CharSequence, String, boolean).
      Specified by:
      toString in interface EnhancedCollection<T>
      Parameters:
      itemSeparator - how to separate items, such as ", "
      braces - true to wrap the result in square brackets, or false to leave the items unadorned
      Returns:
      a new String representing this EnhancedCollection
    • toString

      public String toString(String entrySeparator, boolean braces, Appender<T> keyAppender)
      Makes a String from the contents of this NumberedSet, but uses the given Appender to convert all set items to a customizable representation and append them to a temporary StringBuilder. To use the default String representation, you can use Appender::append as an appender.
      Specified by:
      toString in interface EnhancedCollection<T>
      Parameters:
      entrySeparator - how to separate set items, such as ", "
      braces - true to wrap the output in curly braces, or false to omit them
      keyAppender - a function that takes a StringBuilder and a T, and returns the modified StringBuilder
      Returns:
      a new String representing this set
    • appendTo

      public StringBuilder appendTo(StringBuilder sb, String entrySeparator, boolean braces)
    • appendTo

      public StringBuilder appendTo(StringBuilder sb, String itemSeparator, boolean braces, Appender<T> keyAppender)
      Appends to a StringBuilder from the contents of this NumberedSet, but uses the given Appender to convert all keys to a customizable representation and append them to a StringBuilder. To use the default String representation, you can use Appender::append as an appender.
      Parameters:
      sb - a StringBuilder that this can append to
      itemSeparator - how to separate set items, such as ", "
      braces - true to wrap the output in curly braces, or false to omit them
      keyAppender - a function that takes a StringBuilder and a T, and returns the modified StringBuilder
      Returns:
      sb, with the appended items of this set
    • with

      public static <T> NumberedSet<T> 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.
      Type Parameters:
      T - the type of items; must be given explicitly
      Returns:
      a new set containing nothing
    • with

      public static <T> NumberedSet<T> with(T item)
      Creates a new NumberedSet that holds only the given item, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item - one T item
      Returns:
      a new NumberedSet that holds the given item
    • with

      public static <T> NumberedSet<T> with(T item0, T item1)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      public static <T> NumberedSet<T> with(T item0, T item1, T item2)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      public static <T> NumberedSet<T> with(T item0, T item1, T item2, T item3)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      item3 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      public static <T> NumberedSet<T> with(T item0, T item1, T item2, T item3, T item4)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      item3 - a T item
      item4 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      public static <T> NumberedSet<T> with(T item0, T item1, T item2, T item3, T item4, T item5)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      item3 - a T item
      item4 - a T item
      item5 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      public static <T> NumberedSet<T> with(T item0, T item1, T item2, T item3, T item4, T item5, T item6)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      item3 - a T item
      item4 - a T item
      item5 - a T item
      item6 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      public static <T> NumberedSet<T> with(T item0, T item1, T item2, T item3, T item4, T item5, T item6, T item7)
      Creates a new NumberedSet that holds only the given items, but can be resized.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      item3 - a T item
      item4 - a T item
      item5 - a T item
      item6 - a T item
      Returns:
      a new NumberedSet that holds the given items
    • with

      @SafeVarargs public static <T> NumberedSet<T> with(T... varargs)
      Creates a new NumberedSet 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.
      Type Parameters:
      T - the type of item, typically inferred
      Parameters:
      varargs - a T varargs or T array; remember that varargs allocate
      Returns:
      a new NumberedSet that holds the given items
    • parse

      public static <T> NumberedSet<T> parse(String str, String delimiter, PartialParser<T> parser)
      Calls parse(String, String, PartialParser, boolean) with brackets set to false.
      Parameters:
      str - a String that will be parsed in full
      delimiter - the delimiter between items in str
      parser - a PartialParser that returns a T item from a section of str
      Returns:
      a new collection parsed from str
    • parse

      public static <T> NumberedSet<T> parse(String str, String delimiter, PartialParser<T> 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.
      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 a T 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 <T> NumberedSet<T> parse(String str, String delimiter, PartialParser<T> 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.
      Parameters:
      str - a String that will have the given section parsed
      delimiter - the delimiter between items in str
      parser - a PartialParser that returns a T 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