Class HeaderFields

  • All Implemented Interfaces:
    java.util.Map<java.lang.String,​java.util.List<java.lang.String>>

    public class HeaderFields
    extends java.lang.Object
    implements java.util.Map<java.lang.String,​java.util.List<java.lang.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
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      HeaderFields()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String key, java.lang.String value)
      Adds the given value to the entry of the specified key.
      void add​(java.lang.String key, java.util.List<java.lang.String> values)
      Adds the given values to the entry of the specified key.
      void addAll​(java.util.Map<? extends java.lang.String,​? extends java.util.List<java.lang.String>> values)
      Adds all the entries of the given map to this.
      void clear()  
      boolean contains​(java.lang.String key, java.lang.String value)
      Convenience method for checking whether or not a named header contains a specific value.
      boolean containsIgnoreCase​(java.lang.String key, java.lang.String value)
      Convenience method for checking whether or not a named header contains a specific value, regardless of case.
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.List<java.util.Map.Entry<java.lang.String,​java.lang.String>> entries()
      Returns an unmodifiable list of all key-value pairs of this.
      java.util.Set<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> entrySet()  
      boolean equals​(java.lang.Object obj)  
      java.util.List<java.lang.String> get​(java.lang.Object key)  
      java.lang.String getFirst​(java.lang.String key)
      Convenience method for retrieving the first value of a named header field.
      int hashCode()  
      boolean isEmpty()  
      boolean isTrue​(java.lang.String key)
      Convenience method for checking whether or not a named header field is true.
      java.util.Set<java.lang.String> keySet()  
      java.util.List<java.lang.String> put​(java.lang.String key, java.lang.String value)
      Convenience method to call put(String, List) with a singleton list that contains the specified value.
      java.util.List<java.lang.String> put​(java.lang.String key, java.util.List<java.lang.String> value)  
      void putAll​(java.util.Map<? extends java.lang.String,​? extends java.util.List<java.lang.String>> values)  
      java.util.List<java.lang.String> remove​(java.lang.Object key)  
      boolean remove​(java.lang.String key, java.lang.String value)
      Removes the given value from the entry of the specified key.
      int size()  
      java.lang.String toString()  
      java.util.Collection<java.util.List<java.lang.String>> values()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • HeaderFields

        public HeaderFields()
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • contains

        public boolean contains​(java.lang.String key,
                                java.lang.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​(java.lang.String key,
                                          java.lang.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​(java.lang.String key,
                        java.lang.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​(java.lang.String key,
                        java.util.List<java.lang.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​(java.util.Map<? extends java.lang.String,​? extends java.util.List<java.lang.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 java.util.List<java.lang.String> put​(java.lang.String key,
                                                    java.lang.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.
      • put

        public java.util.List<java.lang.String> put​(java.lang.String key,
                                                    java.util.List<java.lang.String> value)
        Specified by:
        put in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.String,​? extends java.util.List<java.lang.String>> values)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • remove

        public java.util.List<java.lang.String> remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • remove

        public boolean remove​(java.lang.String key,
                              java.lang.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.
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • get

        public java.util.List<java.lang.String> get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • getFirst

        public java.lang.String getFirst​(java.lang.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​(java.lang.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.
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • values

        public java.util.Collection<java.util.List<java.lang.String>> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • entries

        public java.util.List<java.util.Map.Entry<java.lang.String,​java.lang.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.
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,​java.util.List<java.lang.String>>
        Overrides:
        hashCode in class java.lang.Object