Package net.jadler

Class KeyValues


  • public class KeyValues
    extends Object

    This class represents a key-value data structure with following features:

    • multiple values for one key
    • key case insensitivity
    • immutability

    This structure is used in Jadler for modeling request/response headers and request parameters.

    Please note this class is immutable and therefore thread safe. All addition operations (add(java.lang.String, java.lang.String), addAll(net.jadler.KeyValues) create new instances rather than modifying the instance.

    See Also:
    Request, StubResponse
    • Field Detail

      • EMPTY

        public static final KeyValues EMPTY
        An empty instance.
    • Constructor Detail

      • KeyValues

        public KeyValues()
        Creates new empty instance.
    • Method Detail

      • add

        public KeyValues add​(String key,
                             String value)
        Adds new key-value pair. Supports multi-values for one key (if there has already been added some value with this key, additional value is added instead of rewriting). Please note this method creates new instance containing all existing values plus the new one rather than modifying this instance.
        Parameters:
        key - key (cannot be empty)
        value - value (cannot be null, however can be empty for valueless headers)
        Returns:
        an exact copy of this instance containing all existing values plus the new one
      • addAll

        public KeyValues addAll​(KeyValues keyValues)
        Adds all values from the given instance. Supports multi-values for one key (if there has already been added some value with this key, additional value is added instead of rewriting). Please note this method creates new instance containing all existing values plus the new ones rather than modifying this instance.
        Parameters:
        keyValues - values to be added no(cannot be null)
        Returns:
        an exact copy of this instance containing all existing values plus the new ones
      • getValue

        public String getValue​(String key)
        Returns the first value for the given key
        Parameters:
        key - key (case insensitive)
        Returns:
        single (first) value for the given key or null, if there is no such a key in this instance
      • getValues

        public List<String> getValues​(String key)
        Returns all values for the given key
        Parameters:
        key - key (case insensitive)
        Returns:
        all values of the given header or null, if there is no such a key in this instance
      • getKeys

        public Set<String> getKeys()
        Returns:
        all keys (lower-cased) from this instance (never returns null)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object