Interface IntCollection

All Known Implementing Classes:
IntDeque, IntList

public interface IntCollection
Analogous to Collection but for primitive ints, this is built around the primitive-specialized iterator IntIterator instead of the generic Iterator. This is not necessarily a modifiable collection.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(int item)
     
    default boolean
    addAll(int[] array)
     
    default boolean
    addAll(int[] array, int offset, int length)
     
    default boolean
     
    default boolean
    Compares this IntCollection with another IntCollection by checking their identity, their types (both must implement IntCollection), and their sizes, before checking if other contains each item in this IntCollection, in any order or quantity.
    void
     
    boolean
    contains(int item)
     
    default boolean
    containsAll(int[] array)
     
    default boolean
    containsAll(int[] array, int offset, int length)
     
    default boolean
     
    default boolean
    containsAny(int[] array)
     
    default boolean
    containsAny(int[] array, int offset, int length)
     
    default boolean
     
    boolean
    equals(Object other)
     
    default int
    Attempts to get the first item in this PrimitiveCollection, where "first" is only defined meaningfully if this type is ordered.
    default void
    Performs the given action for each element of the IntCollection until all elements have been processed or the action throws an exception.
    int
     
    default boolean
     
     
    default boolean
     
    boolean
    remove(int item)
     
    default boolean
    removeAll(int[] array)
     
    default boolean
    removeAll(int[] array, int offset, int length)
     
    default boolean
    Removes from this collection all occurrences of any elements contained in the specified other collection.
    default boolean
    removeEach(int[] array)
     
    default boolean
    removeEach(int[] array, int offset, int length)
     
    default boolean
    Removes from this collection element-wise occurrences of elements contained in the specified other collection.
    default boolean
    Removes all the elements of this collection that satisfy the given predicate.
    default boolean
     
    int
     
    default int[]
    Allocates a new int array with exactly size() items, fills it with the contents of this PrimitiveCollection, and returns it.
    default int[]
    toArray(int[] receiver)
    Fills the given array with the entire contents of this PrimitiveCollection, up to size() items, or if receiver is not large enough, then this allocates a new int array with size() items and returns that.
  • Method Details

    • size

      int size()
    • isEmpty

      default boolean isEmpty()
    • notEmpty

      default boolean notEmpty()
    • add

      boolean add(int item)
    • remove

      boolean remove(int item)
    • contains

      boolean contains(int item)
    • addAll

      default boolean addAll(IntCollection other)
    • addAll

      default boolean addAll(int[] array)
    • addAll

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

      default boolean removeAll(IntCollection other)
      Removes from this collection all occurrences of any elements contained in the specified other collection.
      Parameters:
      other - a primitive collection of int items to remove fully, such as an IntList or an IntSet
      Returns:
      true if this collection was modified.
    • removeAll

      default boolean removeAll(int[] array)
    • removeAll

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

      default boolean removeEach(IntCollection 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 int items to remove one-by-one, such as an IntList or an IntSet
      Returns:
      true if this collection was modified.
    • removeEach

      default boolean removeEach(int[] array)
    • removeEach

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

      default boolean containsAll(IntCollection other)
    • containsAll

      default boolean containsAll(int[] array)
    • containsAll

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

      default boolean containsAny(IntCollection other)
    • containsAny

      default boolean containsAny(int[] array)
    • containsAny

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

      default boolean removeIf(IntPredicate 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.
    • retainAll

      default boolean retainAll(IntCollection other)
    • iterator

      IntIterator iterator()
    • clear

      void clear()
    • hashCode

      int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      boolean equals(Object other)
      Overrides:
      equals in class Object
    • toArray

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

      default int[] toArray(int[] receiver)
      Fills the given array with the entire contents of this PrimitiveCollection, up to size() items, or if receiver is not large enough, then this allocates a new int array with size() items and returns that.
      Parameters:
      receiver - an int array that will be filled with the items from this, if possible
      Returns:
      receiver, if it was modified, or a new int array otherwise
    • forEach

      default void forEach(IntConsumer action)
      Performs the given action for each element of the IntCollection 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 int 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
    • areEqual

      default boolean areEqual(Object other)
      Compares this IntCollection with another IntCollection by checking their identity, their types (both must implement IntCollection), and their sizes, before checking if other contains each item in this IntCollection, 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 IntCollection, but that isn't necessary for other.
      Parameters:
      other - another Object that should be a IntCollection
      Returns:
      true if other is another IntCollection with exactly the same items, false otherwise