Package com.github.tommyettinger.ds
Interface PrimitiveCollection.OfBoolean
- All Superinterfaces:
PrimitiveCollection<Boolean>
- All Known Implementing Classes:
BooleanBag,BooleanDeque,BooleanList
- Enclosing interface:
- PrimitiveCollection<T>
A PrimitiveCollection with unboxed
boolean items.-
Nested Class Summary
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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(boolean item) default booleanaddAll(boolean[] array) default booleanaddAll(boolean[] array, int offset, int length) default booleandefault booleandefault voidaddDense(CharSequence cs) Adds items to this PrimitiveCollection drawn from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean).default voidaddDense(CharSequence cs, int offset, int length) Adds items to this PrimitiveCollection drawn from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean).default voidaddLegible(String str, String delimiter) Adds items to this PrimitiveCollection drawn from the result oftoString(String)orappendTo(CharSequence, String, boolean).default voidaddLegible(String str, String delimiter, int offset, int length) Adds items to this PrimitiveCollection drawn from the result oftoString(String)orappendTo(CharSequence, String, boolean).default booleanaddVarargs(boolean... varargs) Takes an array of items to add, or more simply 0 or more arguments that will each be added.default <S extends CharSequence & Appendable>
SDelegates toappendTo(CharSequence, String, boolean, BooleanAppender)usingBooleanAppender.DEFAULTto append int items.default <S extends CharSequence & Appendable>
SappendTo(S sb, String separator, boolean brackets, BooleanAppender appender) Appends to an Appendable CharSequence from the contents of this PrimitiveCollection, but uses the givenBooleanAppenderto convert each item to a customizable representation and append them tosb.booleancontains(boolean item) default booleancontainsAll(boolean[] array) default booleancontainsAll(boolean[] array, int offset, int length) default booleandefault booleandefault booleancontainsAny(boolean[] array) default booleancontainsAny(boolean[] array, int offset, int length) default booleandefault booleandefault <S extends CharSequence & Appendable>
SdenseAppendTo(S sb, boolean brackets) Appends tosbany items in this PrimitiveCollection as either "1" for true items or "0" for false, with no separators and optionally with square brackets surrounding the text ifbracketsis true.default booleanfirst()Attempts to get the first item in this PrimitiveCollection, where "first" is only defined meaningfully if this type is ordered.default voidforEach(com.github.tommyettinger.function.BooleanConsumer action) Performs the given action for each element of thePrimitiveCollection.OfBooleanuntil all elements have been processed or the action throws an exception.iterator()static boolean[]readArrayDense(boolean[] buffer, int bufferIndex, CharSequence cs, int offset, int length) Reads zero or more items from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean)and assigns them to consecutive items inbuffer, starting atbufferIndex.static boolean[]Reads zero or more items from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean)and assigns them to consecutive items in a new boolean array sized tocs.length().static booleanreadDense(CharSequence cs, int position) Reads in exactly onecharfrom the givenpositionin the givenCharSequence, such as a String or StringBuilder, and returns true if it is the char'1'or returns false otherwise.booleanremove(boolean item) default booleanremoveAll(boolean[] array) default booleanremoveAll(boolean[] array, int offset, int length) default booleanRemoves from this collection all occurrences of any elements contained in the specified other collection.default booleanRemoves from this collection all occurrences of any elements contained in the specified BooleanIterator.default booleanremoveEach(boolean[] array) default booleanremoveEach(boolean[] array, int offset, int length) default booleanRemoves from this collection element-wise occurrences of elements contained in the specified other collection.default booleanRemoves from this collection element-wise occurrences of elements contained in the specified BooleanIterator.default booleanremoveIf(com.github.tommyettinger.function.BooleanPredicate filter) Removes all the elements of this collection that satisfy the given predicate.default booleanretainAll(boolean[] array) default booleanretainAll(boolean[] array, int offset, int length) default booleandefault boolean[]toArray()Allocates a new boolean array with exactlyPrimitiveCollection.size()items, fills it with the contents of this PrimitiveCollection, and returns it.default boolean[]toArray(boolean[] receiver) Fills the given array with the entire contents of this PrimitiveCollection, up toPrimitiveCollection.size()items, or if receiver is not large enough, then this allocates a new boolean array withPrimitiveCollection.size()items and returns that.default StringReturns a String representing this PrimitiveCollection with "1" for true items and "0" for false, with no surrounding brackets.default StringtoDenseString(boolean brackets) Returns a String representing this PrimitiveCollection with "1" for true items and "0" for false, with surrounding square brackets ifbracketsis true.default StringDelegates totoString(String, boolean)with the given separator and without brackets.default StringDelegates toappendTo(CharSequence, String, boolean)using a new StringBuilder and converts it to a new String.default StringtoString(String separator, boolean brackets, BooleanAppender appender) Makes a String from the contents of this PrimitiveCollection, but uses the givenBooleanAppenderto convert each item to a customizable representation and append them to a StringBuilder.
-
Method Details
-
add
boolean add(boolean item) -
remove
boolean remove(boolean item) -
contains
boolean contains(boolean item) -
addAll
-
addAll
-
addAll
default boolean addAll(boolean[] array) -
addAll
default boolean addAll(boolean[] array, int offset, int length) -
addVarargs
default boolean addVarargs(boolean... varargs) Takes an array of items to add, or more simply 0 or more arguments that will each be added. Ifvarargsis null, this won't add anything and will return false.- Parameters:
varargs- 0 or more items to add; may also be an array- Returns:
- true if this collection was modified
-
removeAll
Removes from this collection all occurrences of any elements contained in the specified other collection.- Parameters:
other- a primitive collection of boolean items to remove fully, such as a BooleanList or a BooleanDeque- Returns:
- true if this collection was modified.
-
removeAll
Removes from this collection all occurrences of any elements contained in the specified BooleanIterator.- Parameters:
it- a BooleanIterator of items to remove fully- Returns:
- true if this collection was modified.
-
removeAll
default boolean removeAll(boolean[] array) -
removeAll
default boolean removeAll(boolean[] array, int offset, int length) -
removeEach
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 inother. Ifotherhas the same contents as this collection or has additional items, then removing each ofotherwill clear this.- Parameters:
other- a primitive collection of boolean items to remove one-by-one, such as a BooleanList or a BooleanDeque- Returns:
- true if this collection was modified.
-
removeEach
Removes from this collection element-wise occurrences of elements contained in the specified BooleanIterator. 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 init. Ifithas the same contents as this collection or has additional items, then removing each ofitwill clear this.- Parameters:
it- a BooleanIterator of items to remove one-by-one- Returns:
- true if this collection was modified.
-
removeEach
default boolean removeEach(boolean[] array) -
removeEach
default boolean removeEach(boolean[] array, int offset, int length) -
containsAll
-
containsAll
-
containsAll
default boolean containsAll(boolean[] array) -
containsAll
default boolean containsAll(boolean[] array, int offset, int length) -
containsAny
-
containsAny
-
containsAny
default boolean containsAny(boolean[] array) -
containsAny
default boolean containsAny(boolean[] array, int offset, int length) -
removeIf
default boolean removeIf(com.github.tommyettinger.function.BooleanPredicate filter) Removes all the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.- Parameters:
filter- a predicate which returnstruefor elements to be removed- Returns:
trueif any elements were removed- Throws:
UnsupportedOperationException- if elements cannot be removed from this collection. Implementations may throw this exception if a matching element cannot be removed or if, in general, removal is not supported.- "Implementation Requirements"
- The default implementation traverses all elements of the collection using
its
iterator(). Each matching element is removed usingIterator.remove(). If the collection's iterator does not support removal then anUnsupportedOperationExceptionwill be thrown on the first matching element.
-
retainAll
-
retainAll
default boolean retainAll(boolean[] array) -
retainAll
default boolean retainAll(boolean[] array, int offset, int length) -
iterator
BooleanIterator iterator()- Specified by:
iteratorin interfacePrimitiveCollection<Boolean>
-
toArray
default boolean[] toArray()Allocates a new boolean array with exactlyPrimitiveCollection.size()items, fills it with the contents of this PrimitiveCollection, and returns it.- Returns:
- a new boolean array
-
toArray
default boolean[] toArray(boolean[] receiver) Fills the given array with the entire contents of this PrimitiveCollection, up toPrimitiveCollection.size()items, or if receiver is not large enough, then this allocates a new boolean array withPrimitiveCollection.size()items and returns that.- Parameters:
receiver- a boolean array that will be filled with the items from this, if possible- Returns:
receiver, if it was modified, or a new boolean array otherwise
-
forEach
default void forEach(com.github.tommyettinger.function.BooleanConsumer action) Performs the given action for each element of thePrimitiveCollection.OfBooleanuntil all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.- Parameters:
action- The action to be performed for each element
-
first
default boolean first()Attempts to get the first item in this PrimitiveCollection, where "first" is only defined meaningfully if this type is ordered. Many times, this applies to a class that is not ordered, and in those cases it can get an arbitrary item, and that item is permitted to be different for different calls to first().
This is useful for cases where you would normally be able to call something likeList.get(int)to get an item, any item, from a collection, but whatever class you're using doesn't necessarily provide a get(), first(), peek(), or similar method.
The default implementation usesiterator(), tries to get the first item, or throws an IllegalStateException if this is empty.- Returns:
- the first item in this PrimitiveCollection, as produced by
iterator() - Throws:
IllegalStateException- if this is empty
-
toString
Delegates totoString(String, boolean)with the given separator and without brackets.- Parameters:
separator- how to separate items, such as", "- Returns:
- a new String representing this PrimitiveCollection
-
toString
Delegates toappendTo(CharSequence, String, boolean)using a new StringBuilder and converts it to a new String.- Parameters:
separator- how to separate items, such as", "brackets- true to wrap the output in square brackets, or false to omit them- Returns:
- a new String representing this PrimitiveCollection
-
toString
Makes a String from the contents of this PrimitiveCollection, but uses the givenBooleanAppenderto convert each item to a customizable representation and append them to a StringBuilder. To use the default String representation, you can useBooleanAppender::appendas an appender, or better yet, useBooleanAppender.DEFAULT, which caches the above method reference when Android won't do that.- Parameters:
separator- how to separate items, such as", "brackets- true to wrap the output in square brackets, or false to omit themappender- a function that takes an Appendable CharSequence and a boolean, and returns the modified sequence- Returns:
- a new String representing this PrimitiveCollection
-
appendTo
Delegates toappendTo(CharSequence, String, boolean, BooleanAppender)usingBooleanAppender.DEFAULTto append int items.- Type Parameters:
S- any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, CharBuffer, or CharList- Parameters:
sb- a StringBuilder or similar that this can append toseparator- how to separate items, such as", "brackets- true to wrap the output in square brackets, or false to omit them- Returns:
sb, with the appended items of this PrimitiveCollection
-
appendTo
default <S extends CharSequence & Appendable> S appendTo(S sb, String separator, boolean brackets, BooleanAppender appender) Appends to an Appendable CharSequence from the contents of this PrimitiveCollection, but uses the givenBooleanAppenderto convert each item to a customizable representation and append them tosb. To use the default String representation, you can useBooleanAppender::appendas an appender, or better yet, useBooleanAppender.DEFAULT, which caches the above method reference when Android won't do that.- Type Parameters:
S- any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, CharBuffer, or CharList- Parameters:
sb- a StringBuilder or similar that this can append toseparator- how to separate items, such as", "brackets- true to wrap the output in square brackets, or false to omit themappender- a function that takes an Appendable CharSequence and a boolean, and returns the modified sequence- Returns:
sb, with the appended items of this PrimitiveCollection
-
toDenseString
Returns a String representing this PrimitiveCollection with "1" for true items and "0" for false, with no surrounding brackets.- Returns:
- a String made of "0" and "1"
-
toDenseString
Returns a String representing this PrimitiveCollection with "1" for true items and "0" for false, with surrounding square brackets ifbracketsis true.- Parameters:
brackets- if true, the result will be surrounded by square brackets- Returns:
- a String made of "0" and "1", optionally with surrounding square brackets
-
denseAppendTo
Appends tosbany items in this PrimitiveCollection as either "1" for true items or "0" for false, with no separators and optionally with square brackets surrounding the text ifbracketsis true.- Parameters:
sb- the StringBuilder to append tobrackets- if true, square brackets will surround the appended text- Returns:
sb, for chaining
-
readDense
Reads in exactly onecharfrom the givenpositionin the givenCharSequence, such as a String or StringBuilder, and returns true if it is the char'1'or returns false otherwise.- Parameters:
cs- a CharSequenceposition- the first position to read exactly one char from incs- Returns:
- true if the char at the given
positionincsis'1', or false otherwise
-
addDense
Adds items to this PrimitiveCollection drawn from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean). Each item is exactly one character long and should use'1'to represent true, or any other character to represent false. No surrounding brackets should be present incs(they will be treated as false items).- Parameters:
cs- a CharSequence containing only BASE90 chars (between'%'and'~', both inclusive)
-
addDense
Adds items to this PrimitiveCollection drawn from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean). Each item is either true if a char is'1'or false otherwise. Any brackets inside the given range of characters will be interpreted as false, not as visual wrappers, so increase offset by 1 and reduce length by 2 if the original CharSequence had brackets added to it.- Parameters:
cs- a CharSequence containing'1'and likely'0'charsoffset- the first position to read chars from incslength- how many chars to read; -1 is treated as maximum length
-
readArrayDense
Reads zero or more items from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean)and assigns them to consecutive items in a new boolean array sized tocs.length(). Each item is exactly one character and can be any Javachar, but only'1'is treated as true.
This may be useful to parse the dense output of one primitive collection into an array to be given to a map constructor or map's addAll() method, which may be able to take an array for keys and for values.- Parameters:
cs- a CharSequence containing typically'1'and'0'as its contents- Returns:
- a new array sized to
cs.length()items, or sized to 0 ifcsis null
-
readArrayDense
static boolean[] readArrayDense(boolean[] buffer, int bufferIndex, CharSequence cs, int offset, int length) Reads zero or more items from the result oftoDenseString()ordenseAppendTo(CharSequence, boolean)and assigns them to consecutive items inbuffer, starting atbufferIndex. Each item is exactly one character and can be any Javachar, but only'1'is treated as true.
This may be useful to parse the dense output of one primitive collection into an array to be given to a map constructor or map's addAll() method, which may be able to take an array for keys and for values.- Parameters:
buffer- an array that will be modified in-place; should not be nullbufferIndex- the first index inbufferto assign tocs- a CharSequence containing typically'1'and'0'as its contentsoffset- the first position to read chars from incslength- how many chars to read; -1 is treated as maximum length- Returns:
buffer, potentially after modifications
-
addLegible
Adds items to this PrimitiveCollection drawn from the result oftoString(String)orappendTo(CharSequence, String, boolean). Each item should be "true" or "false", making it human-readable. Any brackets inside the given range of characters will ruin the parsing, so increase offset by 1 and reduce length by 2 if the original String had brackets added to it.- Parameters:
str- a String containing "true" and "false" separated by delimiterdelimiter- the String separating every item in str
-
addLegible
Adds items to this PrimitiveCollection drawn from the result oftoString(String)orappendTo(CharSequence, String, boolean). Each item should be "true" or "false", making it human-readable. Any brackets inside the given range of characters will ruin the parsing, so increase offset by 1 and reduce length by 2 if the original String had brackets added to it.- Parameters:
str- a String containing "true" and "false" separated by delimiterdelimiter- the String separating every item in stroffset- the first position to read "true" and "false" from instrlength- how many chars to read; -1 is treated as maximum length
-