Class BooleanDeque
- All Implemented Interfaces:
Arrangeable,Ordered.OfBoolean,PrimitiveCollection<Boolean>,PrimitiveCollection.OfBoolean,RandomAccess
boolean with efficient add and remove at the
beginning and end. This extends BooleanList and supports RandomAccess. Like BooleanList, it is a
PrimitiveCollection.OfBoolean, Arrangeable, and Ordered.OfBoolean.
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(boolean).
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, boolean). Relative to a BooleanList, get(int) has slightly
higher overhead, but it still runs in constant time. Unlike ArrayDeque in the JDK, this implements
equals(Object) and hashCode(). This can provide what are effectively
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 BooleanDeque is empty and an item from it is required. An exception is in
set(int, boolean), 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(OfBoolean) and truncateFirst(int). There are
the methods from Arrangeable, and many default methods from PrimitiveCollection and Ordered.
In general, this is an improvement over
ArrayDeque in every type of functionality, and is mostly equivalent
to BooleanList 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 ClassesModifier and TypeClassDescriptionstatic classABooleanIteratorover the elements of a BooleanDeque.Nested classes/interfaces inherited from class com.github.tommyettinger.ds.BooleanList
BooleanList.BooleanListIteratorNested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T>Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.PrimitiveCollection
PrimitiveCollection.OfBoolean, PrimitiveCollection.OfByte, PrimitiveCollection.OfChar, PrimitiveCollection.OfDouble, PrimitiveCollection.OfFloat, PrimitiveCollection.OfInt, PrimitiveCollection.OfLong, PrimitiveCollection.OfShort -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanThe value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when callingpeek()on an empty deque.protected BooleanDeque.BooleanDequeIteratorprotected BooleanDeque.BooleanDequeIteratorprotected intIndex of first element.protected intIndex of last element.Fields inherited from class com.github.tommyettinger.ds.BooleanList
items, iterator1, iterator2, size -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new BooleanDeque which can hold 16 values without needing to resize the backing array.BooleanDeque(boolean[] a) Creates a new BooleanDeque using all the contents of the given array.BooleanDeque(boolean[] a, int offset, int count) Creates a new BooleanDeque usingcountitems froma, starting atoffset.BooleanDeque(int initialSize) Creates a new BooleanDeque which can hold the specified number of values without needing to resize the backing array.BooleanDeque(BooleanDeque deque) Copies the given BooleanDeque exactly into this one.BooleanDeque(Ordered.OfBoolean other) BooleanDeque(Ordered.OfBoolean other, int offset, int count) Creates a new BooleanDeque using all the contents of the given Collection.BooleanDeque(BooleanIterator iter) Creates a new instance containing the items in the specified iterator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(boolean 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, returningtrueupon success and throwing anIllegalStateExceptionif no space is currently available.voidadd(boolean value1, boolean value2) voidadd(boolean value1, boolean value2, boolean value3) voidadd(boolean value1, boolean value2, boolean value3, boolean value4) booleanaddAll(boolean[] array) Exactly likeaddAll(OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean.booleanaddAll(boolean[] array, int offset, int length) booleanaddAll(int index, boolean[] array) LikeaddAll(int, OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean and inserts it so the first item will be at the givenindex.booleanaddAll(int index, boolean[] array, int offset, int length) LikeaddAll(int, OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean, gets items starting atoffsetfrom that array, usinglengthitems, and inserts them so the item at the given offset will be at the givenindex.booleanaddAll(int index, Ordered.OfBoolean ord) LikeaddAll(int, OfBoolean), but takes an ord instead of a PrimitiveCollection.OfBoolean and inserts it so the first item will be at the givenindex.booleanaddAll(int index, Ordered.OfBoolean ord, int offset, int length) LikeaddAll(int, OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean, gets items starting atoffsetfrom that array, usinglengthitems, and inserts them so the item at the given offset will be at the givenindex.booleanaddAll(int index, PrimitiveCollection.OfBoolean c) booleanaddAll(BooleanList list) booleanaddAll(BooleanList list, int offset, int count) booleanaddAll(Ordered.OfBoolean ord) Exactly likeaddAll(OfBoolean), but takes an Ordered.OfBoolean instead of a PrimitiveCollection.OfBoolean.booleanaddAll(Ordered.OfBoolean ord, int offset, int length) booleanAdds all the elements in the specified collection at the end of this deque, as if by callingaddLast(boolean)on each one, in the order that they are returned by the collection's iterator.booleanaddAllFirst(boolean[] array) Exactly likeaddAllFirst(OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean.booleanaddAllFirst(boolean[] array, int offset, int length) booleanExactly likeaddAllFirst(OfBoolean), but takes an ord instead of a PrimitiveCollection.OfBoolean.booleanaddAllFirst(Ordered.OfBoolean ord, int offset, int length) LikeaddAllFirst(Ordered.OfBoolean), but only uses at mostlengthitems fromord, starting atoffset.booleanAdds every item incto this in order at the start.booleanaddAllLast(boolean[] array) An alias foraddAll(boolean[]).booleanaddAllLast(boolean[] array, int offset, int length) An alias foraddAll(boolean[], int, int).booleanAn alias foraddAll(Ordered.OfBoolean).booleanaddAllLast(Ordered.OfBoolean ord, int offset, int length) An alias foraddAll(Ordered.OfBoolean, int, int).booleanAn alias foraddAll(OfBoolean), this adds every item incto this in order at the end.voidaddFirst(boolean value) Prepend given value to the head (enqueue to head).voidaddFirst(boolean value1, boolean value2) voidaddFirst(boolean value1, boolean value2, boolean value3) voidaddFirst(boolean value1, boolean value2, boolean value3, boolean value4) voidaddLast(boolean value) Appends given boolean to the tail (enqueue to tail).voidaddLast(boolean value1, boolean value2) voidaddLast(boolean value1, boolean value2, boolean value3) voidaddLast(boolean value1, boolean value2, boolean value3, boolean value4) and(boolean value) voidand(int index, boolean value) booleanassign(int index, boolean item) Replaces the element at the specified position in this list with the specified element.voidclear()Removes all values from this deque.booleancontains(boolean o) Returnstrueif this deque contains the specified element.booleancontainsAll(BooleanList other) Returns true if this BooleanList contains, at least once, every item inother; otherwise returns false.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.booleanduplicateRange(int index, int count) Inserts the specified number of items at the specified index.booleanelement()Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque).boolean[]ensureCapacity(int additional) Increases the size of the backing array to accommodate the specified number of additional items.protected intensureGap(int index, int gapSize) Make sure there is a "gap" of exactlygapSizevalues starting atindex.booleanUsing==between each item in order, compares for equality with other subtypes ofBooleanList.booleanfirst()Returns the first (head) item in the deque (without removing it).booleanget(int index) Returns the element at the specified position in this deque.booleanGets 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.booleangetFirst()Retrieves, but does not remove, the first element of this deque.booleangetLast()Retrieves, but does not remove, the last element of this deque.booleanGets a randomly selected item from this BooleanDeque, using the given random number generator.inthashCode()intindexOf(boolean value) Returns the index of the first occurrence of value in the deque, or -1 if no such value exists.intindexOf(boolean value, int fromIndex) Returns the index of the first occurrence of value in the deque, or -1 if no such value exists.voidinsert(int index, boolean item) Inserts the specified element into this deque at the specified index.booleaninsertAll(int index, boolean[] array) Alias foraddAll(int, boolean[]).booleaninsertAll(int index, boolean[] array, int offset, int length) Alias foraddAll(int, boolean[], int, int).booleaninsertAll(int index, Ordered.OfBoolean ord) Alias foraddAll(int, Ordered.OfBoolean).booleaninsertAll(int index, Ordered.OfBoolean ord, int offset, int length) Alias foraddAll(int, Ordered.OfBoolean, int, int).booleaninsertAll(int index, PrimitiveCollection.OfBoolean c) An alias foraddAll(int, OfBoolean); inserts all elements in the specified collection into this list at the specified position.booleanisEmpty()Returns true if the deque is empty.iterator()Returns an iterator for the items in the deque.booleanlast()Returns the last (tail) item in the deque (without removing it).intlastIndexOf(boolean value) Returns the index of the last occurrence of value in the deque, or -1 if no such value exists.intlastIndexOf(boolean value, int fromIndex) Returns the index of last occurrence ofvaluein the deque, starting fromfromIndexand going backwards, or -1 if no such value exists.listIterator(int index) Gets an iterator over this deque that starts at the given index.not()voidnot(int index) booleannotEmpty()Returns true if the deque has one or more items.booleanoffer(boolean 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, returningtrueupon success andfalseif no space is currently available.booleanofferFirst(boolean t) Inserts the specified element at the front of this deque unless it would violate capacity restrictions.booleanofferLast(boolean t) Inserts the specified element at the end of this deque unless it would violate capacity restrictions.or(boolean value) voidor(int index, boolean value) order()Returns this BooleanList, since it is its own order.static BooleanDequeCallsparse(String, String, boolean)with brackets set to false.static BooleanDequeCreates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true).static BooleanDequeCreates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)with the given four parameters as-is.booleanpeek()Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returnsdefaultValueif this deque is empty.booleanpeekAt(int index) Returns the element at the specified position in this deque.booleanRetrieves, but does not remove, the first element of this deque, or returnsdefaultValueif this deque is empty.booleanpeekLast()Retrieves, but does not remove, the last element of this deque, or returnsdefaultValueif this deque is empty.booleanpoll()Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returnsdefaultValueif this deque is empty.booleanpoll(int index) Removes the element at the specified position in this deque.booleanpollAt(int index) Removes the element at the specified position in this deque.booleanRetrieves and removes the first element of this deque, or returnsdefaultValueif this deque is empty.booleanpollLast()Retrieves and removes the last element of this deque, or returnsdefaultValueif this deque is empty.booleanpop()Pops an element from the stack represented by this deque.voidpush(boolean t) Pushes an element onto the stack represented by this deque (in other words, at the head of this deque).booleanGets a randomly selected item from this BooleanDeque, using the given random number generator.booleanremove()Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).booleanremove(boolean o) Removes the first occurrence of the specified element from this deque.booleanRemoves from this BooleanList all occurrences of any elements contained in the specified collection.booleanremoveAt(int index) Removes the element at the specified position in this deque.booleanRemoves from this BooleanList element-wise occurrences of elements contained in the specified collection.booleanRemove the first item from the deque.booleanremoveFirstOccurrence(boolean o) Removes the first occurrence of the specified element from this deque.booleanRemove the last item from the deque.booleanremoveLastOccurrence(boolean o) Removes the last occurrence of the specified element from this deque.booleanremoveLastValue(boolean value) Removes the last instance of the specified value in the deque.voidremoveRange(int fromIndex, int toIndex) Removes from this list all the elements whose index is betweenfromIndex, inclusive, andtoIndex, exclusive.booleanremoveValue(boolean value) Removes the first instance of the specified value in the deque.intreplaceAll(boolean find, boolean replace) Replaces every occurrence offindwithreplace.voidreplaceAll(com.github.tommyettinger.function.BooleanPredicate operator) Replaces each element of this list with the result of applying the given operator to that element.booleanreplaceFirst(boolean find, boolean replace) Replaces the first occurrence offindwithreplace.boolean[]resize(int newSize) Resizes the backing array.booleanRemoves all items from this BooleanList that are not present somewhere inother, any number of times.voidreverse()Reverses this BooleanDeque in-place.voidset(int index, boolean item) Replaces the element at the specified position in this list with the specified element.voidsetDefaultValue(boolean 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.boolean[]setSize(int newSize) Sets the list size, leaving any values beyond the current size undefined.boolean[]shrink()Reduces the size of the backing array to the size of the actual items.voidPseudo-randomly shuffles the order of this Ordered in-place.intsize()Returns the number of elements in this deque.voidsort()Attempts to sort this deque in-place using its natural ordering, which sorts false before true.voidsort(int from, int to) UsesBooleanComparators.sort(boolean[], int, int, BooleanComparator)to sort a (clamped) subrange of this collection in ascending order (false, then true).voidsort(int from, int to, BooleanComparator comparator) Sorts a (clamped) subrange of this deque in-place usingBooleanComparators.sort(boolean[], int, int, BooleanComparator).voidsort(BooleanComparator comparator) Sorts this deque in-place usingBooleanComparators.sort(boolean[], int, int, BooleanComparator).voidswap(int first, int second) Switches the ordering of positionsfirstandsecond, without changing any items beyond that.boolean[]toArray()Returns an array containing all the elements in this collection.boolean[]toArray(boolean[] array) Ifarray.lengthat least equal toBooleanList.size(), this copies the contents of this intoarrayand returns it; otherwise, it allocates a new boolean array that can fit all the items in this, and proceeds to copy into that and return that.toString()Delegates toPrimitiveCollection.OfBoolean.toString(String, boolean)with a delimiter of", "and square brackets enabled.voidTrims the capacity of thisBooleanDequeinstance to be the deque's current size.voidtruncate(int newSize) Reduces the size of the deque to the specified size by bulk-removing items from the tail end.voidtruncateFirst(int newSize) Reduces the size of the deque to the specified size by bulk-removing from the head.voidtruncateLast(int newSize) Alias fortruncate(int).static BooleanDequewith()Constructs an empty deque.static BooleanDequewith(boolean item) Creates a new BooleanDeque that holds only the given item, but can be resized.static BooleanDequewith(boolean... varargs) Creates a new BooleanDeque that will hold the items in the given array or varargs.static BooleanDequewith(boolean item0, boolean item1) Creates a new BooleanDeque that holds only the given items, but can be resized.static BooleanDequewith(boolean item0, boolean item1, boolean item2) Creates a new BooleanDeque that holds only the given items, but can be resized.static BooleanDequewith(boolean item0, boolean item1, boolean item2, boolean item3) Creates a new BooleanDeque that holds only the given items, but can be resized.static BooleanDequewith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4) Creates a new BooleanDeque that holds only the given items, but can be resized.static BooleanDequewith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5) Creates a new BooleanDeque that holds only the given items, but can be resized.static BooleanDequewith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6) Creates a new BooleanDeque that holds only the given items, but can be resized.static BooleanDequewith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6, boolean item7) Creates a new BooleanDeque that holds only the given items, but can be resized.xor(boolean value) voidxor(int index, boolean value) Methods inherited from class com.github.tommyettinger.ds.BooleanList
keepsOrderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.tommyettinger.ds.Arrangeable
rearrange, shuffleMethods inherited from interface com.github.tommyettinger.ds.Ordered.OfBoolean
getOrderType, random, selectRanked, selectRankedIndexMethods inherited from interface com.github.tommyettinger.ds.PrimitiveCollection.OfBoolean
addAll, addDense, addDense, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, denseAppendTo, forEach, removeAll, removeAll, removeAll, removeEach, removeEach, removeEach, removeIf, retainAll, retainAll, toDenseString, toDenseString, toString, toString, toString
-
Field Details
-
defaultValue
public boolean defaultValueThe value returned when nothing can be obtained from this deque and an exception is not meant to be thrown, such as when callingpeek()on an empty deque. -
head
protected int headIndex of first element. Logically smaller than tail. Unless empty, it points to a valid element inside the deque. -
tail
protected int tailIndex 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. -
descendingIterator1
-
descendingIterator2
-
-
Constructor Details
-
BooleanDeque
public BooleanDeque()Creates a new BooleanDeque which can hold 16 values without needing to resize the backing array. -
BooleanDeque
public BooleanDeque(int initialSize) Creates a new BooleanDeque 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
-
BooleanDeque
Creates a new BooleanDeque using all the contents of the given Collection.- Parameters:
coll- a Collection of boolean that will be copied into this and used in full- Throws:
NullPointerException- ifcollisnull
-
BooleanDeque
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- ifiterisnull
-
BooleanDeque
Copies the given BooleanDeque exactly into this one. Individual values will be shallow-copied.- Parameters:
deque- another BooleanDeque to copy- Throws:
NullPointerException- ifdequeisnull
-
BooleanDeque
-
BooleanDeque
public BooleanDeque(boolean[] a) Creates a new BooleanDeque using all the contents of the given array.- Parameters:
a- an array of boolean that will be copied into this and used in full- Throws:
NullPointerException- ifaisnull
-
BooleanDeque
public BooleanDeque(boolean[] a, int offset, int count) Creates a new BooleanDeque usingcountitems froma, starting atoffset. Ifcountis 0 or less, this will create an empty BooleanDeque with capacity 1.- Parameters:
a- an array of booleanoffset- where inato start using itemscount- how many items to use froma- Throws:
NullPointerException- ifaisnull
-
BooleanDeque
-
-
Method Details
-
order
Description copied from class:BooleanListReturns this BooleanList, since it is its own order. This is only here to satisfy theOrdered.OfBooleaninterface.- Specified by:
orderin interfaceOrdered.OfBoolean- Overrides:
orderin classBooleanList- Returns:
- this BooleanList
-
getDefaultValue
public boolean 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 usuallynull.- Returns:
- the current default value
-
setDefaultValue
public void setDefaultValue(boolean 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 usuallynull.- Parameters:
defaultValue- any boolean this can return instead of throwing an Exception, ornull
-
addLast
public void addLast(boolean value) Appends given boolean to the tail (enqueue to tail). Unless the backing array needs resizing, operates in O(1) time.- Parameters:
value- can be null
-
addLast
public void addLast(boolean value1, boolean value2) -
addLast
public void addLast(boolean value1, boolean value2, boolean value3) -
addLast
public void addLast(boolean value1, boolean value2, boolean value3, boolean value4) -
addFirst
public void addFirst(boolean value) Prepend given value to the head (enqueue to head). Unless backing array needs resizing, operates in O(1) time.- Parameters:
value- can be null- See Also:
-
addFirst
public void addFirst(boolean value1, boolean value2) -
addFirst
public void addFirst(boolean value1, boolean value2, boolean value3) -
addFirst
public void addFirst(boolean value1, boolean value2, boolean value3, boolean value4) -
trimToSize
public void trimToSize()Trims the capacity of thisBooleanDequeinstance to be the deque's current size. An application can use this operation to minimize the storage of aBooleanDequeinstance.- Overrides:
trimToSizein classBooleanList
-
shrink
public boolean[] shrink()Description copied from class:BooleanListReduces 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.- Overrides:
shrinkin classBooleanList- Returns:
BooleanList.items; this will be a different reference if this resized
-
ensureCapacity
public boolean[] 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.- Overrides:
ensureCapacityin classBooleanList- Returns:
- the backing array this will use after this call
-
resize
public boolean[] 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 atsize - 1. This always allocates a new internal backing array.- Overrides:
resizein classBooleanList- Returns:
- the new backing array, as a direct reference
-
ensureGap
protected int ensureGap(int index, int gapSize) Make sure there is a "gap" of exactlygapSizevalues starting atindex. 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 presentgapSize- 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
-
addAll
- Overrides:
addAllin classBooleanList
-
addAll
- Overrides:
addAllin classBooleanList
-
removeFirst
public boolean removeFirst()Remove the first item from the deque. (dequeue from head) Always O(1).- Returns:
- removed boolean
- Throws:
NoSuchElementException- when the deque is empty
-
removeLast
public boolean removeLast()Remove the last item from the deque. (dequeue from tail) Always O(1).- Returns:
- removed boolean
- Throws:
NoSuchElementException- when the deque is empty- See Also:
-
offerFirst
public boolean offerFirst(boolean 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 theaddFirst(boolean)method, which can fail to insert an element only by throwing an exception.- Parameters:
t- the element to add- Returns:
trueif the element was added to this deque, elsefalse- Throws:
ClassCastException- if the class of the specified element prevents it from being added to this dequeNullPointerException- if the specified element is null and this deque does not permit null elementsIllegalArgumentException- if some property of the specified element prevents it from being added to this deque
-
offerLast
public boolean offerLast(boolean 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 theaddLast(boolean)method, which can fail to insert an element only by throwing an exception.- Parameters:
t- the element to add- Returns:
trueif the element was added to this deque, elsefalse- Throws:
ClassCastException- if the class of the specified element prevents it from being added to this dequeNullPointerException- if the specified element is null and this deque does not permit null elementsIllegalArgumentException- if some property of the specified element prevents it from being added to this deque
-
pollFirst
public boolean pollFirst()Retrieves and removes the first element of this deque, or returnsdefaultValueif this deque is empty. The default value is usuallynullunless it has been changed withsetDefaultValue(boolean).- Returns:
- the head of this deque, or
defaultValueif this deque is empty - See Also:
-
pollLast
public boolean pollLast()Retrieves and removes the last element of this deque, or returnsdefaultValueif this deque is empty. The default value is usuallynullunless it has been changed withsetDefaultValue(boolean).- Returns:
- the tail of this deque, or
defaultValueif this deque is empty - See Also:
-
getFirst
public boolean getFirst()Retrieves, but does not remove, the first element of this deque.This method differs from
peekFirstonly in that it throws an exception if this deque is empty.- Returns:
- the head of this deque
- Throws:
NoSuchElementException- if this deque is empty
-
getLast
public boolean getLast()Retrieves, but does not remove, the last element of this deque. This method differs frompeekLastonly in that it throws an exception if this deque is empty.- Returns:
- the tail of this deque
- Throws:
NoSuchElementException- if this deque is empty
-
peekFirst
public boolean peekFirst()Retrieves, but does not remove, the first element of this deque, or returnsdefaultValueif this deque is empty.- Returns:
- the head of this deque, or
defaultValueif this deque is empty
-
peekLast
public boolean peekLast()Retrieves, but does not remove, the last element of this deque, or returnsdefaultValueif this deque is empty.- Returns:
- the tail of this deque, or
defaultValueif this deque is empty
-
removeFirstOccurrence
public boolean removeFirstOccurrence(boolean 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 elementesuch thato == e(if such an element exists). Returnstrueif this deque contained the specified element (or equivalently, if this deque changed as a result of the call).- Parameters:
o- element to be removed from this deque, if present- Returns:
trueif an element was removed as a result of this call
-
removeLastOccurrence
public boolean removeLastOccurrence(boolean 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 elementesuch thato == e(if such an element exists). Returnstrueif this deque contained the specified element (or equivalently, if this deque changed as a result of the call).- Parameters:
o- element to be removed from this deque, if present- Returns:
trueif an element was removed as a result of this call
-
add
public boolean add(boolean 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, returningtrueupon success and throwing anIllegalStateExceptionif no space is currently available. When using a capacity-restricted deque, it is generally preferable to useoffer.This method is equivalent to
addLast(boolean).- Specified by:
addin interfacePrimitiveCollection.OfBoolean- Overrides:
addin classBooleanList- Parameters:
t- the element to add- Returns:
true(as specified byCollection.add(E))
-
add
public void add(boolean value1, boolean value2) - Overrides:
addin classBooleanList
-
add
public void add(boolean value1, boolean value2, boolean value3) - Overrides:
addin classBooleanList
-
add
public void add(boolean value1, boolean value2, boolean value3, boolean value4) - Overrides:
addin classBooleanList
-
insert
public void insert(int index, boolean item) Inserts the specified element into this deque at the specified index. UnlikeofferFirst(boolean)andofferLast(boolean), 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 tosize()(where it acts like offerLast()).- Overrides:
insertin classBooleanList- Parameters:
index- the index in the deque's insertion order to insert the itemitem- a boolean item to insert; may be null
-
offer
public boolean offer(boolean 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, returningtrueupon success andfalseif no space is currently available. When using a capacity-restricted deque, this method is generally preferable to theadd(boolean)method, which can fail to insert an element only by throwing an exception.This method is equivalent to
offerLast(boolean).- Parameters:
t- the element to add- Returns:
trueif the element was added to this deque, elsefalse
-
remove
public boolean 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 frompoll()only in that it throws an exception if this deque is empty.This method is equivalent to
removeFirst().- Returns:
- the head of the queue represented by this deque
- Throws:
NoSuchElementException- if this deque is empty
-
poll
public boolean poll()Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returnsdefaultValueif this deque is empty.This method is equivalent to
pollFirst().- Returns:
- the first element of this deque, or
defaultValueif this deque is empty
-
element
public boolean 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 frompeekonly in that it throws an exception if this deque is empty.This method is equivalent to
getFirst().- Returns:
- the head of the queue represented by this deque
- Throws:
NoSuchElementException- if this deque is empty
-
peek
public boolean 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 returnsdefaultValueif this deque is empty.This method is equivalent to
peekFirst().- Overrides:
peekin classBooleanList- Returns:
- the head of the queue represented by this deque, or
defaultValueif this deque is empty
-
addAll
Adds all the elements in the specified collection at the end of this deque, as if by callingaddLast(boolean)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
offerseparately 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:
addAllin interfacePrimitiveCollection.OfBoolean- Parameters:
c- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call
-
addAllLast
An alias foraddAll(OfBoolean), this adds every item incto this in order at the end.- Parameters:
c- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call
-
addAllFirst
Adds every item incto this in order at the start. The iteration order ofcwill be preserved for the added items.- Parameters:
c- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call
-
insertAll
An alias foraddAll(int, OfBoolean); 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.)- Parameters:
index- index at which to insert the first element from the specified collectionc- collection containing elements to be added to this list- Returns:
trueif this list changed as a result of the call
-
addAll
-
addAll
public boolean addAll(boolean[] array) Exactly likeaddAll(OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean.- Specified by:
addAllin interfacePrimitiveCollection.OfBoolean- Overrides:
addAllin classBooleanList- Parameters:
array- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAll
public boolean addAll(boolean[] array, int offset, int length) - Specified by:
addAllin interfacePrimitiveCollection.OfBoolean- Overrides:
addAllin classBooleanList- Parameters:
array- the elements to be inserted into this dequeoffset- the index of the first item in array to addlength- how many items, at most, to add from array into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllLast
public boolean addAllLast(boolean[] array) An alias foraddAll(boolean[]).- Parameters:
array- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllLast
public boolean addAllLast(boolean[] array, int offset, int length) An alias foraddAll(boolean[], int, int).- Parameters:
array- the elements to be inserted into this dequeoffset- the index of the first item in array to addlength- how many items, at most, to add from array into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllFirst
public boolean addAllFirst(boolean[] array) Exactly likeaddAllFirst(OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean.- Parameters:
array- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllFirst
public boolean addAllFirst(boolean[] array, int offset, int length) LikeaddAllFirst(boolean[]), but only uses at mostlengthitems fromarray, starting atoffset. The order ofarraywill be preserved, starting at the head of the deque.- Parameters:
array- the elements to be inserted into this dequeoffset- the index of the first item in array to addlength- how many items, at most, to add from array into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
insertAll
public boolean insertAll(int index, boolean[] array) Alias foraddAll(int, boolean[]).- Parameters:
index- the index in this deque's iteration order to place the first item inarrayarray- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call
-
insertAll
public boolean insertAll(int index, boolean[] array, int offset, int length) Alias foraddAll(int, boolean[], int, int).- Parameters:
index- the index in this deque's iteration order to place the first item inarrayarray- the elements to be inserted into this dequeoffset- the index of the first item in array to addlength- how many items, at most, to add from array into this- Returns:
trueif this deque changed as a result of the call
-
addAll
public boolean addAll(int index, boolean[] array) LikeaddAll(int, OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean and inserts it so the first item will be at the givenindex. The order ofarraywill be preserved, starting at the given index in this deque.- Parameters:
index- the index in this deque's iteration order to place the first item inarrayarray- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAll
public boolean addAll(int index, boolean[] array, int offset, int length) LikeaddAll(int, OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean, gets items starting atoffsetfrom that array, usinglengthitems, and inserts them so the item at the given offset will be at the givenindex. The order ofarraywill be preserved, starting at the given index in this deque.- Parameters:
index- the index in this deque's iteration order to place the first item inarrayarray- the elements to be inserted into this dequeoffset- the index of the first item in array to addlength- how many items, at most, to add from array into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAll
Exactly likeaddAll(OfBoolean), but takes an Ordered.OfBoolean instead of a PrimitiveCollection.OfBoolean.- Parameters:
ord- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAll
- Overrides:
addAllin classBooleanList- Parameters:
ord- the elements to be inserted into this dequeoffset- the index of the first item in ord to addlength- how many items, at most, to add from ord into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAll
LikeaddAll(int, OfBoolean), but takes an ord instead of a PrimitiveCollection.OfBoolean and inserts it so the first item will be at the givenindex. The order ofordwill be preserved, starting at the given index in this deque.- Parameters:
index- the index in this deque's iteration order to place the first item inordord- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAll
LikeaddAll(int, OfBoolean), but takes an array instead of a PrimitiveCollection.OfBoolean, gets items starting atoffsetfrom that array, usinglengthitems, and inserts them so the item at the given offset will be at the givenindex. The order ofarraywill be preserved, starting at the given index in this deque.- Overrides:
addAllin classBooleanList- Parameters:
index- the index in this deque's iteration order to place the first item inarrayord- the elements to be inserted into this dequeoffset- the index of the first item in array to addlength- how many items, at most, to add from array into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllLast
An alias foraddAll(Ordered.OfBoolean).- Parameters:
ord- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllLast
An alias foraddAll(Ordered.OfBoolean, int, int).- Parameters:
ord- the elements to be inserted into this dequeoffset- the index of the first item in ord to addlength- how many items, at most, to add from ord into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllFirst
Exactly likeaddAllFirst(OfBoolean), but takes an ord instead of a PrimitiveCollection.OfBoolean.- Parameters:
ord- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call- See Also:
-
addAllFirst
LikeaddAllFirst(Ordered.OfBoolean), but only uses at mostlengthitems fromord, starting atoffset. The order ofordwill be preserved, starting at the head of the deque.- Parameters:
ord- the elements to be inserted into this dequeoffset- the index of the first item in ord to addlength- how many items, at most, to add from ord into this- Returns:
trueif this deque changed as a result of the call- See Also:
-
insertAll
Alias foraddAll(int, Ordered.OfBoolean).- Parameters:
index- the index in this deque's iteration order to place the first item inordord- the elements to be inserted into this deque- Returns:
trueif this deque changed as a result of the call
-
insertAll
Alias foraddAll(int, Ordered.OfBoolean, int, int).- Parameters:
index- the index in this deque's iteration order to place the first item inordord- the elements to be inserted into this dequeoffset- the index of the first item in ord to addlength- how many items, at most, to add from ord into this- Returns:
trueif this deque changed as a result of the call
-
push
public void push(boolean t) Pushes an element onto the stack represented by this deque (in other words, at the head of this deque).This method is equivalent to
addFirst(boolean).- Parameters:
t- the element to push
-
pop
public boolean 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().- Overrides:
popin classBooleanList- 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(boolean 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 elementesuch thato == e(if such an element exists). Returnstrueif this deque contained the specified element (or equivalently, if this deque changed as a result of the call).This method is equivalent to
removeFirstOccurrence(boolean).- Specified by:
removein interfacePrimitiveCollection.OfBoolean- Overrides:
removein classBooleanList- Parameters:
o- element to be removed from this deque, if present- Returns:
trueif an element was removed as a result of this call
-
contains
public boolean contains(boolean o) Returnstrueif this deque contains the specified element. More formally, returnstrueif and only if this deque contains at least one elementesuch thato == e.- Specified by:
containsin interfacePrimitiveCollection.OfBoolean- Overrides:
containsin classBooleanList- Parameters:
o- element whose presence in this deque is to be tested- Returns:
trueif this deque contains the specified element
-
containsAll
Description copied from class:BooleanListReturns true if this BooleanList contains, at least once, every item inother; otherwise returns false.- Overrides:
containsAllin classBooleanList- Parameters:
other- an BooleanList- Returns:
- true if this contains every item in
other, otherwise false
-
size
public int size()Returns the number of elements in this deque.- Specified by:
sizein interfaceArrangeable- Specified by:
sizein interfacePrimitiveCollection<Boolean>- Overrides:
sizein classBooleanList- Returns:
- the number of elements in this deque
-
toArray
public boolean[] 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 isboolean.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:
toArrayin interfacePrimitiveCollection.OfBoolean- Overrides:
toArrayin classBooleanList- Returns:
- an array, whose runtime component
type is
boolean, containing all the elements in this collection
-
toArray
public boolean[] toArray(boolean[] array) Description copied from class:BooleanListIfarray.lengthat least equal toBooleanList.size(), this copies the contents of this intoarrayand returns it; otherwise, it allocates a new boolean array that can fit all the items in this, and proceeds to copy into that and return that.- Specified by:
toArrayin interfacePrimitiveCollection.OfBoolean- Overrides:
toArrayin classBooleanList- Parameters:
array- a boolean array that will be modified if it can fitBooleanList.size()items- Returns:
array, if it had sufficient size, or a new array otherwise, either with a copy of this
-
setSize
public boolean[] setSize(int newSize) Description copied from class:BooleanListSets the list size, leaving any values beyond the current size undefined.- Overrides:
setSizein classBooleanList- Returns:
BooleanList.items; this will be a different reference if this resized to a larger capacity
-
truncateLast
public void truncateLast(int newSize) Alias fortruncate(int).- 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.- Overrides:
truncatein classBooleanList- 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.- 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 betweenfromIndex, inclusive, andtoIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shrinks the list by(toIndex - fromIndex)elements. IftoIndex==fromIndex, this operation has no effect. IffromIndexis 0 or less, this delegates totruncateFirst(int); iftoIndexis equal to or greater than the size of this collection, this delegates totruncate(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:
removeRangein interfaceOrdered.OfBoolean- Overrides:
removeRangein classBooleanList- Parameters:
fromIndex- index of first element to be removed (inclusive)toIndex- index after last element to be removed (exclusive)
-
indexOf
public int indexOf(boolean value) Returns the index of the first occurrence of value in the deque, or -1 if no such value exists.- Overrides:
indexOfin classBooleanList- Parameters:
value- the boolean to look for- Returns:
- An index of the first occurrence of value in the deque or -1 if no such value exists
-
indexOf
public int indexOf(boolean value, int fromIndex) Returns the index of the first occurrence of value in the deque, or -1 if no such value exists. This returnsfromIndexifvalueis present at that point, so if you chain calls to indexOf(), the subsequent fromIndex should be larger than the last-returned index.- Parameters:
value- the boolean to look forfromIndex- 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
-
lastIndexOf
public int lastIndexOf(boolean value) Returns the index of the last occurrence of value in the deque, or -1 if no such value exists.- Overrides:
lastIndexOfin classBooleanList- Parameters:
value- the boolean to look for- Returns:
- An index of the last occurrence of value in the deque or -1 if no such value exists
-
lastIndexOf
public int lastIndexOf(boolean value, int fromIndex) Returns the index of last occurrence ofvaluein the deque, starting fromfromIndexand going backwards, or -1 if no such value exists. This returnsfromIndexifvalueis present at that point, so if you chain calls to indexOf(), the subsequent fromIndex should be smaller than the last-returned index.- Parameters:
value- the boolean to look forfromIndex- 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
-
listIterator
-
listIterator
Gets an iterator over this deque that starts at the given index.- Parameters:
index- the index to start iterating from in this deque- Returns:
- a reused iterator starting at the given index
-
removeValue
public boolean removeValue(boolean value) Removes the first instance of the specified value in the deque.- Parameters:
value- the boolean to remove- Returns:
- true if value was found and removed, false otherwise
-
removeLastValue
public boolean removeLastValue(boolean value) Removes the last instance of the specified value in the deque.- Parameters:
value- the boolean to remove- Returns:
- true if value was found and removed, false otherwise
-
removeAt
public boolean 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.- Overrides:
removeAtin classBooleanList- Parameters:
index- the index of the element to be removed- Returns:
- the element previously at the specified position
-
pollAt
public boolean 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, orthe default valueif this is empty. This will not throw an Exception in normal usage, even if index is negative (which makes this simply returnpollFirst()) or greater than or equal tosize()(which makes this returnpollLast()).
This is an alias forpoll(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.- Parameters:
index- the index of the element to be removed- Returns:
- the element previously at the specified position
-
poll
public boolean 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, orthe default valueif this is empty. This will not throw an Exception in normal usage, even if index is negative (which makes this simply returnpollFirst()) or greater than or equal tosize()(which makes this returnpollLast()).- Parameters:
index- the index of the element to be removed- Returns:
- the element previously at the specified position
-
removeAll
Description copied from class:BooleanListRemoves from this BooleanList all occurrences of any elements contained in the specified collection.- Specified by:
removeAllin interfacePrimitiveCollection.OfBoolean- Overrides:
removeAllin classBooleanList- Parameters:
c- a primitive collection of int items to remove fully, such as another BooleanList or a BooleanDeque- Returns:
- true if this list was modified.
-
removeEach
Description copied from class:BooleanListRemoves from this BooleanList element-wise occurrences of elements contained in the specified collection. Note that if a value is present more than once in this BooleanList, only one of those occurrences will be removed for each occurrence of that value inc. Ifchas the same contents as this BooleanList or has additional items, then removing each ofcwill clear this.- Specified by:
removeEachin interfacePrimitiveCollection.OfBoolean- Overrides:
removeEachin classBooleanList- Parameters:
c- a primitive collection of int items to remove one-by-one, such as another BooleanList or a BooleanDeque- Returns:
- true if this list was modified.
-
retainAll
Description copied from class:BooleanListRemoves all items from this BooleanList that are not present somewhere inother, any number of times.- Specified by:
retainAllin interfacePrimitiveCollection.OfBoolean- Overrides:
retainAllin classBooleanList- Parameters:
other- a PrimitiveCollection.OfBoolean that contains the items that this should keep, whenever present- Returns:
- true if this BooleanList changed as a result of this call, otherwise false
-
notEmpty
public boolean notEmpty()Returns true if the deque has one or more items.- Specified by:
notEmptyin interfacePrimitiveCollection<Boolean>- Overrides:
notEmptyin classBooleanList- Returns:
- true if the list has one or more items, or false otherwise
-
isEmpty
public boolean isEmpty()Returns true if the deque is empty.- Specified by:
isEmptyin interfacePrimitiveCollection<Boolean>- Overrides:
isEmptyin classBooleanList- Returns:
- true if the list is empty, or false if it has any items
-
first
public boolean first()Returns the first (head) item in the deque (without removing it).- Specified by:
firstin interfacePrimitiveCollection.OfBoolean- Overrides:
firstin classBooleanList- Returns:
- the first item, without modifying this
- Throws:
NoSuchElementException- when the deque is empty- See Also:
-
last
public boolean last()Returns the last (tail) item in the deque (without removing it).- Throws:
NoSuchElementException- when the deque is empty- See Also:
-
get
public boolean get(int index) Returns the element at the specified position in this deque. LikeArrayListorBooleanList, but unlikeLinkedList, this runs in O(1) time. It is expected to be slightly slower thanBooleanList.get(int), which also runs in O(1) time. Unlike get() in ArrayList or BooleanList, this considers negative indices to refer to the first item, and too-large indices to refer to the last item. That means it delegates togetFirst()orgetLast()in those cases instead of throwing anIndexOutOfBoundsException, though it may throw aNoSuchElementExceptionif the deque is empty and there is no item it can get.- Overrides:
getin classBooleanList- 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 boolean peekAt(int index) Returns the element at the specified position in this deque. LikeArrayListorBooleanList, but unlikeLinkedList, this runs in O(1) time. It is expected to be slightly slower thanBooleanList.get(int), which also runs in O(1) time. Unlike get() in ArrayList or BooleanList, this considers negative indices to refer to the first item, and too-large indices to refer to the last item. That means it delegates topeekFirst()orpeekLast()in those cases instead of throwing anIndexOutOfBoundsException, and it will returnthe default valueif the deque is empty. Unless changed, the default value is usuallynull.- Parameters:
index- index of the element to return- Returns:
- the element at the specified position in this deque
-
assign
public boolean assign(int index, boolean 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 toaddLast(boolean)and returnsthe default value. If the index is negative, this delegates toaddFirst(boolean)and returnsthe default value.- Parameters:
index- index of the element to replaceitem- element to be stored at the specified position- Returns:
- the element previously at the specified position
-
set
public void set(int index, boolean 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 toaddLast(boolean)and returnsthe default value. If the index is negative, this delegates toaddFirst(boolean)and returnsthe default value.- Overrides:
setin classBooleanList- Parameters:
index- index of the element to replaceitem- element to be stored at the specified position
-
and
public void and(int index, boolean value) - Overrides:
andin classBooleanList
-
and
-
or
public void or(int index, boolean value) - Overrides:
orin classBooleanList
-
or
-
xor
public void xor(int index, boolean value) - Overrides:
xorin classBooleanList
-
xor
-
not
public void not(int index) - Overrides:
notin classBooleanList
-
not
-
replaceAll
public void replaceAll(com.github.tommyettinger.function.BooleanPredicate operator) Description copied from class:BooleanListReplaces each element of this list with the result of applying the given operator to that element.- Overrides:
replaceAllin classBooleanList- Parameters:
operator- a BooleanPredicate (a functional interface defined in funderby)
-
replaceFirst
public boolean replaceFirst(boolean find, boolean replace) Replaces the first occurrence offindwithreplace. 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.- Overrides:
replaceFirstin classBooleanList- Parameters:
find- the item to search forreplace- the item to replacefindwith, if possible- Returns:
- true if this changed, or false otherwise
-
replaceAll
public int replaceAll(boolean find, boolean replace) Replaces every occurrence offindwithreplace. Returns the number of changed items, which is 0 if nothing was found or in the case that find and replace are the same.- Overrides:
replaceAllin classBooleanList- Parameters:
find- the item to search forreplace- the item to replacefindwith, if possible- Returns:
- the number of replacements that occurred; 0 if nothing was found or replaced
-
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.- Overrides:
duplicateRangein classBooleanList- Parameters:
index- the first index to duplicatecount- how many items to duplicate
-
clear
public void clear()Removes all values from this deque. This operates in O(1) time.- Specified by:
clearin interfacePrimitiveCollection<Boolean>- Overrides:
clearin classBooleanList
-
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, useBooleanDequeIterator(BooleanDeque).- Specified by:
iteratorin interfacePrimitiveCollection<Boolean>- Specified by:
iteratorin interfacePrimitiveCollection.OfBoolean- Overrides:
iteratorin classBooleanList- Returns:
- a
BooleanIterator; use its nextBoolean() method instead of next()
-
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, useBooleanDequeIterator(BooleanDeque, boolean).- Returns:
- an iterator over the elements in this deque in reverse sequence
-
descendingIterator
Returns an iterator over the elements in this deque in reverse sequential order. The elements will be returned in order fromindexbackwards to first (head).
Reuses one of two descending iterators for this deque. For nested or multithreaded iteration, useBooleanDequeIterator(BooleanDeque, 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
Delegates toPrimitiveCollection.OfBoolean.toString(String, boolean)with a delimiter of", "and square brackets enabled.- Overrides:
toStringin classBooleanList- Returns:
- the square-bracketed String representation of this BooleanDeque, with items separated by ", "
-
hashCode
public int hashCode()- Specified by:
hashCodein interfacePrimitiveCollection<Boolean>- Overrides:
hashCodein classBooleanList
-
equals
Using==between each item in order, compares for equality with other subtypes ofBooleanList. Ifois not a BooleanList (and is also not somehow reference-equivalent to this collection), this returns false. This uses thePrimitiveCollection.OfBoolean.iterator()of both this ando, so if either is in the middle of a concurrent iteration that modifies the collection, this may fail.- Specified by:
equalsin interfacePrimitiveCollection<Boolean>- Overrides:
equalsin classBooleanList- 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 positionsfirstandsecond, without changing any items beyond that.- Specified by:
swapin interfaceArrangeable- Specified by:
swapin interfaceOrdered.OfBoolean- Overrides:
swapin classBooleanList- Parameters:
first- the first position, must not be negative and must be less thansize()second- the second position, must not be negative and must be less thansize()
-
reverse
public void reverse()Reverses this BooleanDeque in-place.- Specified by:
reversein interfaceArrangeable- Specified by:
reversein interfaceOrdered.OfBoolean- Overrides:
reversein classBooleanList
-
shuffle
Description copied from interface:Ordered.OfBooleanPseudo-randomly shuffles the order of this Ordered in-place. You can seedrng, the random number generator, with an identical seed to reproduce a shuffle on two Ordered with the sameArrangeable.size().- Specified by:
shufflein interfaceArrangeable- Specified by:
shufflein interfaceOrdered.OfBoolean- Overrides:
shufflein classBooleanList- Parameters:
rng- anyRandomclass, such as one from juniper
-
sort
public void sort()Attempts to sort this deque in-place using its natural ordering, which sorts false before true. UsesBooleanComparators.sort(boolean[], int, int, BooleanComparator).- Overrides:
sortin classBooleanList
-
sort
public void sort(int from, int to) UsesBooleanComparators.sort(boolean[], int, int, BooleanComparator)to sort a (clamped) subrange of this collection in ascending order (false, then true).- Overrides:
sortin classBooleanList- Parameters:
from- the index of the first element (inclusive) to be sortedto- the index of the last element (exclusive) to be sorted
-
sort
Sorts this deque in-place usingBooleanComparators.sort(boolean[], int, int, BooleanComparator). 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 forcomparator, which will make this use the natural ordering for boolean (false before true).- Specified by:
sortin interfaceOrdered.OfBoolean- Overrides:
sortin classBooleanList- Parameters:
comparator- the Comparator to use for boolean items; may be null to use the natural order of boolean items when boolean implements Comparable of boolean
-
sort
Sorts a (clamped) subrange of this deque in-place usingBooleanComparators.sort(boolean[], int, int, BooleanComparator). 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 forcomparator, which will make this use the natural ordering for boolean (false before true).- Overrides:
sortin classBooleanList- Parameters:
from- the index of the first element (inclusive) to be sortedto- the index of the last element (exclusive) to be sortedcomparator- the Comparator to use for boolean items; may be null to use the natural order of boolean items when boolean implements Comparable of boolean
-
getRandom
Gets a randomly selected item from this BooleanDeque, using the given random number generator. Throws aNoSuchElementExceptionif empty.- Parameters:
random- any Random or subclass of it, such asAlternateRandom.- Returns:
- a randomly selected item from this deque
-
random
Gets a randomly selected item from this BooleanDeque, using the given random number generator.- Specified by:
randomin interfaceOrdered.OfBoolean- Overrides:
randomin classBooleanList- Parameters:
random- any Random or subclass of it, such asAlternateRandom.- Returns:
- a randomly selected item from this deque, or the default value if empty
-
with
Constructs an empty deque. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new deque containing nothing
-
with
Creates a new BooleanDeque that holds only the given item, but can be resized.- Parameters:
item- one boolean item- Returns:
- a new BooleanDeque that holds the given item
-
with
Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
public static BooleanDeque with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4) Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
public static BooleanDeque with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5) Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean itemitem5- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
public static BooleanDeque with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6) Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean itemitem5- a boolean itemitem6- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
public static BooleanDeque with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6, boolean item7) Creates a new BooleanDeque that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean itemitem5- a boolean itemitem6- a boolean itemitem7- a boolean item- Returns:
- a new BooleanDeque that holds the given items
-
with
Creates a new BooleanDeque that will hold the items in the given array or varargs. This overload will only be used when a boolean array is supplied, or if varargs are used and there are 9 or more arguments.- Parameters:
varargs- either 0 or more boolean items, or an array of boolean- Returns:
- a new BooleanDeque that holds the given boolean items
-
parse
Callsparse(String, String, boolean)with brackets set to false.- Parameters:
str- a String that will be parsed in fulldelimiter- the delimiter between items in str- Returns:
- a new collection parsed from str
-
parse
Creates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true). Each item is expected to be separated bydelimiter.- Parameters:
str- a String that will be parsed in full (depending on brackets)delimiter- the delimiter between items in strbrackets- if true, the first and last chars in str will be ignored- Returns:
- a new collection parsed from str
-
parse
Creates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)with the given four parameters as-is.- Parameters:
str- a String that will have the given section parseddelimiter- the delimiter between items in stroffset- the first position to parse in str, inclusivelength- how many chars to parse, starting from offset- Returns:
- a new collection parsed from str
-