Class ObjectDeque<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<T>
com.github.tommyettinger.ds.ObjectDeque<T>
All Implemented Interfaces:
Arrangeable, Arrangeable.ArrangeableList<T>, EnhancedCollection<T>, Lisque<T>, Iterable<T>, Collection<T>, Deque<T>, List<T>, Queue<T>, RandomAccess

public class ObjectDeque<T> extends AbstractList<T> implements Lisque<T>, RandomAccess, Arrangeable, EnhancedCollection<T>, Arrangeable.ArrangeableList<T>
A resizable, insertion-ordered double-ended queue of objects with efficient add and remove at the beginning and end. This implements both the List and Deque interfaces, and supports RandomAccess. Values in the backing array may wrap back to the beginning, making add and remove at the beginning and end O(1) (unless the backing array needs to resize when adding). Deque functionality is provided via removeLast() and addFirst(Object).
Unlike most Deque implementations in the JDK, you can get and set items anywhere in the deque in constant time with get(int) and set(int, Object). Relative to an ObjectList, get(int) has slightly higher overhead, but it still runs in constant time. Unlike ArrayDeque in the JDK, this implements equals(Object) and hashCode(), as well as equalsIdentity(Object). This can provide full-blown ListIterators for iteration from an index or in reverse order.
Unlike ArrayDeque or ArrayList, most methods that take an index here try to be "forgiving;" that is, they treat negative indices as index 0, and too-large indices as the last index, rather than throwing an Exception, except in some cases where the ObjectDeque is empty and an item from it is required. An exception is in set(int, Object), which allows prepending by setting a negative index, or appending by setting a too-large index. This isn't a standard JDK behavior, and it doesn't always act how Deque or List is documented.
Some new methods are present here, or have been made public when they weren't before. removeRange(int, int), for instance, is now public, as is resize(int). New APIs include Deque-like methods that affect the middle of the deque, such as peekAt(int) and pollAt(int). There are more bulk methods that work at the head or tail region of the deque, such as addAllFirst(Collection) and truncateFirst(int). There are the methods from Arrangeable, and relevant ones from Ordered (this isn't Ordered because it doesn't provide its order as an ObjectList, but can do similar things).
In general, this is an improvement over ArrayDeque in every type of functionality, and is mostly equivalent to ObjectList as long as the performance of get(int) is adequate. Because it is array-backed, it should usually be much faster than LinkedList, as well; only periodic resizing and modifications in the middle of the List using an iterator should be typically faster for LinkedList.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An Iterator and ListIterator over the elements of an ObjectDeque, while also an Iterable.

    Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable

    Arrangeable.ArrangeableList<T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when calling peek() on an empty deque.
     
     
    protected int
    Index of first element.
    protected T[]
    Contains the values in the deque.
     
     
    int
    Number of elements in the deque.
    protected int
    Index of last element.

    Fields inherited from class java.util.AbstractList

    modCount
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new ObjectDeque which can hold 16 values without needing to resize the backing array.
    ObjectDeque(int initialSize)
    Creates a new ObjectDeque which can hold the specified number of values without needing to resize the backing array.
    ObjectDeque(ObjectDeque<? extends T> deque)
    Copies the given ObjectDeque exactly into this one.
    ObjectDeque(Collection<? extends T> coll)
    Creates a new ObjectDeque using all the contents of the given Collection.
    ObjectDeque(Iterator<? extends T> iter)
    Creates a new instance containing the items in the specified iterator.
    Creates a new ObjectDeque using all the contents of the given array.
    ObjectDeque(T[] a, int offset, int count)
    Creates a new ObjectDeque using count items from a, starting at offset.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int index, T item)
    Inserts the specified element into this deque at the specified index.
    boolean
    add(T t)
    Inserts the specified element into the deque represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
    boolean
    add(T item0, T item1)
    Adds all parameters using Collection.add(Object) for each one.
    boolean
    add(T item0, T item1, T item2)
    Adds all parameters using Collection.add(Object) for each one.
    boolean
    add(T item0, T item1, T item2, T item3)
    Adds all parameters using Collection.add(Object) for each one.
    boolean
    addAll(int index, Collection<? extends T> c)
     
    boolean
    addAll(int index, T[] array)
    Like addAll(int, Collection), but takes an array instead of a Collection and inserts it so the first item will be at the given index.
    boolean
    addAll(int index, T[] array, int offset, int length)
    Like addAll(int, Collection), but takes an array instead of a Collection, gets items starting at offset from that array, using length items, and inserts them so the item at the given offset will be at the given index.
    boolean
    addAll(Collection<? extends T> c)
    Adds all the elements in the specified collection at the end of this deque, as if by calling addLast(T) on each one, in the order that they are returned by the collection's iterator.
    boolean
    addAll(T[] array)
    Exactly like addAll(Collection), but takes an array instead of a Collection.
    boolean
    addAll(T[] array, int offset, int length)
    Like addAll(Object[]), but only uses at most length items from array, starting at offset.
    boolean
    addAllFirst(Collection<? extends T> c)
    Adds every item in c to this in order at the start.
    boolean
    addAllFirst(T[] array)
    Exactly like addAllFirst(Collection), but takes an array instead of a Collection.
    boolean
    addAllFirst(T[] array, int offset, int length)
    Like addAllFirst(Object[]), but only uses at most length items from array, starting at offset.
    boolean
    addAllLast(Collection<? extends T> c)
    An alias for addAll(Collection), this adds every item in c to this in order at the end.
    boolean
    addAllLast(T[] array)
    An alias for addAll(Object[]).
    boolean
    addAllLast(T[] array, int offset, int length)
    void
    addFirst(T value)
    Prepends value to the head (enqueue to head).
    void
    addFirst(T value1, T value2)
     
    void
    addFirst(T value1, T value2, T value3)
     
    void
    addFirst(T value1, T value2, T value3, T value4)
     
    void
    addLast(T value)
    Appends value to the tail (enqueue to tail).
    void
    addLast(T value1, T value2)
     
    void
    addLast(T value1, T value2, T value3)
     
    void
    addLast(T value1, T value2, T value3, T value4)
     
    void
    Removes all values from this deque.
    boolean
    Returns true if this deque contains the specified element.
    boolean
    Exactly like containsAll(Collection), but takes an array instead of a Collection.
    boolean
    containsAll(Object[] array, int offset, int length)
    Like containsAll(Object[]), but only uses at most length items from array, starting at offset.
    boolean
    Returns true if this collection contains all the elements in the specified collection.
    boolean
    containsAny(Object[] values)
    Returns true if this ObjectDeque contains any of the specified values.
    boolean
    containsAny(Object[] values, int offset, int length)
    Returns true if this ObjectDeque contains any items from the specified range of values.
    boolean
    Returns true if this ObjectDeque contains any of the specified values.
    Returns an iterator over the elements in this deque in reverse sequential order.
    descendingIterator(int index)
    Returns an iterator over the elements in this deque in reverse sequential order.
    boolean
    duplicateRange(int index, int count)
    Inserts the specified number of items at the specified index.
    Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque).
    void
    ensureCapacity(int additional)
    Increases the size of the backing array to accommodate the specified number of additional items.
    protected int
    ensureGap(int index, int gapSize)
    Make sure there is a "gap" of exactly gapSize values starting at index.
    boolean
    Using Object.equals(Object) between each item in order, compares for equality with other types implementing List or Queue, including other Deque types.
    boolean
    Using == between each item in order, compares for equality with other types implementing List or Queue, including other Deque types.
    Returns the first (head) item in the deque (without removing it).
    get(int index)
    Returns the element at the specified position in this deque.
    Gets the default value, which is the value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when calling peek() on an empty deque.
    Retrieves, but does not remove, the first element of this deque.
    Retrieves, but does not remove, the last element of this deque.
    getRandom(Random random)
    Gets a randomly selected item from this ObjectDeque.
    int
     
    int
    indexOf(Object value)
    Returns the index of the first occurrence of value in the deque, or -1 if no such value exists.
    int
    indexOf(Object value, boolean identity)
    Returns the index of first occurrence of value in the deque, or -1 if no such value exists.
    int
    indexOf(Object value, int fromIndex)
    Returns the index of the first occurrence of value in the deque, or -1 if no such value exists.
    int
    indexOf(Object value, int fromIndex, boolean identity)
    Returns the index of first occurrence of value in the deque, starting from fromIndex, or -1 if no such value exists.
    boolean
    insert(int index, T item)
    This is an alias for add(int, Object) that returns true to indicate it does modify this ObjectDeque.
    boolean
    insertAll(int index, Collection<? extends T> c)
    An alias for addAll(int, Collection); inserts all elements in the specified collection into this list at the specified position.
    boolean
    insertAll(int index, T[] array)
    boolean
    insertAll(int index, T[] array, int offset, int length)
    boolean
    Returns true if the deque is empty.
    Returns an iterator for the items in the deque.
    Returns the last (tail) item in the deque (without removing it).
    int
    Returns the index of the last occurrence of value in the deque, or -1 if no such value exists.
    int
    lastIndexOf(Object value, boolean identity)
    Returns the index of the last occurrence of value in the deque, or -1 if no such value exists.
    int
    lastIndexOf(Object value, int fromIndex)
    Returns the index of last occurrence of value in the deque, starting from fromIndex and going backwards, or -1 if no such value exists.
    int
    lastIndexOf(Object value, int fromIndex, boolean identity)
    Returns the index of last occurrence of value in the deque, starting from fromIndex and going backwards, or -1 if no such value exists.
     
    listIterator(int index)
    Gets an iterator over this deque that starts at the given index.
    boolean
    Returns true if the deque has one or more items.
    boolean
    offer(T t)
    Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available.
    boolean
    Inserts the specified element at the front of this deque unless it would violate capacity restrictions.
    boolean
    Inserts the specified element at the end of this deque unless it would violate capacity restrictions.
    static <T> ObjectDeque<T>
    parse(String str, String delimiter, PartialParser<T> parser)
    Calls parse(String, String, PartialParser, boolean) with brackets set to false.
    static <T> ObjectDeque<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).
    static <T> ObjectDeque<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.
    Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns defaultValue if this deque is empty.
    peekAt(int index)
    Returns the element at the specified position in this deque.
    Retrieves, but does not remove, the first element of this deque, or returns defaultValue if this deque is empty.
    Retrieves, but does not remove, the last element of this deque, or returns defaultValue if this deque is empty.
    Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns defaultValue if this deque is empty.
    poll(int index)
    Removes the element at the specified position in this deque.
    pollAt(int index)
    Removes the element at the specified position in this deque.
    Retrieves and removes the first element of this deque, or returns defaultValue if this deque is empty.
    Retrieves and removes the last element of this deque, or returns defaultValue if this deque is empty.
    pop()
    Pops an element from the stack represented by this deque.
    void
    push(T t)
    Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.
    random(Random random)
    Returns a T item from anywhere in this ObjectDeque, chosen pseudo-randomly using random.
    Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).
    remove(int index)
    Removes the element at the specified position in this deque.
    boolean
    Removes the first occurrence of the specified element from this deque.
    boolean
    removeAll(Object[] other)
    Exactly like removeAll(Collection), but takes an array instead of a Collection.
    boolean
    removeAll(Object[] array, int offset, int length)
    Like removeAll(Object[]), but only uses at most length items from array, starting at offset.
    boolean
    Removes all of this collection's elements that are also contained in the specified collection (optional operation).
    removeAt(int index)
    Removes the element at the specified position in this deque.
    boolean
    removeEach(Object[] array)
    Exactly like removeEachIterable(Iterable), but takes an array instead of a Collection.
    boolean
    removeEach(Object[] array, int offset, int length)
    Like removeEach(Object[]), but only uses at most length items from array, starting at offset.
    boolean
    Removes from this collection element-wise occurrences of elements contained in the specified other collection.
    Remove the first item from the deque.
    boolean
    Removes the first occurrence of the specified element from this deque.
    Remove the last item from the deque.
    boolean
    Removes the last occurrence of the specified element from this deque.
    boolean
    removeLastValue(Object value, boolean identity)
    Removes the last instance of the specified value in the deque.
    void
    removeRange(int fromIndex, int toIndex)
    Removes from this list all the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
    boolean
    removeValue(Object value, boolean identity)
    Removes the first instance of the specified value in the deque.
    int
    replaceAll(T find, T replace)
    Replaces every occurrence of find with replace.
    int
    replaceAllIdentity(T find, T replace)
    Replaces every occurrence of find with replace.
    boolean
    replaceFirst(T find, T replace)
    Replaces the first occurrence of find with replace.
    boolean
    replaceFirstIdentity(T find, T replace)
    Replaces the first occurrence of find with replace.
    void
    resize(int newSize)
    Resizes the backing array.
    boolean
    retainAll(Object[] array)
    Exactly like AbstractCollection.retainAll(Collection), but takes an array instead of a Collection.
    boolean
    retainAll(Object[] array, int offset, int length)
    Like retainAll(Object[]), but only uses at most length items from array, starting at offset.
    void
    Reverses this ObjectDeque in-place.
    Gets a new ObjectDeque (which is both List and Deque) that has had its order reversed.
    selectRanked(Comparator<T> comparator, int kthLowest)
    Selects the kth-lowest element from this ObjectDeque according to Comparator ranking.
    int
    selectRankedIndex(Comparator<T> comparator, int kthLowest)
    Gets the index of the kth-lowest element from this ObjectDeque according to Comparator ranking.
    set(int index, T item)
    Replaces the element at the specified position in this list with the specified element.
    void
    setDefaultValue(T defaultValue)
    Sets the default value, which is the value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when calling peek() on an empty deque.
    void
    Reduces the size of the backing array to the size of the actual items.
    void
    Pseudo-randomly shuffles the order of this Arrangeable in-place.
    int
    Returns the number of elements in this deque.
    void
    Attempts to sort this deque in-place using its natural ordering, which requires T to implement Comparable of T.
    void
    sort(int from, int to)
    Uses ObjectComparators.sort(Object[], int, int, Comparator) to sort a (clamped) subrange of this deque.
    void
    sort(int from, int to, Comparator<? super T> comparator)
    void
    sort(Comparator<? super T> comparator)
    void
    Sorts this deque using Arrays.sort(Object[], int, int).
    void
    sortJDK(int from, int to)
    Uses Arrays.sort(Object[], int, int) to sort a (clamped) subrange of this deque.
    void
    sortJDK(int from, int to, Comparator<? super T> comparator)
    Uses Arrays.sort(Object[], int, int, Comparator) to sort a (clamped) subrange of this deque.
    void
    sortJDK(Comparator<? super T> comparator)
    subList(int fromIndex, int toIndex)
     
    void
    swap(int first, int second)
    Switches the ordering of positions first and second, without changing any items beyond that.
    Returns an array containing all the elements in this collection.
    <E> E[]
    toArray(E[] a)
    Returns an array containing all the elements in this collection; the runtime type of the returned array is that of the specified array.
    Delegates to EnhancedCollection.toString(String, boolean) with a delimiter of ", " and square brackets enabled.
    void
    Trims the capacity of this ObjectDeque instance to be the deque's current size.
    void
    truncate(int newSize)
    Reduces the size of the deque to the specified size by bulk-removing items from the tail end.
    void
    truncateFirst(int newSize)
    Reduces the size of the deque to the specified size by bulk-removing from the head.
    void
    truncateLast(int newSize)
    Alias for truncate(int).
    static <T> ObjectDeque<T>
    Constructs an empty deque given the type as a generic type argument.
    static <T> ObjectDeque<T>
    with(T item)
    Creates a new ObjectDeque that holds only the given item, but can be resized.
    static <T> ObjectDeque<T>
    with(T... varargs)
    Creates a new ObjectDeque that will hold the items in the given array or varargs.
    static <T> ObjectDeque<T>
    with(T item0, T item1)
    Creates a new ObjectDeque that holds only the given items, but can be resized.
    static <T> ObjectDeque<T>
    with(T item0, T item1, T item2)
    Creates a new ObjectDeque that holds only the given items, but can be resized.
    static <T> ObjectDeque<T>
    with(T item0, T item1, T item2, T item3)
    Creates a new ObjectDeque that holds only the given items, but can be resized.
    static <T> ObjectDeque<T>
    with(T item0, T item1, T item2, T item3, T item4)
    Creates a new ObjectDeque that holds only the given items, but can be resized.
    static <T> ObjectDeque<T>
    with(T item0, T item1, T item2, T item3, T item4, T item5)
    Creates a new ObjectDeque that holds only the given items, but can be resized.
    static <T> ObjectDeque<T>
    with(T item0, T item1, T item2, T item3, T item4, T item5, T item6)
    Creates a new ObjectDeque that holds only the given items, but can be resized.
    static <T> ObjectDeque<T>
    with(T item0, T item1, T item2, T item3, T item4, T item5, T item6, T item7)
    Creates a new ObjectDeque that holds only the given items, but can be resized.

    Methods inherited from class java.util.AbstractCollection

    retainAll

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.github.tommyettinger.ds.Arrangeable

    rearrange, shuffle

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface com.github.tommyettinger.ds.Lisque

    peekRandom, retainAll

    Methods inherited from interface java.util.List

    replaceAll, spliterator
  • Field Details

    • defaultValue

      public T defaultValue
      The value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when calling peek() on an empty deque.
    • items

      protected T[] items
      Contains the values in the deque. Head and tail indices go in a circle around this array, wrapping at the end.
    • tail

      protected int tail
      Index of last element. Logically bigger than head. Unless empty, it points to a valid element inside the deque. This may be the same as head, and is if there is one element in the deque (or none), that will be the case.
    • size

      public int size
      Number of elements in the deque.
    • iterator1

      protected transient ObjectDeque.ObjectDequeIterator<T> iterator1
    • iterator2

      protected transient ObjectDeque.ObjectDequeIterator<T> iterator2
    • descendingIterator1

      protected transient ObjectDeque.ObjectDequeIterator<T> descendingIterator1
    • descendingIterator2

      protected transient ObjectDeque.ObjectDequeIterator<T> descendingIterator2
  • Constructor Details

    • ObjectDeque

      public ObjectDeque()
      Creates a new ObjectDeque which can hold 16 values without needing to resize the backing array.
    • ObjectDeque

      public ObjectDeque(int initialSize)
      Creates a new ObjectDeque which can hold the specified number of values without needing to resize the backing array.
      Parameters:
      initialSize - how large the backing array should be, without any padding
    • ObjectDeque

      public ObjectDeque(Collection<? extends T> coll)
      Creates a new ObjectDeque using all the contents of the given Collection.
      Parameters:
      coll - a Collection of T that will be copied into this and used in full
      Throws:
      NullPointerException - if coll is null
    • ObjectDeque

      public ObjectDeque(Iterator<? extends T> iter)
      Creates a new instance containing the items in the specified iterator.
      Parameters:
      iter - an iterator that will have its remaining contents added to this
      Throws:
      NullPointerException - if iter is null
    • ObjectDeque

      public ObjectDeque(ObjectDeque<? extends T> deque)
      Copies the given ObjectDeque exactly into this one. Individual values will be shallow-copied.
      Parameters:
      deque - another ObjectDeque to copy
      Throws:
      NullPointerException - if deque is null
    • ObjectDeque

      public ObjectDeque(T[] a)
      Creates a new ObjectDeque using all the contents of the given array.
      Parameters:
      a - an array of T that will be copied into this and used in full
      Throws:
      NullPointerException - if a is null
    • ObjectDeque

      public ObjectDeque(T[] a, int offset, int count)
      Creates a new ObjectDeque using count items from a, starting at offset. If count is 0 or less, this will create an empty ObjectDeque with capacity 1.
      Parameters:
      a - an array of T
      offset - where in a to start using items
      count - how many items to use from a
      Throws:
      NullPointerException - if a is null
  • Method Details

    • getDefaultValue

      public T getDefaultValue()
      Gets the default value, which is the value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when calling peek() on an empty deque. Unless changed, the default value is usually null.
      Returns:
      the current default value
    • setDefaultValue

      public void setDefaultValue(T defaultValue)
      Sets the default value, which is the value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when calling peek() on an empty deque. Unless changed, the default value is usually null.
      Parameters:
      defaultValue - any T object this can return instead of throwing an Exception, or null
    • addLast

      public void addLast(T value)
      Appends value to the tail (enqueue to tail). Unless backing array needs resizing, operates in O(1) time.
      Specified by:
      addLast in interface Deque<T>
      Specified by:
      addLast in interface Lisque<T>
      Parameters:
      value - can be null
    • addLast

      public void addLast(T value1, T value2)
    • addLast

      public void addLast(T value1, T value2, T value3)
    • addLast

      public void addLast(T value1, T value2, T value3, T value4)
    • addFirst

      public void addFirst(T value)
      Prepends value to the head (enqueue to head). Unless backing array needs resizing, operates in O(1) time.
      Specified by:
      addFirst in interface Deque<T>
      Specified by:
      addFirst in interface Lisque<T>
      Parameters:
      value - can be null
      See Also:
    • addFirst

      public void addFirst(T value1, T value2)
    • addFirst

      public void addFirst(T value1, T value2, T value3)
    • addFirst

      public void addFirst(T value1, T value2, T value3, T value4)
    • trimToSize

      public void trimToSize()
      Trims the capacity of this ObjectDeque instance to be the deque's current size. An application can use this operation to minimize the storage of an ObjectDeque instance.
    • ensureCapacity

      public void ensureCapacity(int additional)
      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.
    • shrink

      public void shrink()
      Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added. This is an alias for trimToSize().
    • resize

      public void resize(int newSize)
      Resizes the backing array. newSize should be greater than the current size; otherwise, newSize will be set to size and the resize to the same size will (for most purposes) be wasted effort. If this is not empty, this will rearrange the items internally to be linear and have the head at index 0, with the tail at size - 1. This always allocates a new internal backing array.
    • ensureGap

      protected int ensureGap(int index, int gapSize)
      Make sure there is a "gap" of exactly gapSize values starting at index. This can resize the backing array to achieve this goal. If possible, this will keep the same backing array and modify it in-place. The "gap" is not assigned null, and may contain old/duplicate references; calling code must overwrite the entire gap with additional values to ensure GC correctness.
      Parameters:
      index - the 0-based index in the iteration order where the gap will be present
      gapSize - the number of items that will need filling in the gap, and can be filled without issues.
      Returns:
      the position in the array where the gap will begin, which is unrelated to the index
      "Implementation Note"
      This is considered an incomplete modification for the purpose of AbstractList.modCount, so it does not change modCount; the code that fills in the gap should change modCount instead.
    • 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
    • removeFirst

      public T removeFirst()
      Remove the first item from the deque. (dequeue from head) Always O(1).
      Specified by:
      removeFirst in interface Deque<T>
      Specified by:
      removeFirst in interface Lisque<T>
      Returns:
      removed object
      Throws:
      NoSuchElementException - when the deque is empty
    • removeLast

      public T removeLast()
      Remove the last item from the deque. (dequeue from tail) Always O(1).
      Specified by:
      removeLast in interface Deque<T>
      Specified by:
      removeLast in interface Lisque<T>
      Returns:
      removed object
      Throws:
      NoSuchElementException - when the deque is empty
      See Also:
    • reversed

      public ObjectDeque<T> reversed()
      Gets a new ObjectDeque (which is both List and Deque) that has had its order reversed. Doesn't create a view; this does actually copy the ObjectDeque. Consider using descendingIterator() to get a reverse-order Iterator over this collection. This runs in O(n) time, and iterates over this deque once (in descending order) to add all items to a new ObjectDeque using EnhancedCollection.addAll(Iterator).
      Specified by:
      reversed in interface Lisque<T>
      Returns:
      a new ObjectDeque that copies this in reverse order
    • offerFirst

      public boolean offerFirst(T t)
      Inserts the specified element at the front of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addFirst(T) method, which can fail to insert an element only by throwing an exception.
      Specified by:
      offerFirst in interface Deque<T>
      Specified by:
      offerFirst in interface Lisque<T>
      Parameters:
      t - the element to add
      Returns:
      true if the element was added to this deque, else false
      Throws:
      ClassCastException - if the class of the specified element prevents it from being added to this deque
      NullPointerException - if the specified element is null and this deque does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this deque
    • offerLast

      public boolean offerLast(T t)
      Inserts the specified element at the end of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addLast(T) method, which can fail to insert an element only by throwing an exception.
      Specified by:
      offerLast in interface Deque<T>
      Specified by:
      offerLast in interface Lisque<T>
      Parameters:
      t - the element to add
      Returns:
      true if the element was added to this deque, else false
      Throws:
      ClassCastException - if the class of the specified element prevents it from being added to this deque
      NullPointerException - if the specified element is null and this deque does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this deque
    • pollFirst

      public T pollFirst()
      Retrieves and removes the first element of this deque, or returns defaultValue if this deque is empty. The default value is usually null unless it has been changed with setDefaultValue(Object).
      Specified by:
      pollFirst in interface Deque<T>
      Specified by:
      pollFirst in interface Lisque<T>
      Returns:
      the head of this deque, or defaultValue if this deque is empty
      See Also:
    • pollLast

      public T pollLast()
      Retrieves and removes the last element of this deque, or returns defaultValue if this deque is empty. The default value is usually null unless it has been changed with setDefaultValue(Object).
      Specified by:
      pollLast in interface Deque<T>
      Specified by:
      pollLast in interface Lisque<T>
      Returns:
      the tail of this deque, or defaultValue if this deque is empty
      See Also:
    • getFirst

      public T getFirst()
      Retrieves, but does not remove, the first element of this deque.

      This method differs from peekFirst only in that it throws an exception if this deque is empty.

      Specified by:
      getFirst in interface Deque<T>
      Specified by:
      getFirst in interface Lisque<T>
      Returns:
      the head of this deque
      Throws:
      NoSuchElementException - if this deque is empty
    • getLast

      public T getLast()
      Retrieves, but does not remove, the last element of this deque. This method differs from peekLast only in that it throws an exception if this deque is empty.
      Specified by:
      getLast in interface Deque<T>
      Specified by:
      getLast in interface Lisque<T>
      Returns:
      the tail of this deque
      Throws:
      NoSuchElementException - if this deque is empty
    • peekFirst

      public T peekFirst()
      Retrieves, but does not remove, the first element of this deque, or returns defaultValue if this deque is empty.
      Specified by:
      peekFirst in interface Deque<T>
      Specified by:
      peekFirst in interface Lisque<T>
      Returns:
      the head of this deque, or defaultValue if this deque is empty
    • peekLast

      public T peekLast()
      Retrieves, but does not remove, the last element of this deque, or returns defaultValue if this deque is empty.
      Specified by:
      peekLast in interface Deque<T>
      Specified by:
      peekLast in interface Lisque<T>
      Returns:
      the tail of this deque, or defaultValue if this deque is empty
    • removeFirstOccurrence

      public boolean removeFirstOccurrence(Object o)
      Removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the first element e such that Objects.equals(o, e) (if such an element exists). Returns true if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).
      Specified by:
      removeFirstOccurrence in interface Deque<T>
      Specified by:
      removeFirstOccurrence in interface Lisque<T>
      Parameters:
      o - element to be removed from this deque, if present
      Returns:
      true if an element was removed as a result of this call
      Throws:
      ClassCastException - if the class of the specified element is incompatible with this deque (optional)
      NullPointerException - if the specified element is null and this deque does not permit null elements (optional)
    • removeLastOccurrence

      public boolean removeLastOccurrence(Object o)
      Removes the last occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the last element e such that Objects.equals(o, e) (if such an element exists). Returns true if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).
      Specified by:
      removeLastOccurrence in interface Deque<T>
      Specified by:
      removeLastOccurrence in interface Lisque<T>
      Parameters:
      o - element to be removed from this deque, if present
      Returns:
      true if an element was removed as a result of this call
      Throws:
      ClassCastException - if the class of the specified element is incompatible with this deque (optional)
      NullPointerException - if the specified element is null and this deque does not permit null elements (optional)
    • add

      public boolean add(T t)
      Inserts the specified element into the deque represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. When using a capacity-restricted deque, it is generally preferable to use offer.

      This method is equivalent to addLast(T).

      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Deque<T>
      Specified by:
      add in interface Lisque<T>
      Specified by:
      add in interface List<T>
      Specified by:
      add in interface Queue<T>
      Overrides:
      add in class AbstractList<T>
      Parameters:
      t - the element to add
      Returns:
      true (as specified by Collection.add(E))
      Throws:
      IllegalStateException - if the element cannot be added at this time due to capacity restrictions
      ClassCastException - if the class of the specified element prevents it from being added to this deque
      NullPointerException - if the specified element is null and this deque does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this deque
    • add

      public boolean add(T item0, T item1)
      Description copied from interface: EnhancedCollection
      Adds all parameters using Collection.add(Object) for each one. Returns true if the set was modified.
      Specified by:
      add in interface EnhancedCollection<T>
      Parameters:
      item0 - a T item
      item1 - a T item
      Returns:
      true if this modified the set
    • add

      public boolean add(T item0, T item1, T item2)
      Description copied from interface: EnhancedCollection
      Adds all parameters using Collection.add(Object) for each one. Returns true if the set was modified.
      Specified by:
      add in interface EnhancedCollection<T>
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      Returns:
      true if this modified the set
    • add

      public boolean add(T item0, T item1, T item2, T item3)
      Description copied from interface: EnhancedCollection
      Adds all parameters using Collection.add(Object) for each one. Returns true if the set was modified.
      Specified by:
      add in interface EnhancedCollection<T>
      Parameters:
      item0 - a T item
      item1 - a T item
      item2 - a T item
      item3 - a T item
      Returns:
      true if this modified the set
    • add

      public void add(int index, T item)
      Inserts the specified element into this deque at the specified index. Unlike offerFirst(Object) and offerLast(Object), this does not run in expected constant time unless the index is less than or equal to 0 (where it acts like offerFirst()) or greater than or equal to size() (where it acts like offerLast()).
      Specified by:
      add in interface Lisque<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractList<T>
      Parameters:
      index - the index in the deque's insertion order to insert the item
      item - a T item to insert; may be null
    • insert

      public boolean insert(int index, T item)
      This is an alias for add(int, Object) that returns true to indicate it does modify this ObjectDeque.
      Specified by:
      insert in interface Lisque<T>
      Parameters:
      index - index at which the specified element is to be inserted
      item - element to be inserted
      Returns:
      true if this was modified, which should always happen
    • offer

      public boolean offer(T t)
      Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available. When using a capacity-restricted deque, this method is generally preferable to the add(T) method, which can fail to insert an element only by throwing an exception.

      This method is equivalent to offerLast(T).

      Specified by:
      offer in interface Deque<T>
      Specified by:
      offer in interface Lisque<T>
      Specified by:
      offer in interface Queue<T>
      Parameters:
      t - the element to add
      Returns:
      true if the element was added to this deque, else false
      Throws:
      ClassCastException - if the class of the specified element prevents it from being added to this deque
      NullPointerException - if the specified element is null and this deque does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this deque
    • remove

      public T remove()
      Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque). This method differs from poll() only in that it throws an exception if this deque is empty.

      This method is equivalent to removeFirst().

      Specified by:
      remove in interface Deque<T>
      Specified by:
      remove in interface Lisque<T>
      Specified by:
      remove in interface Queue<T>
      Returns:
      the head of the queue represented by this deque
      Throws:
      NoSuchElementException - if this deque is empty
    • poll

      public T poll()
      Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns defaultValue if this deque is empty.

      This method is equivalent to pollFirst().

      Specified by:
      poll in interface Deque<T>
      Specified by:
      poll in interface Lisque<T>
      Specified by:
      poll in interface Queue<T>
      Returns:
      the first element of this deque, or defaultValue if this deque is empty
    • element

      public T element()
      Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque). This method differs from peek only in that it throws an exception if this deque is empty.

      This method is equivalent to getFirst().

      Specified by:
      element in interface Deque<T>
      Specified by:
      element in interface Lisque<T>
      Specified by:
      element in interface Queue<T>
      Returns:
      the head of the queue represented by this deque
      Throws:
      NoSuchElementException - if this deque is empty
    • peek

      public T peek()
      Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns defaultValue if this deque is empty.

      This method is equivalent to peekFirst().

      Specified by:
      peek in interface Deque<T>
      Specified by:
      peek in interface Lisque<T>
      Specified by:
      peek in interface Queue<T>
      Returns:
      the head of the queue represented by this deque, or defaultValue if this deque is empty
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Adds all the elements in the specified collection at the end of this deque, as if by calling addLast(T) on each one, in the order that they are returned by the collection's iterator.

      When using a capacity-restricted deque, it is generally preferable to call offer separately on each element.

      An exception encountered while trying to add an element may result in only some of the elements having been successfully added when the associated exception is thrown.

      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Deque<T>
      Specified by:
      addAll in interface List<T>
      Overrides:
      addAll in class AbstractCollection<T>
      Parameters:
      c - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
      Throws:
      IllegalStateException - if not all the elements can be added at this time due to insertion restrictions
      ClassCastException - if the class of an element of the specified collection prevents it from being added to this deque
      NullPointerException - if the specified collection contains a null element and this deque does not permit null elements, or if the specified collection is null
      IllegalArgumentException - if some property of an element of the specified collection prevents it from being added to this deque
    • addAllLast

      public boolean addAllLast(Collection<? extends T> c)
      An alias for addAll(Collection), this adds every item in c to this in order at the end.
      Specified by:
      addAllLast in interface Lisque<T>
      Parameters:
      c - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
    • addAllFirst

      public boolean addAllFirst(Collection<? extends T> c)
      Adds every item in c to this in order at the start. The iteration order of c will be preserved for the added items.
      Specified by:
      addAllFirst in interface Lisque<T>
      Parameters:
      c - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
    • insertAll

      public boolean insertAll(int index, Collection<? extends T> c)
      An alias for addAll(int, Collection); inserts all elements in the specified collection into this list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
      Specified by:
      insertAll in interface Lisque<T>
      Parameters:
      index - index at which to insert the first element from the specified collection
      c - collection containing elements to be added to this list
      Returns:
      true if this list changed as a result of the call
    • addAll

      public boolean addAll(int index, Collection<? extends T> c)
      Specified by:
      addAll in interface List<T>
      Overrides:
      addAll in class AbstractList<T>
    • addAll

      public boolean addAll(T[] array)
      Exactly like addAll(Collection), but takes an array instead of a Collection.
      Specified by:
      addAll in interface EnhancedCollection<T>
      Specified by:
      addAll in interface Lisque<T>
      Parameters:
      array - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • addAll

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

      public boolean addAllLast(T[] array)
      An alias for addAll(Object[]).
      Specified by:
      addAllLast in interface Lisque<T>
      Parameters:
      array - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • addAllLast

      public boolean addAllLast(T[] array, int offset, int length)
      Specified by:
      addAllLast in interface Lisque<T>
      Parameters:
      array - the elements to be inserted into this deque
      offset - the index of the first item in array to add
      length - how many items, at most, to add from array into this
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • addAllFirst

      public boolean addAllFirst(T[] array)
      Exactly like addAllFirst(Collection), but takes an array instead of a Collection.
      Specified by:
      addAllFirst in interface Lisque<T>
      Parameters:
      array - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • addAllFirst

      public boolean addAllFirst(T[] array, int offset, int length)
      Like addAllFirst(Object[]), but only uses at most length items from array, starting at offset. The order of array will be preserved, starting at the head of the deque.
      Specified by:
      addAllFirst in interface Lisque<T>
      Parameters:
      array - the elements to be inserted into this deque
      offset - the index of the first item in array to add
      length - how many items, at most, to add from array into this
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • insertAll

      public boolean insertAll(int index, T[] array)
      Specified by:
      insertAll in interface Lisque<T>
      Parameters:
      index - the index in this deque's iteration order to place the first item in array
      array - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
    • insertAll

      public boolean insertAll(int index, T[] array, int offset, int length)
      Specified by:
      insertAll in interface Lisque<T>
      Parameters:
      index - the index in this deque's iteration order to place the first item in array
      array - the elements to be inserted into this deque
      offset - the index of the first item in array to add
      length - how many items, at most, to add from array into this
      Returns:
      true if this deque changed as a result of the call
    • addAll

      public boolean addAll(int index, T[] array)
      Like addAll(int, Collection), but takes an array instead of a Collection and inserts it so the first item will be at the given index. The order of array will be preserved, starting at the given index in this deque.
      Specified by:
      addAll in interface Lisque<T>
      Parameters:
      index - the index in this deque's iteration order to place the first item in array
      array - the elements to be inserted into this deque
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • addAll

      public boolean addAll(int index, T[] array, int offset, int length)
      Like addAll(int, Collection), but takes an array instead of a Collection, gets items starting at offset from that array, using length items, and inserts them so the item at the given offset will be at the given index. The order of array will be preserved, starting at the given index in this deque.
      Specified by:
      addAll in interface Lisque<T>
      Parameters:
      index - the index in this deque's iteration order to place the first item in array
      array - the elements to be inserted into this deque
      offset - the index of the first item in array to add
      length - how many items, at most, to add from array into this
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • push

      public void push(T t)
      Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.

      This method is equivalent to addFirst(T).

      Specified by:
      push in interface Deque<T>
      Specified by:
      push in interface Lisque<T>
      Parameters:
      t - the element to push
      Throws:
      IllegalStateException - if the element cannot be added at this time due to capacity restrictions
      ClassCastException - if the class of the specified element prevents it from being added to this deque
      NullPointerException - if the specified element is null and this deque does not permit null elements
      IllegalArgumentException - if some property of the specified element prevents it from being added to this deque
    • pop

      public T pop()
      Pops an element from the stack represented by this deque. In other words, removes and returns the first element of this deque.

      This method is equivalent to removeFirst().

      Specified by:
      pop in interface Deque<T>
      Specified by:
      pop in interface Lisque<T>
      Returns:
      the element at the front of this deque (which is the top of the stack represented by this deque)
      Throws:
      NoSuchElementException - if this deque is empty
    • remove

      public boolean remove(Object o)
      Removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the first element e such that Objects.equals(o, e) (if such an element exists). Returns true if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).

      This method is equivalent to removeFirstOccurrence(Object).

      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface Deque<T>
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractCollection<T>
      Parameters:
      o - element to be removed from this deque, if present
      Returns:
      true if an element was removed as a result of this call
      Throws:
      ClassCastException - if the class of the specified element is incompatible with this deque (optional)
      NullPointerException - if the specified element is null and this deque does not permit null elements (optional)
    • contains

      public boolean contains(Object o)
      Returns true if this deque contains the specified element. More formally, returns true if and only if this deque contains at least one element e such that Objects.equals(o, e).
      Specified by:
      contains in interface Collection<T>
      Specified by:
      contains in interface Deque<T>
      Specified by:
      contains in interface Lisque<T>
      Specified by:
      contains in interface List<T>
      Overrides:
      contains in class AbstractCollection<T>
      Parameters:
      o - element whose presence in this deque is to be tested
      Returns:
      true if this deque contains the specified element
      Throws:
      ClassCastException - if the class of the specified element is incompatible with this deque (optional)
      NullPointerException - if the specified element is null and this deque does not permit null elements (optional)
    • size

      public int size()
      Returns the number of elements in this deque.
      Specified by:
      size in interface Arrangeable
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface Deque<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
      Returns:
      the number of elements in this deque
    • toArray

      public Object[] toArray()
      Returns an array containing all the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array's runtime component type is Object.

      The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface List<T>
      Overrides:
      toArray in class AbstractCollection<T>
      Returns:
      an array, whose runtime component type is Object, containing all the elements in this collection
    • toArray

      public <E> E[] toArray(E[] a)
      Returns an array containing all the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

      If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

      If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface List<T>
      Overrides:
      toArray in class AbstractCollection<T>
      Parameters:
      a - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
      an array containing all the elements in this collection
      Throws:
      ArrayStoreException - if the runtime type of any element in this collection is not assignable to the runtime component type of the specified array
      NullPointerException - if the specified array is null
    • containsAll

      public boolean containsAll(Collection<?> c)
      Returns true if this collection contains all the elements in the specified collection.
      Specified by:
      containsAll in interface Collection<T>
      Specified by:
      containsAll in interface Lisque<T>
      Specified by:
      containsAll in interface List<T>
      Overrides:
      containsAll in class AbstractCollection<T>
      Parameters:
      c - collection to be checked for containment in this collection
      Returns:
      true if this collection contains all the elements in the specified collection
      Throws:
      ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection (optional)
      NullPointerException - if the specified collection contains one or more null elements and this collection does not permit null elements (optional), or if the specified collection is null.
      See Also:
    • containsAll

      public boolean containsAll(Object[] array)
      Exactly like 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 deque
      Returns:
      true if this deque 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 deque
      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 deque contains all the elements in the specified range of array
      See Also:
    • containsAnyIterable

      public boolean containsAnyIterable(Iterable<?> values)
      Returns true if this ObjectDeque 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 ObjectDeque contains any of the items in values, false otherwise
    • containsAny

      public boolean containsAny(Object[] values)
      Returns true if this ObjectDeque 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 ObjectDeque contains any of the items in values, false otherwise
    • containsAny

      public boolean containsAny(Object[] values, int offset, int length)
      Returns true if this ObjectDeque 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 ObjectDeque contains any of the items in the given range of values, false otherwise
    • removeAll

      public boolean removeAll(Collection<?> other)
      Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface Lisque<T>
      Specified by:
      removeAll in interface List<T>
      Overrides:
      removeAll in class AbstractCollection<T>
      Parameters:
      other - collection containing elements to be removed from this collection
      Returns:
      true if this deque changed as a result of the call
      Throws:
      UnsupportedOperationException - if the removeAll method is not supported by this collection
      ClassCastException - if the types of one or more elements in this collection are incompatible with the specified collection (optional)
      NullPointerException - if this collection contains one or more null elements and the specified collection does not support null elements (optional), or if the specified collection is null
      See Also:
    • removeAll

      public boolean removeAll(Object[] other)
      Exactly like 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 collection
      Returns:
      true if this deque 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 deque
      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 deque changed as a result of the call
      See Also:
    • removeEachIterable

      public boolean removeEachIterable(Iterable<?> other)
      Removes from this collection element-wise occurrences of elements contained in the specified other collection. Note that if a value is present more than once in this collection, only one of those occurrences will be removed for each occurrence of that value in other. If other has the same contents as this collection or has additional items, then removing each of other will clear this.
      Specified by:
      removeEachIterable in interface EnhancedCollection<T>
      Parameters:
      other - a Collection of items to remove one-by-one, such as an ObjectList or an ObjectSet
      Returns:
      true if this deque 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 collection
      Returns:
      true if this deque 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 deque
      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 deque changed as a result of the call
      See Also:
    • retainAll

      public boolean retainAll(Object[] array)
      Exactly like AbstractCollection.retainAll(Collection), but takes an array instead of a Collection.
      Specified by:
      retainAll in interface Lisque<T>
      Parameters:
      array - array containing elements to be retained in this collection
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • retainAll

      public boolean retainAll(Object[] array, int offset, int length)
      Like retainAll(Object[]), but only uses at most length items from array, starting at offset.
      Specified by:
      retainAll in interface Lisque<T>
      Parameters:
      array - the elements to be retained in this deque
      offset - the index of the first item in array to retain
      length - how many items, at most, to retain from array in this
      Returns:
      true if this deque changed as a result of the call
      See Also:
    • selectRanked

      public T selectRanked(Comparator<T> comparator, int kthLowest)
      Selects the kth-lowest element from this ObjectDeque according to Comparator ranking. This might partially sort the ObjectDeque, changing its order. The ObjectDeque must have a size greater than 0, or a RuntimeException will be thrown.
      Parameters:
      comparator - used for comparison
      kthLowest - rank of desired object according to comparison; k is based on ordinal numbers, not array indices. For min value use 1, for max value use size of the ObjectDeque; using 0 results in a runtime exception.
      Returns:
      the value of the kth lowest ranked object.
      See Also:
    • selectRankedIndex

      public int selectRankedIndex(Comparator<T> comparator, int kthLowest)
      Gets the index of the kth-lowest element from this ObjectDeque according to Comparator ranking. This might partially sort the ObjectDeque, changing its order. The ObjectDeque must have a size greater than 0, or a RuntimeException will be thrown.
      Parameters:
      comparator - used for comparison
      kthLowest - rank of desired object according to comparison; k is based on ordinal numbers, not array indices. For min value use 1, for max value use size of the ObjectDeque; using 0 results in a runtime exception.
      Returns:
      the index of the kth lowest ranked object.
      See Also:
    • truncateLast

      public void truncateLast(int newSize)
      Alias for truncate(int).
      Specified by:
      truncateLast in interface Lisque<T>
      Parameters:
      newSize - the size this deque should have after this call completes, if smaller than the current size
    • truncate

      public void truncate(int newSize)
      Reduces the size of the deque to the specified size by bulk-removing items from the tail end. If the deque is already smaller than the specified size, no action is taken.
      Specified by:
      truncate in interface Lisque<T>
      Parameters:
      newSize - the size this deque should have after this call completes, if smaller than the current size
    • truncateFirst

      public void truncateFirst(int newSize)
      Reduces the size of the deque to the specified size by bulk-removing from the head. If the deque is already smaller than the specified size, no action is taken.
      Specified by:
      truncateFirst in interface Lisque<T>
      Parameters:
      newSize - the size this deque should have after this call completes, if smaller than the current size
    • removeRange

      public void removeRange(int fromIndex, int toIndex)
      Removes from this list all the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. If toIndex==fromIndex, this operation has no effect. If fromIndex is 0 or less, this delegates to truncateFirst(int); if toIndex is equal to or greater than the size of this collection, this delegates to truncate(int).
      This is public here, not protected as in most JDK collections, because there are actually sometimes needs for this in user code.
      Specified by:
      removeRange in interface Lisque<T>
      Overrides:
      removeRange in class AbstractList<T>
      Parameters:
      fromIndex - index of first element to be removed (inclusive)
      toIndex - index after last element to be removed (exclusive)
    • indexOf

      public int indexOf(Object value)
      Returns the index of the first occurrence of value in the deque, or -1 if no such value exists. Uses .equals() to compare items.
      Specified by:
      indexOf in interface Lisque<T>
      Specified by:
      indexOf in interface List<T>
      Overrides:
      indexOf in class AbstractList<T>
      Parameters:
      value - the Object to look for, which may be null
      Returns:
      An index of the first occurrence of value in the deque or -1 if no such value exists
    • indexOf

      public int indexOf(Object value, int fromIndex)
      Returns the index of the first occurrence of value in the deque, or -1 if no such value exists. Uses .equals() to compare items. This returns fromIndex if value is present at that point, so if you chain calls to indexOf(), the subsequent fromIndex should be larger than the last-returned index.
      Specified by:
      indexOf in interface Lisque<T>
      Parameters:
      value - the Object to look for, which may be null
      fromIndex - the initial index to check (zero-indexed, starts at the head, inclusive)
      Returns:
      An index of first occurrence of value at or after fromIndex in the deque, or -1 if no such value exists
    • indexOf

      public int indexOf(Object value, boolean identity)
      Returns the index of first occurrence of value in the deque, or -1 if no such value exists. When identity is false, uses .equals() to compare items; when identity is true, uses == .
      Parameters:
      value - the Object to look for, which may be null
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      An index of first occurrence of value in the deque or -1 if no such value exists
    • indexOf

      public int indexOf(Object value, int fromIndex, boolean identity)
      Returns the index of first occurrence of value in the deque, starting from fromIndex, or -1 if no such value exists. This returns fromIndex if value is present at that point, so if you chain calls to indexOf(), the subsequent fromIndex should be larger than the last-returned index. When identity is false, uses .equals() to compare items; when identity is true, uses == .
      Parameters:
      value - the Object to look for, which may be null
      fromIndex - the initial index to check (zero-indexed, starts at the head, inclusive)
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      An index of first occurrence of value at or after fromIndex in the deque, or -1 if no such value exists
    • lastIndexOf

      public int lastIndexOf(Object value)
      Returns the index of the last occurrence of value in the deque, or -1 if no such value exists. Uses .equals() to compare items.
      Specified by:
      lastIndexOf in interface Lisque<T>
      Specified by:
      lastIndexOf in interface List<T>
      Overrides:
      lastIndexOf in class AbstractList<T>
      Parameters:
      value - the Object to look for, which may be null
      Returns:
      An index of the last occurrence of value in the deque or -1 if no such value exists
    • lastIndexOf

      public int lastIndexOf(Object value, int fromIndex)
      Returns the index of last occurrence of value in the deque, starting from fromIndex and going backwards, or -1 if no such value exists. This returns fromIndex if value is present at that point, so if you chain calls to indexOf(), the subsequent fromIndex should be smaller than the last-returned index. Uses .equals() to compare items.
      Specified by:
      lastIndexOf in interface Lisque<T>
      Parameters:
      value - the Object to look for, which may be null
      fromIndex - the initial index to check (zero-indexed, starts at the head, inclusive)
      Returns:
      An index of last occurrence of value at or before fromIndex in the deque, or -1 if no such value exists
    • lastIndexOf

      public int lastIndexOf(Object value, boolean identity)
      Returns the index of the last occurrence of value in the deque, or -1 if no such value exists.
      Parameters:
      value - the Object to look for, which may be null
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      An index of the last occurrence of value in the deque or -1 if no such value exists
    • lastIndexOf

      public int lastIndexOf(Object value, int fromIndex, boolean identity)
      Returns the index of last occurrence of value in the deque, starting from fromIndex and going backwards, or -1 if no such value exists. This returns fromIndex if value is present at that point, so if you chain calls to indexOf(), the subsequent fromIndex should be smaller than the last-returned index. When identity is false, uses .equals() to compare items; when identity is true, uses == .
      Parameters:
      value - the Object to look for, which may be null
      fromIndex - the initial index to check (zero-indexed, starts at the head, inclusive)
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      An index of last occurrence of value at or before fromIndex in the deque, or -1 if no such value exists
    • listIterator

      public ListIterator<T> listIterator()
      Specified by:
      listIterator in interface Lisque<T>
      Specified by:
      listIterator in interface List<T>
      Overrides:
      listIterator in class AbstractList<T>
    • listIterator

      public ListIterator<T> listIterator(int index)
      Gets an iterator over this deque that starts at the given index.
      Specified by:
      listIterator in interface Lisque<T>
      Specified by:
      listIterator in interface List<T>
      Overrides:
      listIterator in class AbstractList<T>
      Parameters:
      index - the index to start iterating from in this deque
      Returns:
      a reused iterator starting at the given index
    • subList

      public List<T> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<T>
      Overrides:
      subList in class AbstractList<T>
    • removeValue

      public boolean removeValue(Object value, boolean identity)
      Removes the first instance of the specified value in the deque.
      Parameters:
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      true if value was found and removed, false otherwise
    • removeLastValue

      public boolean removeLastValue(Object value, boolean identity)
      Removes the last instance of the specified value in the deque.
      Parameters:
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      true if value was found and removed, false otherwise
    • removeAt

      public T removeAt(int index)
      Removes the element at the specified position in this deque. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the deque.
      This is an alias for remove(int) for compatibility with primitive-backed lists and deques; remove(int) can refer to the method that removes an item by value, not by index, in those types.
      Specified by:
      removeAt in interface Lisque<T>
      Parameters:
      index - the index of the element to be removed
      Returns:
      the element previously at the specified position
    • remove

      public T remove(int index)
      Removes the element at the specified position in this deque. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the deque.
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractList<T>
      Parameters:
      index - the index of the element to be removed
      Returns:
      the element previously at the specified position
    • pollAt

      public T pollAt(int index)
      Removes the element at the specified position in this deque. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the deque, or the default value if this is empty. This will not throw an Exception in normal usage, even if index is negative (which makes this simply return pollFirst()) or greater than or equal to size() (which makes this return pollLast()).
      This is an alias for poll(int) for compatibility with primitive-backed lists and deques; poll(int) can refer to the method that removes an item by value, not by index, in those types.
      Specified by:
      pollAt in interface Lisque<T>
      Parameters:
      index - the index of the element to be removed
      Returns:
      the element previously at the specified position
    • poll

      public T poll(int index)
      Removes the element at the specified position in this deque. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the deque, or the default value if this is empty. This will not throw an Exception in normal usage, even if index is negative (which makes this simply return pollFirst()) or greater than or equal to size() (which makes this return pollLast()).
      Specified by:
      poll in interface Lisque<T>
      Parameters:
      index - the index of the element to be removed
      Returns:
      the element previously at the specified position
    • notEmpty

      public boolean notEmpty()
      Returns true if the deque has one or more items.
      Specified by:
      notEmpty in interface Lisque<T>
    • isEmpty

      public boolean isEmpty()
      Returns true if the deque is empty.
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface Lisque<T>
      Specified by:
      isEmpty in interface List<T>
      Overrides:
      isEmpty in class AbstractCollection<T>
    • first

      public T first()
      Returns the first (head) item in the deque (without removing it).
      Specified by:
      first in interface EnhancedCollection<T>
      Returns:
      the first item in this EnhancedCollection, as produced by Collection.iterator()
      Throws:
      NoSuchElementException - when the deque is empty
      See Also:
    • last

      public T last()
      Returns the last (tail) item in the deque (without removing it).
      Specified by:
      last in interface Lisque<T>
      Throws:
      NoSuchElementException - when the deque is empty
      See Also:
    • get

      public T get(int index)
      Returns the element at the specified position in this deque. Like ArrayList or ObjectList, but unlike LinkedList, this runs in O(1) time. It is expected to be slightly slower than ArrayList.get(int), which also runs in O(1) time. Unlike get() in ArrayList or ObjectList, this considers negative indices to refer to the first item, and too-large indices to refer to the last item. That means it delegates to getFirst() or getLast() in those cases instead of throwing an IndexOutOfBoundsException, though it may throw a NoSuchElementException if the deque is empty and there is no item it can get.
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<T>
      Parameters:
      index - index of the element to return
      Returns:
      the element at the specified position in this deque
      Throws:
      NoSuchElementException - if the deque is empty
    • peekAt

      public T peekAt(int index)
      Returns the element at the specified position in this deque. Like ArrayList or ObjectList, but unlike LinkedList, this runs in O(1) time. It is expected to be slightly slower than ArrayList.get(int), which also runs in O(1) time. Unlike get() in ArrayList or ObjectList, this considers negative indices to refer to the first item, and too-large indices to refer to the last item. That means it delegates to peekFirst() or peekLast() in those cases instead of throwing an IndexOutOfBoundsException, and it will return the default value if the deque is empty. Unless changed, the default value is usually null.
      Specified by:
      peekAt in interface Lisque<T>
      Parameters:
      index - index of the element to return
      Returns:
      the element at the specified position in this deque
    • set

      public T set(int index, T item)
      Replaces the element at the specified position in this list with the specified element. If this deque is empty or the index is larger than the largest index currently in this deque, this delegates to addLast(Object) and returns the default value. If the index is negative, this delegates to addFirst(Object) and returns the default value.
      Specified by:
      set in interface Lisque<T>
      Specified by:
      set in interface List<T>
      Overrides:
      set in class AbstractList<T>
      Parameters:
      index - index of the element to replace
      item - element to be stored at the specified position
      Returns:
      the element previously at the specified position
      Throws:
      ClassCastException - if the class of the specified element prevents it from being put in this list
    • clear

      public void clear()
      Removes all values from this deque. Values in backing array are set to null to prevent memory leaks, so this operates in O(n) time.
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface List<T>
      Overrides:
      clear in class AbstractList<T>
    • 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 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:
      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 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:
      the number of replacements that occurred; 0 if nothing was found or replaced
    • iterator

      public ObjectDeque.ObjectDequeIterator<T> iterator()
      Returns an iterator for the items in the deque. Remove is supported.
      Reuses one of two iterators for this deque. For nested or multithreaded iteration, use ObjectDequeIterator(ObjectDeque).
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Deque<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Lisque<T>
      Specified by:
      iterator in interface List<T>
      Overrides:
      iterator in class AbstractList<T>
    • descendingIterator

      public ObjectDeque.ObjectDequeIterator<T> descendingIterator()
      Returns an iterator over the elements in this deque in reverse sequential order. The elements will be returned in order from last (tail) to first (head).
      Reuses one of two descending iterators for this deque. For nested or multithreaded iteration, use ObjectDequeIterator(ObjectDeque, boolean).
      Specified by:
      descendingIterator in interface Deque<T>
      Specified by:
      descendingIterator in interface Lisque<T>
      Returns:
      an iterator over the elements in this deque in reverse sequence
    • descendingIterator

      public ObjectDeque.ObjectDequeIterator<T> descendingIterator(int index)
      Returns an iterator over the elements in this deque in reverse sequential order. The elements will be returned in order from index backwards to first (head).
      Reuses one of two descending iterators for this deque. For nested or multithreaded iteration, use ObjectDequeIterator(ObjectDeque, boolean).
      Parameters:
      index - the index to start iterating from in this deque
      Returns:
      an iterator over the elements in this deque in reverse sequence
    • toString

      public String toString()
      Delegates to EnhancedCollection.toString(String, boolean) with a delimiter of ", " and square brackets enabled.
      Overrides:
      toString in class AbstractCollection<T>
      Returns:
      the square-bracketed String representation of this ObjectDeque, with items separated by ", "
    • hashCode

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

      public boolean equals(Object o)
      Using Object.equals(Object) between each item in order, compares for equality with other types implementing List or Queue, including other Deque types. If o is not a List or Queue (and is also not somehow reference-equivalent to this collection), this returns false. This uses the Iterable.iterator() of both this and o, so if either is in the middle of a concurrent iteration that modifies the Collection, this may fail.
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface List<T>
      Overrides:
      equals in class AbstractList<T>
      Parameters:
      o - object to be compared for equality with this collection
      Returns:
      true if this is equal to o, or false otherwise
    • equalsIdentity

      public boolean equalsIdentity(Object o)
      Using == between each item in order, compares for equality with other types implementing List or Queue, including other Deque types. If o is not a List or Queue (and is also not somehow reference-equivalent to this collection), this returns false. This uses the Iterable.iterator() of both this and o, so if either is in the middle of a concurrent iteration that modifies the Collection, this may fail.
      Parameters:
      o - object to be compared for equality with this collection
      Returns:
      true if this is equal to o, or false otherwise
    • swap

      public void swap(int first, int second)
      Switches the ordering of positions first and second, without changing any items beyond that.
      Specified by:
      swap in interface Arrangeable
      Parameters:
      first - the first position, must not be negative and must be less than size()
      second - the second position, must not be negative and must be less than size()
    • reverse

      public void reverse()
      Reverses this ObjectDeque in-place.
      Specified by:
      reverse in interface Arrangeable
    • shuffle

      public void shuffle(Random rng)
      Description copied from interface: Arrangeable
      Pseudo-randomly shuffles the order of this Arrangeable in-place.
      Specified by:
      shuffle in interface Arrangeable
      Parameters:
      rng - any Random, such as AlternateRandom or one from juniper
    • sort

      public void sort()
      Attempts to sort this deque in-place using its natural ordering, which requires T to implement Comparable of T. Uses ObjectComparators.sort(Object[], int, int, Comparator).
    • sort

      public void sort(int from, int to)
      Uses ObjectComparators.sort(Object[], int, int, Comparator) to sort a (clamped) subrange of this deque. Sorts using the natural ordering of T, which requires T to implement Comparable of T. This only sorts between indices from (inclusive) and to (exclusive).
      Parameters:
      from - first index to use, inclusive
      to - last index to use, exclusive
    • sort

      public void sort(Comparator<? super T> comparator)
      Sorts this deque in-place using ObjectComparators.sort(Object[], int, int, Comparator). This should operate in O(n log(n)) time or less when the internals of the deque are continuous (the head is before the tail in the array). If the internals are not continuous, this takes an additional O(n) step (where n is less than the size of the deque) to rearrange the internals before sorting. You can pass null as the value for comparator if T implements Comparable of T, which will make this use the natural ordering for T.
      Specified by:
      sort in interface Lisque<T>
      Specified by:
      sort in interface List<T>
      Parameters:
      comparator - the Comparator to use for T items; may be null to use the natural order of T items when T implements Comparable of T
    • sort

      public void sort(int from, int to, Comparator<? super T> comparator)
      Sorts this deque in-place using ObjectComparators.sort(Object[], int, int, Comparator). This only sorts between indices from (inclusive) and to (exclusive). This should operate in O(n log(n)) time or less when the subrange of the deque is continuous (from is before to in the array). If the internals are not continuous, this takes an additional O(n) step (where n is less than the size of the deque) to rearrange the internals before sorting. You can pass null as the value for comparator if T implements Comparable of T, which will make this use the natural ordering for T.
      Parameters:
      comparator - the Comparator to use for T items; may be null to use the natural order of T items when T implements Comparable of T
    • sortJDK

      public void sortJDK()
      Sorts this deque using Arrays.sort(Object[], int, int). This should operate in O(n log(n)) time or less when the internals of the deque are continuous (the head is before the tail in the array). If the internals are not continuous, this takes an additional O(n) step (where n is less than the size of the deque) to rearrange the internals before sorting. This requires T to implement Comparable of T, and this will use the natural ordering for T.
    • sortJDK

      public void sortJDK(Comparator<? super T> comparator)
      Sorts this deque using Arrays.sort(Object[], int, int, Comparator). This should operate in O(n log(n)) time or less when the internals of the deque are continuous (the head is before the tail in the array). If the internals are not continuous, this takes an additional O(n) step (where n is less than the size of the deque) to rearrange the internals before sorting. You can pass null as the value for comparator if T implements Comparable of T, which will make this use the natural ordering for T.
      Parameters:
      comparator - the Comparator to use for T items; may be null to use the natural order of T items when T implements Comparable of T
    • sortJDK

      public void sortJDK(int from, int to)
      Uses Arrays.sort(Object[], int, int) to sort a (clamped) subrange of this deque. This only sorts between indices from (inclusive) and to (exclusive). This should operate in O(n log(n)) time or less when the subrange of the deque is continuous (from is before to in the array). If the internals are not continuous, this takes an additional O(n) step (where n is less than the size of the deque) to rearrange the internals before sorting. You can pass null as the value for comparator if T implements Comparable of T, which will make this use the natural ordering for T.
      Parameters:
      from - first index to use, inclusive
      to - last index to use, exclusive
    • sortJDK

      public void sortJDK(int from, int to, Comparator<? super T> comparator)
      Uses Arrays.sort(Object[], int, int, Comparator) to sort a (clamped) subrange of this deque. This only sorts between indices from (inclusive) and to (exclusive). This should operate in O(n log(n)) time or less when the subrange of the deque is continuous (from is before to in the array). If the internals are not continuous, this takes an additional O(n) step (where n is less than the size of the deque) to rearrange the internals before sorting. You can pass null as the value for comparator if T implements Comparable of T, which will make this use the natural ordering for T.
      Parameters:
      from - first index to use, inclusive
      to - last index to use, exclusive
      comparator - the Comparator to use for T items; may be null to use the natural order of T items when T implements Comparable of T
    • getRandom

      public T getRandom(Random random)
      Gets a randomly selected item from this ObjectDeque. Throws a NoSuchElementException if empty.
      Parameters:
      random - any Random or subclass of it, such as AlternateRandom.
      Returns:
      a randomly selected item from this deque
    • random

      public T random(Random random)
      Returns a T item from anywhere in this ObjectDeque, chosen pseudo-randomly using random. If this ObjectDeque is empty, returns getDefaultValue().
      Specified by:
      random in interface Lisque<T>
      Parameters:
      random - any Random or subclass of it, such as AlternateRandom.
      Returns:
      a randomly selected item from this deque, or the default value if empty
    • with

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

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

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

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

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

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

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

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

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

      @SafeVarargs public static <T> ObjectDeque<T> with(T... varargs)
      Creates a new ObjectDeque 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 ObjectDeque that holds the given T items
    • parse

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