Interface PersistentSet.Builder<E extends @Nullable Object>

All Superinterfaces:
Collection<E>, Iterable<E>, PersistentCollection.Builder<E>, Set<E>
Enclosing interface:
PersistentSet<E extends @Nullable Object>

public static interface PersistentSet.Builder<E extends @Nullable Object> extends Set<E>, PersistentCollection.Builder<E>

A generic builder of the persistent set. Builder exposes its modification operations through the MutableSet interface.

Builders are reusable, that is build method can be called multiple times with modifications between these calls. However, modifications applied do not affect previously built persistent set instances.

Builder is backed by the same underlying data structure as the persistent set it was created from. Thus, builder and build methods take constant time consisting of passing the backing storage to the new builder and persistent set instances, respectively.

The builder tracks which nodes in the structure are shared with the persistent set, and which are owned by it exclusively. It owns the nodes it copied during modification operations and avoids copying them on subsequent modifications.

When build is called the builder forgets about all owned nodes it had created.

  • Method Details

    • build

      PersistentSet<E> build()
      Description copied from interface: PersistentCollection.Builder

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

      This method can be called multiple times.

      If operations applied on this builder have caused no modifications:

      • on the first call it returns the same persistent collection instance this builder was obtained from.
      • on subsequent calls it returns the same previously returned persistent collection instance.
      Specified by:
      build in interface PersistentCollection.Builder<E extends @Nullable Object>