Interface PrimitiveCollection.OfBoolean

All Superinterfaces:
PrimitiveCollection<Boolean>
All Known Implementing Classes:
BooleanBag, BooleanDeque, BooleanList
Enclosing interface:
PrimitiveCollection<T>

public static interface PrimitiveCollection.OfBoolean extends PrimitiveCollection<Boolean>
A PrimitiveCollection with unboxed boolean items.
  • Method Details

    • add

      boolean add(boolean item)
    • remove

      boolean remove(boolean item)
    • contains

      boolean contains(boolean item)
    • addAll

      default boolean addAll(PrimitiveCollection.OfBoolean other)
    • addAll

      default boolean addAll(BooleanIterator it)
    • 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. If varargs is 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

      default boolean removeAll(PrimitiveCollection.OfBoolean other)
      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

      default boolean removeAll(BooleanIterator it)
      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

      default boolean removeEach(PrimitiveCollection.OfBoolean other)
      Removes from this collection element-wise occurrences of elements contained in the specified other collection. Note that if a value is present more than once in this collection, only one of those occurrences will be removed for each occurrence of that value in other. If other has the same contents as this collection or has additional items, then removing each of other will clear this.
      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

      default boolean removeEach(BooleanIterator it)
      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 in it. If it has the same contents as this collection or has additional items, then removing each of it will 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

      default boolean containsAll(PrimitiveCollection.OfBoolean other)
    • containsAll

      default boolean containsAll(BooleanIterator it)
    • containsAll

      default boolean containsAll(boolean[] array)
    • containsAll

      default boolean containsAll(boolean[] array, int offset, int length)
    • containsAny

      default boolean containsAny(PrimitiveCollection.OfBoolean other)
    • containsAny

      default boolean containsAny(BooleanIterator it)
    • 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 returns true for elements to be removed
      Returns:
      true if 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 using Iterator.remove(). If the collection's iterator does not support removal then an UnsupportedOperationException will be thrown on the first matching element.
    • retainAll

      default boolean retainAll(PrimitiveCollection.OfBoolean other)
    • retainAll

      default boolean retainAll(boolean[] array)
    • retainAll

      default boolean retainAll(boolean[] array, int offset, int length)
    • iterator

      BooleanIterator iterator()
      Specified by:
      iterator in interface PrimitiveCollection<Boolean>
    • toArray

      default boolean[] toArray()
      Allocates a new boolean array with exactly PrimitiveCollection.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 to PrimitiveCollection.size() items, or if receiver is not large enough, then this allocates a new boolean array with PrimitiveCollection.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 the PrimitiveCollection.OfBoolean until 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 like List.get(int) to get an item, any item, from a collection, but whatever class you're using doesn't necessarily provide a get(), first(), peek(), or similar method.
      The default implementation uses iterator(), 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

      default String toString(String separator)
      Delegates to toString(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

      default String toString(String separator, boolean brackets)
      Delegates to appendTo(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

      default String toString(String separator, boolean brackets, BooleanAppender appender)
      Makes a String from the contents of this PrimitiveCollection, but uses the given BooleanAppender to convert each item to a customizable representation and append them to a StringBuilder. To use the default String representation, you can use BooleanAppender::append as an appender, or better yet, use BooleanAppender.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 them
      appender - a function that takes an Appendable CharSequence and a boolean, and returns the modified sequence
      Returns:
      a new String representing this PrimitiveCollection
    • appendTo

      default <S extends CharSequence & Appendable> S appendTo(S sb, String separator, boolean brackets)
      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 to
      separator - 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 given BooleanAppender to convert each item to a customizable representation and append them to sb. To use the default String representation, you can use BooleanAppender::append as an appender, or better yet, use BooleanAppender.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 to
      separator - how to separate items, such as ", "
      brackets - true to wrap the output in square brackets, or false to omit them
      appender - 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

      default String 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

      default String toDenseString(boolean brackets)
      Returns a String representing this PrimitiveCollection with "1" for true items and "0" for false, with surrounding square brackets if brackets is 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

      default <S extends CharSequence & Appendable> S denseAppendTo(S sb, boolean brackets)
      Appends to sb any 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 if brackets is true.
      Parameters:
      sb - the StringBuilder to append to
      brackets - if true, square brackets will surround the appended text
      Returns:
      sb, for chaining
    • readDense

      static boolean readDense(CharSequence cs, int position)
      Reads in exactly one char from the given position in the given CharSequence, such as a String or StringBuilder, and returns true if it is the char '1' or returns false otherwise.
      Parameters:
      cs - a CharSequence
      position - the first position to read exactly one char from in cs
      Returns:
      true if the char at the given position in cs is '1', or false otherwise
    • addDense

      default void addDense(CharSequence cs)
      Adds items to this PrimitiveCollection drawn from the result of toDenseString() or denseAppendTo(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 in cs (they will be treated as false items).
      Parameters:
      cs - a CharSequence containing only BASE90 chars (between '%' and '~', both inclusive)
    • addDense

      default void addDense(CharSequence cs, int offset, int length)
      Adds items to this PrimitiveCollection drawn from the result of toDenseString() or denseAppendTo(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' chars
      offset - the first position to read chars from in cs
      length - how many chars to read; -1 is treated as maximum length
    • readArrayDense

      static boolean[] readArrayDense(CharSequence cs)
      Reads zero or more items from the result of toDenseString() or denseAppendTo(CharSequence, boolean) and assigns them to consecutive items in a new boolean array sized to cs.length(). Each item is exactly one character and can be any Java char, 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 if cs is null
    • readArrayDense

      static boolean[] readArrayDense(boolean[] buffer, int bufferIndex, CharSequence cs, int offset, int length)
      Reads zero or more items from the result of toDenseString() or denseAppendTo(CharSequence, boolean) and assigns them to consecutive items in buffer, starting at bufferIndex. Each item is exactly one character and can be any Java char, 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 null
      bufferIndex - the first index in buffer to assign to
      cs - a CharSequence containing typically '1' and '0' as its contents
      offset - the first position to read chars from in cs
      length - how many chars to read; -1 is treated as maximum length
      Returns:
      buffer, potentially after modifications
    • addLegible

      default void addLegible(String str, String delimiter)
      Adds items to this PrimitiveCollection drawn from the result of toString(String) or appendTo(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 delimiter
      delimiter - the String separating every item in str
    • addLegible

      default void addLegible(String str, String delimiter, int offset, int length)
      Adds items to this PrimitiveCollection drawn from the result of toString(String) or appendTo(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 delimiter
      delimiter - the String separating every item in str
      offset - the first position to read "true" and "false" from in str
      length - how many chars to read; -1 is treated as maximum length