Interface PersistentSet<E extends @Nullable Object>

Type Parameters:
E - the type of elements contained in the set. The persistent set is covariant on its element type.
All Superinterfaces:
ImmutableCollection<E>, ImmutableSet<E>, Iterable<E>, PersistentCollection<E>

public interface PersistentSet<E extends @Nullable Object> extends ImmutableSet<E>, PersistentCollection<E>

A generic persistent unordered collection of elements that does not support duplicate elements, and supports adding and removing elements.

Modification operations return new instances of the persistent set with the modification applied.

  • Method Details

    • of

      static <E extends @Nullable Object> PersistentSet<E> of()
      Returns an empty persistent set.
    • of

      @SafeVarargs static <E extends @Nullable Object> PersistentSet<E> of(E... elements)

      Returns a new persistent set with the given elements.

      Elements of the returned set are iterated in the order they were specified.

    • hashOf

      static <E extends @Nullable Object> PersistentSet<E> hashOf()
      Returns an empty persistent set.
    • hashOf

      @SafeVarargs static <E extends @Nullable Object> PersistentSet<E> hashOf(E... elements)

      Returns a new persistent set with the given elements.

      Order of the elements in the returned set is unspecified.

    • from

      static <T extends @Nullable Object> PersistentSet<T> from(Iterable<T> iterable)

      Returns a persistent set of all elements of the specified collection.

      If the specified collection is already a persistent set, returns it as is. If the specified collection is a persistent set builder, calls build on it and returns the result.

      Elements of the returned set are iterated in the same order as in the specified collection.

    • from

      static <T extends @Nullable Object> PersistentSet<T> from(T[] array)

      Returns a persistent set of all elements of the specified array.

      Elements of the returned set are iterated in the same order as in the specified array.

    • from

      static <T extends @Nullable Object> PersistentSet<T> from(Stream<? extends T> stream)

      Returns a persistent set of all elements of the specified sequence.

      Elements of the returned set are iterated in the same order as in the specified sequence.

    • from

      static PersistentSet<Character> from(CharSequence chars)

      Returns a persistent set of all characters.

      Elements of the returned set are iterated in the same order as in the specified char sequence.

    • hashFrom

      static <T extends @Nullable Object> PersistentSet<T> hashFrom(Iterable<T> iterable)

      Returns a persistent set containing all elements from the specified collection.

      If the specified collection is already a persistent hash set, returns it as is. If the specified collection is a persistent hash set builder, calls build on it and returns the result.

      Order of the elements in the returned set is unspecified.

    • hashFrom

      static <T extends @Nullable Object> PersistentSet<T> hashFrom(T[] array)

      Returns a persistent set of all elements of the specified array.

      Order of the elements in the returned set is unspecified.

    • hashFrom

      static <T extends @Nullable Object> PersistentSet<T> hashFrom(Stream<? extends T> stream)

      Returns a persistent set of all elements of the specified sequence.

      Order of the elements in the returned set is unspecified.

    • hashFrom

      static PersistentSet<Character> hashFrom(CharSequence chars)

      Returns a persistent set of all characters.

      Order of the elements in the returned set is unspecified.

    • add

      PersistentSet<E> add(E element)
      Returns the result of adding the specified element to this set.
      Specified by:
      add in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with the specified element added; or this instance if it already contains the element.
    • addAll

      PersistentSet<E> addAll(Collection<? extends E> elements)
      Returns the result of adding all elements of the specified elements collection to this set.
      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements of the specified elements collection added; or this instance if it already contains every element of the specified collection.
    • remove

      PersistentSet<E> remove(E element)
      Returns the result of removing the specified element from this set.
      Specified by:
      remove in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with the specified element removed; or this instance if there is no such element in this set.
    • removeAll

      PersistentSet<E> removeAll(Collection<? extends E> elements)
      Returns the result of removing all elements in this set that are also contained in the specified elements collection.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements in this set that are also contained in the specified elements collection removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      PersistentSet<E> removeAll(Predicate<? super E> predicate)
      Returns the result of removing all elements in this set that match the specified predicate.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements matching the specified predicate removed; or this instance if no elements match the predicate.
    • retainAll

      PersistentSet<E> retainAll(Collection<? extends E> elements)
      Returns all elements in this set that are also contained in the specified elements collection.
      Specified by:
      retainAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements in this set that are also contained in the specified elements collection; or this instance if no modifications were made in the result of this operation.
    • clear

      PersistentSet<E> clear()
      Returns an empty persistent set.
      Specified by:
      clear in interface PersistentCollection<E extends @Nullable Object>
    • builder

      Description copied from interface: PersistentCollection

      Returns a new builder with the same contents as this collection.

      The builder can be used to efficiently perform multiple modification operations.

      Specified by:
      builder in interface PersistentCollection<E extends @Nullable Object>
    • mutate

      default PersistentSet<E> mutate(Consumer<? super Set<E>> mutator)
    • addAll

      default PersistentSet<E> addAll(Iterable<? extends E> elements)
      Returns the result of adding all elements of the specified elements collection to this set.
      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements of the specified elements collection added; or this instance if it already contains every element of the specified collection.
    • addAll

      default PersistentSet<E> addAll(E[] elements)
      Returns the result of adding all elements of the specified elements array to this set.
      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements of the specified elements array added; or this instance if it already contains every element of the specified array.
    • addAll

      default PersistentSet<E> addAll(Stream<? extends E> elements)
      Returns the result of adding all elements of the specified elements sequence to this set.
      Specified by:
      addAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements of the specified elements sequence added; or this instance if it already contains every element of the specified sequence.
    • removeAll

      default PersistentSet<E> removeAll(Iterable<? extends E> elements)
      Returns the result of removing all elements in this set that are also contained in the specified elements collection.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements in this set that are also contained in the specified elements collection removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentSet<E> removeAll(E[] elements)
      Returns the result of removing all elements in this set that are also contained in the specified elements array.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements in this set that are also contained in the specified elements array removed; or this instance if no modifications were made in the result of this operation.
    • removeAll

      default PersistentSet<E> removeAll(Stream<? extends E> elements)
      Returns the result of removing all elements in this set that are also contained in the specified elements sequence.
      Specified by:
      removeAll in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements in this set that are also contained in the specified elements sequence removed; or this instance if no modifications were made in the result of this operation.
    • intersect

      default PersistentSet<E> intersect(Iterable<? extends E> elements)
      Returns all elements in this set that are also contained in the specified elements collection.
      Specified by:
      intersect in interface PersistentCollection<E extends @Nullable Object>
      Returns:
      a new persistent set with elements in this set that are also contained in the specified elements collection; or this instance if no modifications were made in the result of this operation.