Class ListBuilder<E>

java.lang.Object
org.apache.juneau.internal.ListBuilder<E>
Type Parameters:
E - Element type.

public final class ListBuilder<E> extends Object
Builder for lists.
See Also:
  • Constructor Details

    • ListBuilder

      public ListBuilder(Class<E> elementType, Type... elementTypeArgs)
      Constructor.
      Parameters:
      elementType - The element type.
      elementTypeArgs - The element type generic arguments if there are any.
    • ListBuilder

      public ListBuilder(List<E> addTo)
      Constructor.
      Parameters:
      addTo - The list to add to.
  • Method Details

    • create

      public static <E> ListBuilder<E> create(Class<E> elementType, Type... elementTypeArgs)
      Static creator.
      Type Parameters:
      E - The element type.
      Parameters:
      elementType - The element type.
      elementTypeArgs - Optional element type arguments.
      Returns:
      A new builder.
    • build

      public List<E> build()
      Builds the list.
      Returns:
      A list conforming to the settings on this builder.
    • sparse

      public ListBuilder<E> sparse()
      When specified, the build() method will return null if the list is empty.

      Otherwise build() will never return null.

      Returns:
      This object.
    • unmodifiable

      When specified, build() will return an unmodifiable list.
      Returns:
      This object.
    • copy

      public ListBuilder<E> copy()
      Forces the existing list to be copied instead of appended to.
      Returns:
      This object.
    • sorted

      public ListBuilder<E> sorted()
      Sorts the contents of the list.
      Returns:
      This object.
    • sorted

      public ListBuilder<E> sorted(Comparator<E> comparator)
      Sorts the contents of the list using the specified comparator.
      Parameters:
      comparator - The comparator to use for sorting.
      Returns:
      This object.
    • addAll

      public ListBuilder<E> addAll(Collection<E> value)
      Appends the contents of the specified collection into this list.

      This is a no-op if the value is null.

      Parameters:
      value - The collection to add to this list.
      Returns:
      This object.
    • add

      public ListBuilder<E> add(E value)
      Adds a single value to this list.
      Parameters:
      value - The value to add to this list.
      Returns:
      This object.
    • add

      public ListBuilder<E> add(E... values)
      Adds multiple values to this list.
      Parameters:
      values - The values to add to this list.
      Returns:
      This object.
    • addJson

      public ListBuilder<E> addJson(String... values)
      Adds entries to this list via JSON array strings.
      Parameters:
      values - The JSON array strings to parse and add to this list.
      Returns:
      This object.
    • addAny

      public ListBuilder<E> addAny(Object... values)
      Adds arbitrary values to this list.

      Objects can be any of the following:

      • The same type or convertible to the element type of this list.
      • Collections or arrays of anything on this list.
      • JSON array strings parsed and convertible to the element type of this list.
      Parameters:
      values - The values to add.
      Returns:
      This object.
    • addIf

      public ListBuilder<E> addIf(boolean flag, E value)
      Appends a value to this list of the flag is true.
      Parameters:
      flag - The flag.
      value - The value.
      Returns:
      This object.