Interface ImmutableSet<E>

Type Parameters:
E - the element type
All Superinterfaces:
ImmutableCollection<E>, Iterable<E>, ReadOnlyCollection<E>, ReadOnlySet<E>
All Known Subinterfaces:
ImmutableNavigableSet<E>, ImmutableSequencedSet<E>, ImmutableSortedSet<E>
All Known Implementing Classes:
ChampSet, ChampVectorSet, ImmutableSetFacade, RedBlackSet

public interface ImmutableSet<E> extends ReadOnlySet<E>, ImmutableCollection<E>
An interface to an immutable set; the implementation guarantees that the state of the collection does not change.

An interface to an immutable set provides methods for creating a new immutable set with added or removed elements, without changing the original immutable set.

  • Method Details

    • empty

      <T> @NonNull ImmutableSet<T> empty()
      Returns an empty set instance that has the specified element type.
      Specified by:
      empty in interface ImmutableCollection<E>
      Type Parameters:
      T - the element type of the returned set
      Returns:
      an empty set of the specified element type.
    • add

      @NonNull ImmutableSet<E> add(E element)
      Returns a copy of this set that contains all elements of this set and also the specified element.
      Specified by:
      add in interface ImmutableCollection<E>
      Parameters:
      element - an element
      Returns:
      this set instance if it already contains the element, or a different set instance with the element added
    • addAll

      default @NonNull ImmutableSet<E> addAll(@NonNull Iterable<? extends E> c)
      Returns a copy of this set that contains all elements of this set and also all elements of the specified collection.
      Specified by:
      addAll in interface ImmutableCollection<E>
      Parameters:
      c - a collection to be added to this set
      Returns:
      this set instance if it already contains the elements, or a different set instance with the elements added
    • remove

      @NonNull ImmutableSet<E> remove(E element)
      Returns a copy of this set that contains all elements of this set except the specified element.
      Specified by:
      remove in interface ImmutableCollection<E>
      Parameters:
      element - an element
      Returns:
      this set instance if it already does not contain the element, or a different set instance with the element removed
    • removeAll

      default @NonNull ImmutableSet<E> removeAll(@NonNull Iterable<?> c)
      Returns a copy of this set that contains all elements of this set except the elements of the specified collection.
      Specified by:
      removeAll in interface ImmutableCollection<E>
      Parameters:
      c - a collection with elements to be removed from this set
      Returns:
      this set instance if it already does not contain the elements, or a different set instance with the elements removed
    • retainAll

      default @NonNull ImmutableSet<E> retainAll(@NonNull Iterable<?> c)
      Returns a copy of this set that contains only elements that are in this set and in the specified collection.
      Specified by:
      retainAll in interface ImmutableCollection<E>
      Parameters:
      c - a collection with elements to be retained in this set
      Returns:
      this set instance if it has not changed, or a different set instance with elements removed
    • toMutable

      @NonNull Set<E> toMutable()
      Returns a mutable copy of this set.
      Specified by:
      toMutable in interface ImmutableCollection<E>
      Returns:
      a mutable copy.