Class ObjectList<T>

All Implemented Interfaces:
Arrangeable, Arrangeable.ArrangeableList<T>, EnhancedCollection<T>, Ordered<T>, Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess
Direct Known Subclasses:
ObjectBag

public class ObjectList<T> extends ArrayList<T> implements Ordered<T>, EnhancedCollection<T>, Arrangeable.ArrangeableList<T>
A resizable, insertion-ordered list of T items, typically objects (they can also be arrays). This is a thin wrapper around ArrayList to implement Ordered and do some of what libGDX's Array class does. Because this is a generic class and arrays do not interact well with generics, ObjectList does not permit access to a T[] of items like Array does; you can use ArrayList.toArray(Object[]) or (if you can use Java 11) toArray(IntFunction) to make a new array of T from the contents of an ArrayList. The second of these toArray methods is newer; You can use it with code like ObjectList<String> myList = new ObjectList<>(); String[] s = myList.toArray(String::new);.
See Also:
  • Field Details

  • Constructor Details

    • ObjectList

      public ObjectList(int initialCapacity)
      Constructs an empty list with the specified initial capacity.
      Parameters:
      initialCapacity - the initial capacity of the list
      Throws:
      IllegalArgumentException - if the specified initial capacity is negative
    • ObjectList

      @Deprecated public ObjectList(boolean ordered, int initialCapacity)
      Deprecated.
      This is equivalent to ObjectList(int); make an ObjectBag for an unordered list
      Constructs an empty list with the specified initial capacity.
      Parameters:
      ordered - ignored; use an ObjectBag for an unordered list
      initialCapacity - the initial capacity of the list
      Throws:
      IllegalArgumentException - if the specified initial capacity is negative
    • ObjectList

      public ObjectList()
      Constructs an empty list with an initial capacity of 10.
    • ObjectList

      public ObjectList(Collection<? extends T> c)
      Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
      Parameters:
      c - the collection whose elements are to be placed into this list
      Throws:
      NullPointerException - if the specified collection is null
    • ObjectList

      @Deprecated public ObjectList(boolean ordered, Collection<? extends T> c)
      Deprecated.
      This is equivalent to ObjectList(Collection); make an ObjectBag for an unordered list
      Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
      Parameters:
      ordered - ignored; use an ObjectBag for an unordered list
      c - the collection whose elements are to be placed into this list
      Throws:
      NullPointerException - if the specified collection is null
    • ObjectList

      public ObjectList(Iterator<? extends T> coll)
      Creates a new instance containing the items in the specified iterator.
      Parameters:
      coll - an iterator that will have its remaining contents added to this
    • ObjectList

      public ObjectList(T[] a)
    • ObjectList

      public ObjectList(T[] a, int offset, int count)
    • ObjectList

      public ObjectList(Ordered<T> other, int offset, int count)
      Creates a new list 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

    • keepsOrder

      public boolean keepsOrder()
      Returns true if this implementation retains order, which it does.
      Returns:
      true
    • add

      public void add(int index, T element)
      Specified by:
      add in interface List<T>
      Overrides:
      add in class ArrayList<T>
    • insert

      public void insert(int index, T element)
      This is an alias for add(int, Object) to improve compatibility with primitive lists.
      Parameters:
      index - index at which the specified element is to be inserted
      element - element to be inserted
    • remove

      public T remove(int index)
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class ArrayList<T>
    • removeAt

      public T removeAt(int index)
      This is an alias for remove(int) to make the API the same for primitive lists.
      Parameters:
      index - must be non-negative and less than ArrayList.size()
      Returns:
      the previously-held item at the given index
    • 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. This is also different from removeRange() in the libGDX Array class because it is exclusive on end, instead of how Array is inclusive on end.
      Specified by:
      removeRange in interface Ordered<T>
      Overrides:
      removeRange in class ArrayList<T>
      Parameters:
      start - the first index to remove, inclusive
      end - the last index (after what should be removed), exclusive
    • removeAll

      public boolean removeAll(Object[] other)
      Exactly like ArrayList.removeAll(Collection), but takes an array instead of a Collection.
      Specified by:
      removeAll in interface EnhancedCollection<T>
      Parameters:
      other - array containing elements to be removed from this list
      Returns:
      true if this list changed as a result of the call
      See Also:
    • removeAll

      public boolean removeAll(Object[] array, int offset, int length)
      Like removeAll(Object[]), but only uses at most length items from array, starting at offset.
      Specified by:
      removeAll in interface EnhancedCollection<T>
      Parameters:
      array - the elements to be removed from this list
      offset - the index of the first item in array to remove
      length - how many items, at most, to get from array and remove from this
      Returns:
      true if this list changed as a result of the call
      See Also:
    • removeEachIterable

      public boolean removeEachIterable(Iterable<?> other)
      Removes from this ObjectList element-wise occurrences of elements contained in the specified Iterable. Note that if a value is present more than once in this ObjectList, only one of those occurrences will be removed for each occurrence of that value in other. If other has the same contents as this ObjectList or has additional items, then removing each of other will clear this.
      This matches the behavior of the libGDX Array.removeAll(Array) method in libGDX 1.10.0 and earlier. The method ArrayList.removeAll(Collection) here matches the behavior of the JDK List.removeAll(Collection) method.
      Specified by:
      removeEachIterable in interface EnhancedCollection<T>
      Parameters:
      other - an Iterable of T items to remove one-by-one, such as another ObjectList or an ObjectSet
      Returns:
      true if this list was modified.
    • removeEach

      public boolean removeEach(Object[] array)
      Exactly like removeEachIterable(Iterable), but takes an array instead of a Collection.
      Specified by:
      removeEach in interface EnhancedCollection<T>
      Parameters:
      array - array containing elements to be removed from this list
      Returns:
      true if this list changed as a result of the call
      See Also:
    • removeEach

      public boolean removeEach(Object[] array, int offset, int length)
      Like removeEach(Object[]), but only uses at most length items from array, starting at offset.
      Specified by:
      removeEach in interface EnhancedCollection<T>
      Parameters:
      array - the elements to be removed from this list
      offset - the index of the first item in array to remove
      length - how many items, at most, to get from array and remove from this
      Returns:
      true if this list changed as a result of the call
      See Also:
    • addAll

      public boolean addAll(T[] a)
      Adds each item in the array a to this ObjectList, appending to the end.
      Specified by:
      addAll in interface EnhancedCollection<T>
      Parameters:
      a - a non-null array of T
      Returns:
      true if this is modified by this call, as ArrayList.addAll(Collection) does
    • addAll

      public boolean addAll(int insertionIndex, T[] a)
      Adds each item in the array a to this ObjectList, inserting starting at insertionIndex.
      Parameters:
      insertionIndex - where to insert into this ObjectList
      a - a non-null array of T
      Returns:
      true if this is modified by this call, as ArrayList.addAll(Collection) does
    • addAll

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

      public boolean duplicateRange(int index, int count)
      Inserts the specified number of items at the specified index. The new items will have values equal to the values at those indices before the insertion, and the previous values will be pushed to after the duplicated range.
      Parameters:
      index - the first index to duplicate
      count - how many items to duplicate
    • containsAll

      public boolean containsAll(Object[] array)
      Exactly like AbstractCollection.containsAll(Collection), but takes an array instead of a Collection.
      Specified by:
      containsAll in interface EnhancedCollection<T>
      Parameters:
      array - array to be checked for containment in this collection
      Returns:
      true if this list contains all the elements in the specified array
      See Also:
    • containsAll

      public boolean containsAll(Object[] array, int offset, int length)
      Like containsAll(Object[]), but only uses at most length items from array, starting at offset.
      Specified by:
      containsAll in interface EnhancedCollection<T>
      Parameters:
      array - array to be checked for containment in this collection
      offset - the index of the first item in array to check
      length - how many items, at most, to check from array
      Returns:
      true if this collection contains all the elements in the specified range of array
      See Also:
    • containsAnyIterable

      public boolean containsAnyIterable(Iterable<?> values)
      Returns true if this ObjectList contains any of the specified values.
      Specified by:
      containsAnyIterable in interface EnhancedCollection<T>
      Parameters:
      values - may contain nulls, but must not be null itself
      Returns:
      true if this ObjectList contains any of the items in values, false otherwise
    • containsAny

      public boolean containsAny(Object[] values)
      Returns true if this ObjectList contains any of the specified values.
      Specified by:
      containsAny in interface EnhancedCollection<T>
      Parameters:
      values - may contain nulls, but must not be null itself
      Returns:
      true if this ObjectList contains any of the items in values, false otherwise
    • containsAny

      public boolean containsAny(Object[] values, int offset, int length)
      Returns true if this ObjectList contains any items from the specified range of values.
      Specified by:
      containsAny in interface EnhancedCollection<T>
      Parameters:
      values - may contain nulls, but must not be null itself
      offset - the index to start checking in values
      length - how many items to check from values
      Returns:
      true if this ObjectList contains any of the items in the given range of values, false otherwise
    • addAll

      public boolean addAll(int insertionIndex, T[] a, int offset, int count)
      Adds up to count items, starting from offset, in the array a to this ObjectList, inserting starting at insertionIndex.
      Parameters:
      insertionIndex - where to insert into this ObjectList
      a - a non-null array of T
      offset - the first index in a to use
      count - how many indices in a to use
      Returns:
      true if this is modified by this call, as ArrayList.addAll(Collection) does
    • 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 list, 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 ArrayList.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 list, 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 ArrayList.addAll(Collection) does
    • pop

      public T pop()
      Removes and returns the last item.
    • peek

      public T peek()
      Returns the last item.
    • first

      public T first()
      Returns the first item.
      Specified by:
      first in interface EnhancedCollection<T>
      Returns:
      the first item in this EnhancedCollection, as produced by Collection.iterator()
    • notEmpty

      public boolean notEmpty()
      Returns true if the array has one or more items.
    • ensureCapacity

      public void ensureCapacity(int additionalCapacity)
      Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes. Note that this has different behavior from ArrayList.ensureCapacity(int); ArrayList's version specifies a minimum capacity (which can result in no change if the capacity is currently larger than that minimum), whereas this version specifies additional capacity (which always increases capacity if additionalCapacity is non-negative). The behavior here matches the primitive-backed lists like IntList, as well as libGDX Array classes.
      Overrides:
      ensureCapacity in class ArrayList<T>
      Parameters:
      additionalCapacity - how much room to add to the capacity; this is measured in the number of items this can store
    • shrink

      public void shrink()
    • trimToSize

      public void trimToSize()
      Overrides:
      trimToSize in class ArrayList<T>
    • equalsIdentity

      public boolean equalsIdentity(Object object)
      Uses == for comparison of each item.
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface List<T>
      Overrides:
      equals in class ArrayList<T>
    • hashCode

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

      public String toString()
      Overrides:
      toString in class AbstractCollection<T>
    • appendTo

      public StringBuilder appendTo(StringBuilder builder, String separator)
    • replaceFirst

      public boolean replaceFirst(T find, T replace)
      Replaces the first occurrence of find with replace. Returns true if it performed the replacement, or false if there was nothing to replace. This also returns false if find and replace are the same. This compares T items by Object.equals(Object), unless an item is null.
      Parameters:
      find - the item to search for
      replace - the item to replace find with, if possible
      Returns:
      true if this changed, or false otherwise
    • replaceAll

      public int replaceAll(T find, T replace)
      Replaces every occurrence of find with replace. Returns the number of changed items, which is 0 if nothing was found or in the case that find and replace are the same. This compares T items by Object.equals(Object), unless an item is null.
      Parameters:
      find - the item to search for
      replace - the item to replace find with, if possible
      Returns:
      the number of replacements that occurred; 0 if nothing was found or replaced
    • replaceFirstIdentity

      public boolean replaceFirstIdentity(T find, T replace)
      Replaces the first occurrence of find with replace. Returns true if it performed the replacement, or false if there was nothing to replace. This also returns false if find and replace are the same. This compares T items by identity, not with Object.equals(Object) ! This may be useful to replace occurrences of null by a given replace value.
      Parameters:
      find - the item to search for
      replace - the item to replace find with, if possible
      Returns:
      true if this changed, or false otherwise
    • replaceAllIdentity

      public int replaceAllIdentity(T find, T replace)
      Replaces every occurrence of find with replace. Returns the number of changed items, which is 0 if nothing was found or in the case that find and replace are the same. This compares T items by identity, not with Object.equals(Object) ! This may be useful to replace an occurrence of null by a given replace value.
      Parameters:
      find - the item to search for
      replace - the item to replace find with, if possible
      Returns:
      the number of replacements that occurred; 0 if nothing was found or replaced
    • listIterator

      public ObjectList.ObjectListIterator<T> listIterator(int index)
      Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.
      The returned iterator is reused by this ObjectList, so it is likely unsuitable for nested iteration. Use ObjectListIterator(ObjectList, int) to create a ListIterator if you need nested iteration.
      Specified by:
      listIterator in interface List<T>
      Overrides:
      listIterator in class ArrayList<T>
      Parameters:
      index - the index to start the iterator at
    • listIterator

      public ObjectList.ObjectListIterator<T> listIterator()
      Returns a list iterator over the elements in this list (in proper sequence).
      The returned iterator is reused by this ObjectList, so it is likely unsuitable for nested iteration. Use ObjectListIterator(ObjectList) to create a ListIterator if you need nested iteration.
      Specified by:
      listIterator in interface List<T>
      Overrides:
      listIterator in class ArrayList<T>
      See Also:
    • iterator

      public ObjectList.ObjectListIterator<T> iterator()
      Returns an iterator over the elements in this list in proper sequence.
      The returned iterator is reused by this ObjectList, so it is likely unsuitable for nested iteration. Use ObjectListIterator(ObjectList) to create an Iterator if you need nested iteration.
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface List<T>
      Overrides:
      iterator in class ArrayList<T>
      Returns:
      an iterator over the elements in this list in proper sequence
    • order

      public ObjectList<T> order()
      Gets the ObjectList of T items that this data structure holds, in the order it uses for iteration. This method actually returns this ObjectList directly, since it extends ArrayList.
      Specified by:
      order in interface Ordered<T>
      Returns:
      this ObjectList
    • swap

      public void swap(int first, int second)
      Switches the ordering of positions a and b, without changing any items beyond that.
      Specified by:
      swap in interface Arrangeable
      Specified by:
      swap in interface Ordered<T>
      Parameters:
      first - the first position
      second - the second position
    • shuffle

      public void shuffle(Random rng)
      Pseudo-randomly shuffles the order of this Ordered in-place. You can use any Random class for rng;
      Specified by:
      shuffle in interface Arrangeable
      Specified by:
      shuffle in interface Ordered<T>
      Parameters:
      rng - any Random class
    • random

      public T random(Random random)
      Returns a T item from anywhere in this ObjectList, chosen pseudo-randomly using random. If this ObjectList is empty, returns null.
      Specified by:
      random in interface Ordered<T>
      Parameters:
      random - a Random or a subclass
      Returns:
      a pseudo-randomly selected item from this ObjectLists
    • truncate

      public void truncate(int newSize)
      Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.
    • reverse

      public void reverse()
      Description copied from interface: Ordered
      Reverses the order of this Ordered in-place.
      Specified by:
      reverse in interface Arrangeable
      Specified by:
      reverse in interface Ordered<T>
    • sort

      public void sort()
      Sorts this ObjectList based on the natural order of its elements; T must implement Comparable for this to succeed.
      This uses ObjectComparators.sort(List, Comparator), which is slower than the approach used by the JDK in Arrays.sort(Object[], int, int), but ArrayList doesn't expose its internal array to its subclasses, so we need to use a different technique. You can potentially use ObjectDeque, which also implements List, and its ObjectDeque.sortJDK() method if TimSort is significantly faster for your use-case, such as if you have truly massive lists.
    • sort

      public void sort(int from, int to)
      Sorts a subrange of this ObjectList based on the natural order of its elements; T must implement Comparable for this to succeed.
      This uses ObjectComparators.sort(List, int, int, Comparator), which is slower than the approach used by the JDK in Arrays.sort(Object[], int, int), but ArrayList doesn't expose its internal array to its subclasses, so we need to use a different technique. You can potentially use ObjectDeque, which also implements List, and its ObjectDeque.sortJDK(int, int) method if TimSort is significantly faster for your use-case, such as if you have truly massive lists.
      Parameters:
      from - the index of the first element (inclusive) to be sorted
      to - the index of the last element (exclusive) to be sorted
    • sort

      public void sort(Comparator<? super T> c)
      Sorts this ObjectList using the given Comparator. If the Comparator is null, then this sorts based on the natural order of its elements, and T must implement Comparable.
      This uses ObjectComparators.sort(List, Comparator), which is slower than the approach used by the JDK in Arrays.sort(Object[], int, int, Comparator), but ArrayList doesn't expose its internal array to its subclasses, so we need to use a different technique. You can potentially use ObjectDeque, which also implements List, and its ObjectDeque.sortJDK(Comparator) method if TimSort is significantly faster for your use-case, such as if you have truly massive lists.
      This is implemented explicitly and not annotated with Override because of Android limitations. RoboVM also has limits here; when using RoboVM, List does not have any sort() methods, so Override wouldn't make sense there either (except that Override annotations are ignored on RoboVM). These methods should be safe to call directly, even if they aren't as fast as the TimSort-based version in Java 8 onward in ArrayList's sort() methods, but Collections.sort(List, Comparator) should be used cautiously when the List parameter is an ObjectList. You should make sure to test that sorting, especially sorting Lists, works on every platform you intend to target.
      Specified by:
      sort in interface List<T>
      Specified by:
      sort in interface Ordered<T>
      Overrides:
      sort in class ArrayList<T>
      Parameters:
      c - a Comparator that can compare T items, or null to use the natural order of Comparable T items
    • sort

      public void sort(int from, int to, Comparator<? super T> c)
      Sorts a subrange of this ObjectList using the given Comparator. If the Comparator is null, then this sorts based on the natural order of its elements, and T must implement Comparable.
      This uses ObjectComparators.sort(List, int, int, Comparator), which is slower than the approach used by the JDK in Arrays.sort(Object[], int, int, Comparator), but ArrayList doesn't expose its internal array to its subclasses, so we need to use a different technique. You can potentially use ObjectDeque, which also implements List, and its ObjectDeque.sortJDK(int, int, Comparator) method if TimSort is significantly faster for your use-case, such as if you have truly massive lists.
      This is implemented explicitly and not annotated with Override because of Android limitations. RoboVM also has limits here; when using RoboVM, List does not have any sort() methods, so Override wouldn't make sense there either (except that Override annotations are ignored on RoboVM). These methods should be safe to call directly, even if they aren't as fast as the TimSort-based version in Java 8 onward in ArrayList's sort() methods, but Collections.sort(List, Comparator) should be used cautiously when the List parameter is an ObjectList. You should make sure to test that sorting, especially sorting Lists, works on every platform you intend to target.
      Parameters:
      from - the index of the first element (inclusive) to be sorted
      to - the index of the last element (exclusive) to be sorted
      c - a Comparator that can compare T items, or null to use the natural order of Comparable T items
    • sortJDK

      public void sortJDK()
      Currently calls sort() because this can't access Arrays.sort(Object[], int, int) without the parent ArrayList's items array. You can use ObjectDeque, which has a working ObjectDeque.sortJDK(), or you can just use sort(), which is likely slower but doesn't allocate.
      See Also:
    • sortJDK

      public void sortJDK(int from, int to)
      Currently calls sort(int, int) because this can't access Arrays.sort(Object[], int, int) without the parent ArrayList's items array. You can use ObjectDeque, which has a working ObjectDeque.sortJDK(int, int), or you can just use sort(int, int), which is likely slower but doesn't allocate.
      Parameters:
      from - the index of the first element (inclusive) to be sorted
      to - the index of the last element (exclusive) to be sorted
      See Also:
    • sortJDK

      public void sortJDK(Comparator<? super T> c)
      Currently calls sort(Comparator) because this can't access Arrays.sort(Object[], int, int, Comparator) without the parent ArrayList's items array. You can use ObjectDeque, which has a working ObjectDeque.sortJDK(Comparator), or you can just use sort(Comparator), which is likely slower but doesn't allocate.
      Parameters:
      c - a Comparator that can compare T items, or null to use the natural order of Comparable T items
      See Also:
    • sortJDK

      public void sortJDK(int from, int to, Comparator<? super T> c)
      Currently calls sort(int, int, Comparator) because this can't access Arrays.sort(Object[], int, int, Comparator) without the parent ArrayList's items array. You can use ObjectDeque, which has a working ObjectDeque.sortJDK(int, int, Comparator), or you can just use sort(int, int, Comparator), which is likely slower but doesn't allocate.
      Parameters:
      from - the index of the first element (inclusive) to be sorted
      to - the index of the last element (exclusive) to be sorted
      c - a Comparator that can compare T items, or null to use the natural order of Comparable T items
      See Also:
    • with

      public static <T> ObjectList<T> with()
      Constructs an empty list 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 list containing nothing
    • with

      public static <T> ObjectList<T> with(T item)
      Creates a new ObjectList 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 ObjectList that holds the given item
    • with

      public static <T> ObjectList<T> with(T item0, T item1)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      public static <T> ObjectList<T> with(T item0, T item1, T item2)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      public static <T> ObjectList<T> with(T item0, T item1, T item2, T item3)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      public static <T> ObjectList<T> with(T item0, T item1, T item2, T item3, T item4)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      public static <T> ObjectList<T> with(T item0, T item1, T item2, T item3, T item4, T item5)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      public static <T> ObjectList<T> with(T item0, T item1, T item2, T item3, T item4, T item5, T item6)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      public static <T> ObjectList<T> with(T item0, T item1, T item2, T item3, T item4, T item5, T item6, T item7)
      Creates a new ObjectList 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 ObjectList that holds the given items
    • with

      @SafeVarargs public static <T> ObjectList<T> with(T... varargs)
      Creates a new ObjectList that will hold the items in the given array or varargs. 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 items, typically inferred by all the items being the same type
      Parameters:
      varargs - either 0 or more T items, or an array of T
      Returns:
      a new ObjectList that holds the given T items
    • parse

      public static <T> ObjectList<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> ObjectList<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> ObjectList<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