Interface PrimitiveCollection.OfChar

All Superinterfaces:
PrimitiveCollection<Character>
All Known Subinterfaces:
PrimitiveSet.SetOfChar
All Known Implementing Classes:
CharBag, CharBitSet, CharDeque, CharList
Enclosing interface:
PrimitiveCollection<T>

public static interface PrimitiveCollection.OfChar extends PrimitiveCollection<Character>
A PrimitiveCollection with unboxed char items.
  • Method Details

    • add

      boolean add(char item)
    • remove

      boolean remove(char item)
    • contains

      boolean contains(char item)
    • addAll

      default boolean addAll(PrimitiveCollection.OfChar other)
    • addAll

      default boolean addAll(CharIterator it)
    • addAll

      default boolean addAll(char[] array)
    • addAll

      default boolean addAll(char[] array, int offset, int length)
    • addVarargs

      default boolean addVarargs(char... 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.OfChar other)
      Removes from this collection all occurrences of any elements contained in the specified other collection.
      Parameters:
      other - a primitive collection of char items to remove fully, such as a CharList or a CharDeque
      Returns:
      true if this collection was modified.
    • removeAll

      default boolean removeAll(CharIterator it)
      Removes from this collection all occurrences of any elements contained in the specified CharIterator.
      Parameters:
      it - a CharIterator of items to remove fully
      Returns:
      true if this collection was modified.
    • removeAll

      default boolean removeAll(char[] array)
    • removeAll

      default boolean removeAll(char[] array, int offset, int length)
    • removeEach

      default boolean removeEach(PrimitiveCollection.OfChar 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 char items to remove one-by-one, such as a CharList or a CharDeque
      Returns:
      true if this collection was modified.
    • removeEach

      default boolean removeEach(CharIterator it)
      Removes from this collection element-wise occurrences of elements contained in the specified CharIterator. 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 CharIterator of items to remove one-by-one
      Returns:
      true if this collection was modified.
    • removeEach

      default boolean removeEach(char[] array)
    • removeEach

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

      default boolean containsAll(PrimitiveCollection.OfChar other)
    • containsAll

      default boolean containsAll(CharIterator it)
    • containsAll

      default boolean containsAll(char[] array)
    • containsAll

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

      default boolean containsAny(PrimitiveCollection.OfChar other)
    • containsAny

      default boolean containsAny(CharIterator it)
    • containsAny

      default boolean containsAny(char[] array)
    • containsAny

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

      default boolean removeIf(com.github.tommyettinger.function.CharPredicate 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.OfChar other)
    • retainAll

      default boolean retainAll(char[] array)
    • retainAll

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

      CharIterator iterator()
      Specified by:
      iterator in interface PrimitiveCollection<Character>
    • toArray

      default char[] toArray()
      Allocates a new char array with exactly PrimitiveCollection.size() items, fills it with the contents of this PrimitiveCollection, and returns it.
      Returns:
      a new char array
    • toArray

      default char[] toArray(char[] 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 char array with PrimitiveCollection.size() items and returns that.
      Parameters:
      receiver - a char array that will be filled with the items from this, if possible
      Returns:
      receiver, if it was modified, or a new char array otherwise
    • forEach

      default void forEach(com.github.tommyettinger.function.CharConsumer action)
      Performs the given action for each element of the PrimitiveCollection.OfChar 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 char 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
    • equalContents

      default boolean equalContents(Object other)
      Compares this PrimitiveCollection.OfChar with a PrimitiveSet.SetOfChar by checking their identity, their types (both must implement PrimitiveCollection.OfChar, and other must implement PrimitiveSet.SetOfChar), and their sizes, before checking if other contains each item in this PrimitiveCollection.OfChar, in any order or quantity. This is most useful for the key "set" or value collection in a primitive-backed map, since quantity doesn't matter for keys and order doesn't matter for either. Many implementations may need to reset the iterator on this PrimitiveCollection.OfChar, but that isn't necessary for other.
      This is not meant for general object equality, but instead for equality following Set semantics. Classes that implement PrimitiveCollection that are not Set-like should usually not use this.
      Parameters:
      other - another Object that should be a PrimitiveSet.SetOfChar
      Returns:
      true if other is a PrimitiveSet.SetOfChar with exactly the same items, false otherwise
    • 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, CharAppender appender)
      Makes a String from the contents of this PrimitiveCollection, but uses the given CharAppender to convert each item to a customizable representation and append them to a StringBuilder. To use the default String representation, you can use CharAppender::append as an appender, or better yet, use CharAppender.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 char, 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, CharAppender appender)
      Appends to an Appendable CharSequence from the contents of this PrimitiveCollection, but uses the given CharAppender to convert each item to a customizable representation and append them to sb. To use the default String representation, you can use CharAppender::append as an appender, or better yet, use CharAppender.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 char, and returns the modified sequence
      Returns:
      sb, with the appended items of this PrimitiveCollection
    • toDenseString

      default String toDenseString()
      Returns a String representing this PrimitiveCollection as the char items themselves, with no surrounding brackets. This does not necessarily make semantically-well-formed text, particularly if it contains surrogate characters without matching them into pairs, but it should always be possible to append any chars.
      Returns:
      a String made of "0" and "1"
    • toDenseString

      default String toDenseString(boolean brackets)
      Returns a String representing this PrimitiveCollection as the char items themselves, with surrounding square brackets if brackets is true. This does not necessarily make semantically-well-formed text, particularly if it contains surrogate characters without matching them into pairs, but it should always be possible to append any chars.
      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 the char items themselves, with no separators and optionally with square brackets surrounding the text if brackets is true. This does not necessarily make semantically-well-formed text, particularly if it contains surrogate characters without matching them into pairs, but it should always be possible to append any chars.
      Parameters:
      sb - the StringBuilder to append to
      brackets - if true, square brackets will surround the appended text
      Returns:
      sb, for chaining
    • readDense

      static char 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 that char. As you may have guessed, this is equivalent to CharSequence.charAt(int). This is only here for completeness.
      Parameters:
      cs - a CharSequence
      position - the first position to read exactly one char from in cs
      Returns:
      the char at the given position in cs
    • 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 is exactly that character, so all chars in the Unicode BMP can be present. No surrounding brackets should be present in cs (they will be treated as 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 exactly the shown character in the CharSequence. Any brackets inside the given range of characters will be interpreted as items, 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 arbitrary 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 char[] 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 char array sized to cs.length(). Each item is exactly one character and can be any Java char.
      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 only BASE90 chars (between '%' and '~', both inclusive)
      Returns:
      a new array sized to cs.length() items, or sized to 0 if cs is null
    • readArrayDense

      static char[] readArrayDense(char[] 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.
      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 BASE90 chars (between '%' and '~', both inclusive)
      offset - the first position to read BASE90 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 can vary significantly in length, and should use Base.BASE10 digits, which should be 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 BASE10 chars
      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 can vary significantly in length, and should use Base.BASE10 digits, which should be 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 BASE10 chars
      delimiter - the String separating every item in str
      offset - the first position to read BASE10 chars from in str
      length - how many chars to read; -1 is treated as maximum length