Class ArrayBuilder<E>

java.lang.Object
org.apache.juneau.internal.ArrayBuilder<E>
Type Parameters:
E - The array element type.

public final class ArrayBuilder<E> extends Object
Builder for arrays.

Designed to create arrays without array copying. Initial capacity cannot be exceeded without throwing a ArrayIndexOutOfBoundsException.

See Also:
  • Constructor Details

    • ArrayBuilder

      public ArrayBuilder(Class<E> elementType)
      Constructor.
      Parameters:
      elementType - The element type.
  • Method Details

    • of

      public static <E> ArrayBuilder<E> of(Class<E> elementType)
      Static creator.
      Type Parameters:
      E - The element type.
      Parameters:
      elementType - The element type.
      Returns:
      A new builder object.
    • size

      public ArrayBuilder<E> size(int value)
      Sets the expected size for this array.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • filter

      public ArrayBuilder<E> filter(Predicate<E> value)
      The predicate to use to filter values added to this builder.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • add

      public ArrayBuilder<E> add(E t)
      Appends to this array if the specified value is not null.
      Parameters:
      t - The element to add.
      Returns:
      This object.
      Throws:
      ArrayIndexOutOfBoundsException - if size is exceeded.
    • orElse

      public E[] orElse(E[] def)
      Returns the populated array.
      Parameters:
      def - The default value if no values were added to this builder.
      Returns:
      A new array containing the added entries.