Class HeaderFields

  • All Implemented Interfaces:
    Map<String,​List<String>>

    public class HeaderFields
    extends Object
    implements Map<String,​List<String>>
    This is an encapsulation of the header fields that belong to either a Request or a Response. It is a multimap from String to String, with some additional methods for convenience. The keys of this map are compared by ignoring their case, so that get("foo") returns the same entry as get("FOO").
    Author:
    Simon Thoresen Hult
    • Constructor Detail

      • HeaderFields

        public HeaderFields()
    • Method Detail

      • contains

        public boolean contains​(String key,
                                String value)

        Convenience method for checking whether or not a named header contains a specific value. If the named header is not set, or if the given value is not contained within that header's value list, this method returns false.

        NOTE: This method is case-SENSITIVE.

        Parameters:
        key - The key whose values to search in.
        value - The values to search for.
        Returns:
        True if the given value was found in the named header.
        See Also:
        containsIgnoreCase(java.lang.String, java.lang.String)
      • containsIgnoreCase

        public boolean containsIgnoreCase​(String key,
                                          String value)

        Convenience method for checking whether or not a named header contains a specific value, regardless of case. If the named header is not set, or if the given value is not contained within that header's value list, this method returns false.

        NOTE: This method is case-INSENSITIVE.

        Parameters:
        key - The key whose values to search in.
        value - The values to search for, ignoring case.
        Returns:
        True if the given value was found in the named header.
        See Also:
        contains(java.lang.String, java.lang.String)
      • add

        public void add​(String key,
                        String value)

        Adds the given value to the entry of the specified key. If no entry exists for the given key, a new one is created containing only the given value.

        Parameters:
        key - The key with which the specified value is to be associated.
        value - The value to be added to the list associated with the specified key.
      • add

        public void add​(String key,
                        List<String> values)

        Adds the given values to the entry of the specified key. If no entry exists for the given key, a new one is created containing only the given values.

        Parameters:
        key - The key with which the specified value is to be associated.
        values - The values to be added to the list associated with the specified key.
      • addAll

        public void addAll​(Map<? extends String,​? extends List<String>> values)

        Adds all the entries of the given map to this. This is the same as calling add(String, List) for each entry in values.

        Parameters:
        values - The values to be added to this.
      • put

        public List<String> put​(String key,
                                String value)

        Convenience method to call put(String, List) with a singleton list that contains the specified value.

        Parameters:
        key - The key of the entry to put.
        value - The value to put.
        Returns:
        The previous value associated with key, or null if there was no mapping for key.
      • remove

        public boolean remove​(String key,
                              String value)

        Removes the given value from the entry of the specified key.

        Parameters:
        key - The key of the entry to remove from.
        value - The value to remove from the entry.
        Returns:
        True if the value was removed.
      • getFirst

        public String getFirst​(String key)

        Convenience method for retrieving the first value of a named header field. If the header is not set, or if the value list is empty, this method returns null.

        Parameters:
        key - The key whose first value to return.
        Returns:
        The first value of the named header, or null.
      • isTrue

        public boolean isTrue​(String key)

        Convenience method for checking whether or not a named header field is true. To satisfy this, the header field needs to have at least 1 entry, and Boolean.valueOf() of all its values must parse as true.

        Parameters:
        key - The key whose values to parse as a boolean.
        Returns:
        The boolean value of the named header.
      • entries

        public List<Map.Entry<String,​String>> entries()

        Returns an unmodifiable list of all key-value pairs of this. This provides a flattened view on the content of this map.

        Returns:
        The collection of entries.