Class FList.Builder<E>

  • Type Parameters:
    E - the type of the elements
    Enclosing class:
    FList<E>

    public static class FList.Builder<E>
    extends Object
    Mutable builder for building functional lists. It internally uses a mutable linked list for collecting the elements. Then allows to create the immutable functional list with the collected elements.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private LinkedList<E> list
      The mutable linked list for collecting the elements.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Builder()
      Private constructor for creating an empty builder.
      private Builder​(E[] es)
      Private constructor for creating a builder with the provided elements already collected.
      private Builder​(Iterable<? extends E> es)
      Private constructor for creating a builder where the elements in the provided iterable get collected.
    • Field Detail

      • list

        private final LinkedList<E> list
        The mutable linked list for collecting the elements.
    • Constructor Detail

      • Builder

        private Builder()
        Private constructor for creating an empty builder.
      • Builder

        private Builder​(E[] es)
        Private constructor for creating a builder with the provided elements already collected.
        Parameters:
        es - the elements to collect
      • Builder

        private Builder​(Iterable<? extends E> es)
        Private constructor for creating a builder where the elements in the provided iterable get collected.
        Parameters:
        es - the elements to collect
    • Method Detail

      • of

        public static <E> FList.Builder<E> of​(Iterable<? extends E> es)
        Creates a builder with the provided elements already collected.
        Type Parameters:
        E - the element type
        Parameters:
        es - the elements to collect
        Returns:
        the builder with the elements collected
      • of

        public static <E> FList.Builder<E> of​(E... es)
        Creates a builder with the provided elements already collected.
        Type Parameters:
        E - the element type
        Parameters:
        es - the elements to collect
        Returns:
        the builder with the elements collected
      • create

        public static <E> FList.Builder<E> create()
        Creates a new builder for collecting elements and building a functional list.
        Type Parameters:
        E - the element type
        Returns:
        a new builder
      • add

        public void add​(E e)
        Adds an element to the builder.
        Parameters:
        e - the element to add
      • addAll

        public void addAll​(Iterable<? extends E> es)
        Adds all elements in the iterable to this builder.
        Parameters:
        es - the elements to add
      • addAll

        public void addAll​(E[] es)
        Adds all elements in the array to this builder.
        Parameters:
        es - the elements to add
      • concat

        public FList<E> concat​(FList<E> fList)
        Adds all elements in the given list to this builder.
        Parameters:
        fList - the elements to add
        Returns:
        the concatenated list
      • build

        public FList<E> build()
        Creates a functional list with the elements collected in the builder.
        Returns:
        the functional list with the colleced elements