Interface PrimitiveCollection.OfShort

All Superinterfaces:
PrimitiveCollection<Short>
All Known Implementing Classes:
ShortBag, ShortDeque, ShortList
Enclosing interface:
PrimitiveCollection<T>

public static interface PrimitiveCollection.OfShort extends PrimitiveCollection<Short>
A PrimitiveCollection with unboxed short items.
  • Method Details

    • add

      boolean add(short item)
    • remove

      boolean remove(short item)
    • contains

      boolean contains(short item)
    • addAll

      default boolean addAll(PrimitiveCollection.OfShort other)
    • addAll

      default boolean addAll(ShortIterator it)
    • addAll

      default boolean addAll(short[] array)
    • addAll

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

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

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

      default boolean removeAll(short[] array)
    • removeAll

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

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

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

      default boolean removeEach(short[] array)
    • removeEach

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

      default boolean containsAll(PrimitiveCollection.OfShort other)
    • containsAll

      default boolean containsAll(ShortIterator it)
    • containsAll

      default boolean containsAll(short[] array)
    • containsAll

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

      default boolean containsAny(PrimitiveCollection.OfShort other)
    • containsAny

      default boolean containsAny(ShortIterator it)
    • containsAny

      default boolean containsAny(short[] array)
    • containsAny

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

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

      default boolean retainAll(short[] array)
    • retainAll

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

      ShortIterator iterator()
      Specified by:
      iterator in interface PrimitiveCollection<Short>
    • toArray

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

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

      default void forEach(com.github.tommyettinger.function.ShortConsumer action)
      Performs the given action for each element of the PrimitiveCollection.OfShort 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 short 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, ShortAppender appender)
      Makes a String from the contents of this PrimitiveCollection, but uses the given ShortAppender to convert each item to a customizable representation and append them to a StringBuilder. To use the default String representation, you can use Base.BASE10::appendSigned as an appender, or better yet, use ShortAppender.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 short, 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, ShortAppender appender)
      Appends to an Appendable CharSequence from the contents of this PrimitiveCollection, but uses the given ShortAppender to convert each item to a customizable representation and append them to sb. To use the default String representation, you can use Base.BASE10::appendSigned as an appender, or better yet, use ShortAppender.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 short, 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 three Base.BASE90 digits per item, with no surrounding brackets.
      Returns:
      a String made of Base.BASE90 digits
    • toDenseString

      default String toDenseString(boolean brackets)
      Returns a String representing this PrimitiveCollection with three Base.BASE90 digits per item, 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 Base.BASE90 digits, 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 three Base.BASE90 digits per item, 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 short readDense(CharSequence cs, int position)
      Reads in exactly three BASE90 chars from the given position in the given CharSequence, such as a String or StringBuilder, and returns the short they represent. This does no validation of the CharSequence or position; ensuring that position is non-negative and that position + 2 is less than cs.length() is the caller's responsibility.
      Parameters:
      cs - a CharSequence containing BASE90 chars (between '%' and '~', both inclusive)
      position - the first position to read exactly three chars from in cs
      Returns:
      the short the three BASE90 chars represent
    • 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 three characters long and uses the Base.BASE90 digits, which are not meant to be human-readable. No surrounding brackets should be present in cs (they will be treated as digits).
      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 three characters long and uses the Base.BASE90 digits, which are not meant to be human-readable. Any brackets inside the given range of characters will be interpreted as BASE90 digits, 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 BASE90 chars (between '%' and '~', both inclusive)
      offset - the first position to read BASE90 chars from in cs
      length - how many chars to read; should be a multiple of three; -1 is treated as maximum length
    • readArrayDense

      static short[] 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 short array sized to cs.length() / 3. Each item is exactly three characters long and uses the Base.BASE90 digits, which are not meant to be human-readable.
      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() / 3 items, or sized to 0 if cs is null
    • readArrayDense

      static short[] readArrayDense(short[] 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 three characters long and uses the Base.BASE90 digits, which are not meant to be human-readable.
      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; should be a multiple of three; -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