Class Fields

java.lang.Object
org.eclipse.jetty.util.Fields
All Implemented Interfaces:
Iterable<Fields.Field>

public class Fields extends Object implements Iterable<Fields.Field>

A container for name/value pairs, known as fields.

A Fields.Field is immutable and is composed of a name string that can be case-sensitive or case-insensitive (by specifying the option at the constructor) and of a case-sensitive set of value strings.

The implementation of this class is not thread safe.

  • Field Details

    • EMPTY

      public static final Fields EMPTY
  • Constructor Details

    • Fields

      public Fields()

      Creates an empty, modifiable, case insensitive Fields instance.

    • Fields

      public Fields(boolean caseSensitive)

      Creates an empty, modifiable, case insensitive Fields instance.

      **
      Parameters:
      caseSensitive - whether this Fields instance must be case sensitive
    • Fields

      public Fields(MultiMap<String> params)
    • Fields

      public Fields(Map<String,Fields.Field> fields)
    • Fields

      public Fields(Fields fields)
  • Method Details

    • asImmutable

      public Fields asImmutable()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getNames

      public Set<String> getNames()
      Returns:
      a set of field names
    • stream

      public Stream<Fields.Field> stream()
    • get

      public Fields.Field get(String name)
      Parameters:
      name - the field name
      Returns:
      the Fields.Field with the given name, or null if no such field exists
    • getValue

      public String getValue(String name)
      Parameters:
      name - the field name
      Returns:
      the first value of the field with the given name, or null if no such field exists
    • getValues

      public List<String> getValues(String name)
      Parameters:
      name - the field name
      Returns:
      the values of the field with the given name, or null if no such field exists
    • getValuesOrEmpty

      public List<String> getValuesOrEmpty(String name)
      Parameters:
      name - the field name
      Returns:
      the values of the field with the given name, or empty list if no such field exists
    • put

      public void put(String name, String value)

      Inserts or replaces the given name/value pair as a single-valued Fields.Field.

      Parameters:
      name - the field name
      value - the field value
    • put

      public void put(Fields.Field field)

      Inserts or replaces the given Fields.Field, mapped to the field's name

      Parameters:
      field - the field to put
    • add

      public void add(String name, String value)

      Adds the given value to a field with the given name, creating a Fields.Field is none exists for the given name.

      Parameters:
      name - the field name
      value - the field value to add
    • add

      public void add(String name, String... values)

      Adds the given value to a field with the given name, creating a Fields.Field is none exists for the given name.

      Parameters:
      name - the field name
      values - the field values to add
    • add

      public void add(Fields.Field field)

      Adds the given field, storing it if none exists for the given name, or adding all the values to the existing field with the given name.

      Parameters:
      field - the field to add
    • addAll

      public void addAll(Fields fields)
    • remove

      public Fields.Field remove(String name)

      Removes the Fields.Field with the given name.

      Parameters:
      name - the name of the field to remove
      Returns:
      the removed field, or null if no such field existed
    • clear

      public void clear()

      Empties this Fields instance from all fields.

      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns:
      whether this Fields instance is empty
    • getSize

      public int getSize()
      Get the number of fields.
      Returns:
      the number of fields
    • iterator

      public Iterator<Fields.Field> iterator()
      Specified by:
      iterator in interface Iterable<Fields.Field>
      Returns:
      an iterator over the Fields.Fields present in this instance
    • toStringArrayMap

      public Map<String,String[]> toStringArrayMap()
      Returns:
      the fields (name and values) of this instance copied into a Map
    • toMultiMap

      public MultiMap<String> toMultiMap()
      Returns:
      the fields (name and values) of this instance copied into a MultiMap<String>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • combine

      public static Fields combine(Fields a, Fields b)

      Combine two Fields

      Parameters:
      a - The base Fields or null
      b - The overlay Fields or null
      Returns:
      Fields, which may be empty, but never null.