Interface IntSet

  • All Superinterfaces:
    java.util.Collection<java.lang.Integer>, java.lang.Iterable<java.lang.Integer>, java.util.Set<java.lang.Integer>
    All Known Implementing Classes:
    ImmutableIntSet, RangeSet, RangeSet, SmallIntSet

    public interface IntSet
    extends java.util.Set<java.lang.Integer>
    A set that represents primitive ints. This interface describes methods that can be used without having to box an int. This set does not support negative numbers.
    Since:
    9.2
    Author:
    wburns
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      boolean add​(int i)
      Adds the given int to this set and returns true if it was set or false if it was already present
      boolean addAll​(IntSet set)
      Adds all ints from the provided set into this one
      boolean contains​(int i)
      Whether this set contains the given int
      boolean containsAll​(IntSet set)
      Whether this set contains all ints in the given IntSet
      default void forEach​(java.util.function.IntConsumer action)
      Performs the given action for each int of the IntSet until all elements have been processed or the action throws an exception.
      default java.util.Spliterator.OfInt intSpliterator()
      Creates a Spliterator.OfInt over the ints in this set.
      java.util.stream.IntStream intStream()
      A stream of ints representing the data in this set
      java.util.PrimitiveIterator.OfInt iterator()
      A primtive iterator that allows iteration over the int values.
      boolean remove​(int i)
      Removes, if present, the int from the set and returns if it was present or not
      boolean removeAll​(IntSet set)
      Removes all ints from this IntSet that are in the provided IntSet
      default boolean removeIf​(java.util.function.IntPredicate filter)
      Removes all of the ints of this set that satisfy the given predicate.
      boolean retainAll​(IntSet c)
      Modifies this set to remove all ints that are not present in the provided IntSet
      void set​(int i)
      Adds or sets the int without returning whether it was previously set
      default java.util.stream.Stream<java.lang.Integer> stream()  
      default int[] toIntArray()
      Returns an array containing all of the elements in this set.
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, spliterator, toArray, toArray
    • Method Detail

      • add

        boolean add​(int i)
        Adds the given int to this set and returns true if it was set or false if it was already present
        Parameters:
        i - the int value to add
        Returns:
        whether this int was already present
      • set

        void set​(int i)
        Adds or sets the int without returning whether it was previously set
        Parameters:
        i - the value to make sure is in the set
      • remove

        boolean remove​(int i)
        Removes, if present, the int from the set and returns if it was present or not
        Parameters:
        i - the int to remove
        Returns:
        whether the int was present in the set before it was removed
      • contains

        boolean contains​(int i)
        Whether this set contains the given int
        Parameters:
        i - the int to check
        Returns:
        if the set contains the int
      • addAll

        boolean addAll​(IntSet set)
        Adds all ints from the provided set into this one
        Parameters:
        set - the set of ints to add
        Returns:
        if this set has a new int in it
      • containsAll

        boolean containsAll​(IntSet set)
        Whether this set contains all ints in the given IntSet
        Parameters:
        set - the set to check if all are present
        Returns:
        if the set contains all the ints
      • removeAll

        boolean removeAll​(IntSet set)
        Removes all ints from this IntSet that are in the provided IntSet
        Parameters:
        set - the ints to remove from this IntSet
        Returns:
        if this set removed any ints
      • retainAll

        boolean retainAll​(IntSet c)
        Modifies this set to remove all ints that are not present in the provided IntSet
        Parameters:
        c - the ints this set should kep
        Returns:
        if this set removed any ints
      • iterator

        java.util.PrimitiveIterator.OfInt iterator()
        A primtive iterator that allows iteration over the int values. This iterator supports removal if the set is modifiable.
        Specified by:
        iterator in interface java.util.Collection<java.lang.Integer>
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Integer>
        Specified by:
        iterator in interface java.util.Set<java.lang.Integer>
        Returns:
        the iterator
      • intStream

        java.util.stream.IntStream intStream()
        A stream of ints representing the data in this set
        Returns:
        the stream
      • stream

        default java.util.stream.Stream<java.lang.Integer> stream()
        Specified by:
        stream in interface java.util.Collection<java.lang.Integer>
      • forEach

        default void forEach​(java.util.function.IntConsumer action)
        Performs the given action for each int of the IntSet until all elements have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.
        Parameters:
        action - The action to be performed for each element
        Throws:
        java.lang.NullPointerException - if the specified action is null
        Since:
        9.3
      • intSpliterator

        default java.util.Spliterator.OfInt intSpliterator()
        Creates a Spliterator.OfInt over the ints in this set.

        The Spliterator.OfInt reports Spliterator.DISTINCT. Implementations should document the reporting of additional characteristic values.

        Returns:
        a Spliterator.OfInt over the ints in this set
        Since:
        9.3
      • removeIf

        default boolean removeIf​(java.util.function.IntPredicate filter)
        Removes all of the ints of this set 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 ints to be removed
        Returns:
        true if any ints were removed
        Throws:
        java.lang.NullPointerException - if the specified filter is null
        java.lang.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.
        Since:
        9.3
      • toIntArray

        default int[] toIntArray()
        Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
        Returns:
        this int set as an array
        Since:
        9.3