Class HttpPartList

All Implemented Interfaces:
Serializable, Cloneable, Iterable<HttpPart>, Collection<HttpPart>, List<HttpPart>, RandomAccess
Direct Known Subclasses:
HttpPartList.Unmodifiable, HttpPartList.Void

public class HttpPartList extends ArrayList<HttpPart>
A mutable, ordered list of HttpPart instances.

Mirrors the semantics of PartList from juneau-rest-common-classic without the Apache HttpCore dependency. Part-name comparisons are case-sensitive by default (matching the classic default for parts; headers use case-insensitive comparisons).

Use PartList when you need an immutable list bound to an HTTP body (e.g. application/x-www-form-urlencoded); use HttpPartList when you need a mutable builder for default form data / query parameter lists.

See Also:
Since:
10.0.0
See Also:
  • Constructor Details

    • HttpPartList

      public HttpPartList()
      Constructor.
    • HttpPartList

      protected HttpPartList(HttpPartList copyFrom)
      Copy constructor.
      Parameters:
      copyFrom - The list to copy. Must not be null.
  • Method Details

    • create

      public static HttpPartList create()
      Creates a new empty HttpPartList.
      Returns:
      A new instance. Never null.
    • of

      public static HttpPartList of(HttpPart... parts)
      Creates a new HttpPartList initialized with the given parts.
      Parameters:
      parts - The parts to include. null entries are ignored.
      Returns:
      A new instance. Never null.
    • of

      public static HttpPartList of(List<HttpPart> parts)
      Creates a new HttpPartList initialized with the given parts.
      Parameters:
      parts - The parts to include. null entries are ignored.
      Returns:
      A new instance. Never null.
    • ofPairs

      public static HttpPartList ofPairs(String... pairs)
      Creates a new HttpPartList initialized with the given alternating name/value pairs.
      Parameters:
      pairs - Alternating name/value strings. Can be null (treated as empty). Length must be even.
      Returns:
      A new instance. Never null.
      Throws:
      IllegalArgumentException - If the number of arguments is odd.
    • caseInsensitive

      public HttpPartList caseInsensitive(boolean value)
      Sets whether part-name comparisons are case-insensitive. Defaults to false (case-sensitive).
      Parameters:
      value - New value.
      Returns:
      This object.
    • append

      public HttpPartList append(HttpPart value)
      Appends the given part.
      Parameters:
      value - The part to add. null is ignored.
      Returns:
      This object.
    • append

      public HttpPartList append(HttpPart... values)
      Appends the given parts in order.
      Parameters:
      values - The parts to add. null entries are ignored.
      Returns:
      This object.
    • append

      public HttpPartList append(List<HttpPart> values)
      Appends the given parts in order.
      Parameters:
      values - The parts to add. null entries are ignored.
      Returns:
      This object.
    • append

      public HttpPartList append(String name, String value)
      Appends a part constructed from the given name and string value.
      Parameters:
      name - The part name. Must not be null.
      value - The part value. Can be null to omit the part from the request.
      Returns:
      This object.
    • setDefault

      Sets the given part as a default. If a part with the same name already exists, this is a no-op (first-in-chain wins per name).
      Parameters:
      value - The part to set. null is ignored.
      Returns:
      This object.
    • setDefault

      public HttpPartList setDefault(HttpPart... values)
      Sets the given parts as defaults, in order. For each, if a part with the same name already exists, the entry is skipped (first-in-chain wins per name).
      Parameters:
      values - The parts to set. null entries are ignored.
      Returns:
      This object.
    • setDefault

      public HttpPartList setDefault(String name, String value)
      Sets a default part with the given name and value (first-in-chain wins per name).
      Parameters:
      name - The part name. Must not be null.
      value - The part value. Can be null to omit the part from the request.
      Returns:
      This object.
    • set

      public HttpPartList set(HttpPart value)
      Sets the given part, replacing any prior entry with the same name.
      Parameters:
      value - The part to set. null is ignored.
      Returns:
      This object.
    • set

      public HttpPartList set(HttpPart... values)
      Sets the given parts, each replacing any prior entry with the same name.
      Parameters:
      values - The parts to set. null entries are ignored.
      Returns:
      This object.
    • set

      public HttpPartList set(String name, String value)
      Sets a part with the given name and value, replacing any prior entry with the same name.
      Parameters:
      name - The part name. Must not be null.
      value - The part value. Can be null to omit the part from the request.
      Returns:
      This object.
    • removeAll

      public HttpPartList removeAll(String name)
      Removes all parts with the given name.
      Parameters:
      name - The part name. Must not be null.
      Returns:
      This object.
    • contains

      public boolean contains(String name)
      Returns true if a part with the given name is present.
      Parameters:
      name - The part name.
      Returns:
      true if present.
    • getFirst

      public HttpPart getFirst(String name)
      Returns the first part with the given name, or null if absent.
      Parameters:
      name - The part name.
      Returns:
      The first matching part, or null.
    • getLast

      public HttpPart getLast(String name)
      Returns the last part with the given name, or null if absent.
      Parameters:
      name - The part name.
      Returns:
      The last matching part, or null.
    • getAll

      public List<HttpPart> getAll(String name)
      Returns all parts with the given name in insertion order.
      Parameters:
      name - The part name.
      Returns:
      A new list of matching parts. Never null.
    • getAll

      public HttpPart[] getAll()
      Returns all parts in this list as a typed array.
      Returns:
      A new array. Never null.
    • forEach

      public HttpPartList forEach(String name, Consumer<HttpPart> action)
      Performs an action on each part whose name matches.
      Parameters:
      name - The part name.
      action - The action.
      Returns:
      This object.
    • copy

      public HttpPartList copy()
      Returns a copy of this list.
      Returns:
      A new copy. Never null.
    • unmodifiable

      Returns an unmodifiable snapshot of this list.

      Idempotency: if this list is already an HttpPartList.Unmodifiable snapshot, it is returned as-is.

      Returns:
      An unmodifiable snapshot of this list, or this list if it is already unmodifiable.
    • isUnmodifiable

      public boolean isUnmodifiable()
      Returns true if this list is an unmodifiable snapshot.
      Returns:
      true if this list is an UnmodifiableBean snapshot.
    • toPartArray

      public HttpPart[] toPartArray()
      Returns the parts in this list as a typed array.
      Returns:
      A new array. Never null.