Interface VectorBuilder<A>

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

    public interface VectorBuilder<A>
    A builder for ImmutableVectors.

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

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

    • Method Detail

      • add

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

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

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

        Since Vectors are FiniteIterables, this method accepts any Vector.

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

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

        Since NonEmptyVectors are NonEmptyFiniteIterables, this method accepts any NonEmptyVector.

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

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

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

        Returns:
        an ImmutableVector.
      • builder

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

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