Interface SetBuilder<A>

  • Type Parameters:
    A - the element type
    All Known Subinterfaces:
    NonEmptySetBuilder<A>

    public interface SetBuilder<A>
    A builder for ImmutableSets.

    A SetBuilder is immutable and all add operations return a new SetBuilder. To construct the ImmutableSet, call build().

    It is safe to continue adding to a SetBuilder even after build is called. It is also safe to "fork" a SetBuilder, but be aware that internal copies may be made when doing so.

    • Method Detail

      • add

        NonEmptySetBuilder<A> add​(A element)
        Adds an element to this SetBuilder.
        Parameters:
        element - the element to add
        Returns:
        a new NonEmptySetBuilder with the element added
      • addAll

        SetBuilder<A> addAll​(java.util.Collection<A> elements)
        Adds all elements in a java.util.Collection to this SetBuilder.
        Parameters:
        elements - the collection to add
        Returns:
        a new SetBuilder with the elements added
      • addAll

        SetBuilder<A> addAll​(software.kes.enhancediterables.FiniteIterable<A> elements)
        Adds all elements in a FiniteIterable to this SetBuilder.

        Since Sets are FiniteIterables, this method accepts any Set.

        Parameters:
        elements - the FiniteIterable to add
        Returns:
        a new SetBuilder with the elements added
      • addAll

        NonEmptySetBuilder<A> addAll​(software.kes.enhancediterables.NonEmptyFiniteIterable<A> elements)
        Adds all elements in a NonEmptyFiniteIterable to this SetBuilder.

        Since NonEmptyVectors are NonEmptyFiniteIterables, this method accepts any NonEmptyVector.

        Parameters:
        elements - the NonEmptyFiniteIterable to add
        Returns:
        a new NonEmptySetBuilder with the elements added
      • build

        ImmutableSet<A> build()
        Builds a new ImmutableSet.

        It is safe to call this at any point, and it safe to continue adding elements after calling this.

        Returns:
        an ImmutableSet.
      • builder

        static <A> SetBuilder<A> builder()
        Creates a new SetBuilder.
        Type Parameters:
        A - the element type
        Returns:
        an empty SetBuilder
      • builder

        static <A> SetBuilder<A> builder​(int initialCapacity)
        Creates a new SetBuilder with an initial capacity hint.
        Type Parameters:
        A - the element type
        Parameters:
        initialCapacity - an initial capacity hint. Must be >= 0.
        Returns:
        an empty SetBuilder