Class ListBuilder<X>

  • Type Parameters:
    X - the type of elements in the list
    All Implemented Interfaces:
    Builder<List<X>>

    public final class ListBuilder<X>
    extends Object
    implements Builder<List<X>>
    The ListBuilder class allows to build a list.
    Author:
    pchretien
    • Constructor Detail

      • ListBuilder

        public ListBuilder()
    • Method Detail

      • add

        public ListBuilder<X> add​(X value)
        Adds a value in the list. The value CAN NOT be null.
        Parameters:
        value - Value not null
        Returns:
        this builder
      • addAll

        public ListBuilder<X> addAll​(Collection<? extends X> values)
        Adds a collection of values in the list. These values CAN NOT be null.
        Parameters:
        values - Values not null
        Returns:
        this builder
      • unmodifiable

        public ListBuilder<X> unmodifiable()
        Makes this list as unmodifiable.
        Returns:
        this builder
      • sort

        public ListBuilder<X> sort​(Comparator<? super X> comparator)
        Sorts the list with the provided comparator.
        Parameters:
        comparator - the comparator to use
        Returns:
        this builder
      • build

        public List<X> build()
        Specified by:
        build in interface Builder<X>
        Returns:
        the built object