Class HashParameters

java.lang.Object
io.helidon.common.http.HashParameters
All Implemented Interfaces:
Parameters, Iterable<Map.Entry<String,List<String>>>
Direct Known Subclasses:
HashHeaders

public class HashParameters extends Object implements Parameters
A Map-based Parameters implementation with keys and immutable List of values that needs to be copied on each write.

By default, this implementation uses case-sensitive keys but a subclass can override the map factory methods emptyMapForReads() and emptyMapForUpdates() to control the specific type of map used.

  • Constructor Details

    • HashParameters

      protected HashParameters()
      Creates a new instance.
    • HashParameters

      protected HashParameters(Map<String,List<String>> initialContent)
      Creates a new instance from provided data. Initial data are copied.
      Parameters:
      initialContent - initial content.
    • HashParameters

      protected HashParameters(Iterable<Map.Entry<String,List<String>>> initialContent)
      Creates a new instance from provided data, typically either another Parameters instance or a map's entry set. Initial data are copied.
      Parameters:
      initialContent - initial content
    • HashParameters

      protected HashParameters(Parameters initialContent)
      Creates a new instance from provided data. Initial data is copied.
      Parameters:
      initialContent - initial content.
  • Method Details

    • create

      public static HashParameters create()
      Creates a new empty instance HashParameters.
      Returns:
      a new instance of HashParameters.
    • create

      public static HashParameters create(Map<String,List<String>> initialContent)
      Creates a new instance of HashParameters from a single provided Map. Initial data is copied.
      Parameters:
      initialContent - initial content.
      Returns:
      a new instance of HashParameters initialized with the given content.
    • create

      public static HashParameters create(Parameters initialContent)
      Creates a new instance HashParameters from provided data. Initial data is copied.
      Parameters:
      initialContent - initial content.
      Returns:
      a new instance of HashParameters initialized with the given content.
    • create

      public static HashParameters create(Iterable<Map.Entry<String,List<String>>> initialContent)
      Creates a new instance of HashParameters from a single provided Parameter or Map. Initial data is copied.
      Parameters:
      initialContent - initial content.
      Returns:
      a new instance of HashParameters initialized with the given content.
    • concat

      public static HashParameters concat(Parameters... parameters)
      Creates new instance of HashParameters as a concatenation of provided parameters. Values for keys found across the provided parameters are "concatenated" into a List entry for their respective key in the created HashParameters instance.
      Parameters:
      parameters - parameters to concatenate.
      Returns:
      a new instance of HashParameters that represents the concatenation of the provided parameters.
    • concat

      public static HashParameters concat(Iterable<Parameters> parameters)
      Creates new instance of HashParameters as a concatenation of provided parameters. Values for keys found across the provided parameters are "concatenated" into a List entry for their respective key in the created HashParameters instance.
      Parameters:
      parameters - parameters to concatenate.
      Returns:
      a new instance of HashParameters that represents the concatenation of the provided parameters.
    • iterator

      public Iterator<Map.Entry<String,List<String>>> iterator()
      Description copied from interface: Parameters

      Implementations should override this default with a more efficient implementation.

      Specified by:
      iterator in interface Iterable<Map.Entry<String,List<String>>>
      Specified by:
      iterator in interface Parameters
      Returns:
      Iterator over the entries in the data
    • concat

      protected static <T extends HashParameters> T concat(Iterable<? extends Iterable<Map.Entry<String,List<String>>>> contentSources, Supplier<T> emptyFactory, Function<Iterable<Map.Entry<String,List<String>>>,T> singletonFactory)
      Creates a new instance of the correct HashParameters subclass as a concatenation of the provided sources. Values for keys found across the sources are "concatenated" into a List entry for their respective key in the created HashParameters (or subclass) instance.
      Type Parameters:
      T - type of the named value lists implementation to create
      Parameters:
      contentSources - Iterable over the sources whose contents are to be combined
      emptyFactory - factory for an empty named value lists implementation
      singletonFactory - factory for a named value lists implementation preloaded with one source's data
      Returns:
      new named value lists implementation containing the combined data from the sources
    • emptyMapForUpdates

      protected ConcurrentMap<String,List<String>> emptyMapForUpdates()
      Returns an empty Map suitable for case-sensitivity or case-insensitivity and for read-write access.

      Typical implementations should return a concurrent implementation.

      Returns:
      empty Map implementation with correct case-sensitivity behavior and suitable for read-write access
    • emptyMapForReads

      protected Map<String,List<String>> emptyMapForReads()
      Returns an empty Map suitable for case-sensitivity or case-insensitivity and optimized for read-only access.

      Typical implementations should not return a concurrent implementation.

      Returns:
      empty Map implementation with correct case-sensitivity behavior and optimized for read-only access
    • first

      public Optional<String> first(String name)
      Description copied from interface: Parameters
      Returns an Optional containing the first value of the given parameter (and possibly multi-valued) parameter. If the parameter is not present, then the returned Optional is empty.
      Specified by:
      first in interface Parameters
      Parameters:
      name - the parameter name
      Returns:
      an Optional<V> for the first named value
    • all

      public List<String> all(String name)
      Description copied from interface: Parameters
      Returns an unmodifiable List of all of the values of the given named parameter. Always returns a List, which may be empty if the parameter is not present.
      Specified by:
      all in interface Parameters
      Parameters:
      name - the parameter name
      Returns:
      a List of values with zero or greater size
    • put

      public List<String> put(String key, String... values)
      Description copied from interface: Parameters
      Associates specified values with the specified key (optional operation). If parameters previously contained a mapping for the key, the old values fully replaced.
      Specified by:
      put in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be associated with the specified key
      Returns:
      the previous values associated with key, or empty List if there was no mapping for key.
    • put

      public List<String> put(String key, Iterable<String> values)
      Description copied from interface: Parameters
      Associates specified values with the specified key (optional operation). If parameters previously contained a mapping for the key, the old values fully replaced.
      Specified by:
      put in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be associated with the specified key. If null then association will be removed.
      Returns:
      the previous values associated with key, or empty List if there was no mapping for key.
    • putIfAbsent

      public List<String> putIfAbsent(String key, String... values)
      Description copied from interface: Parameters
      If the specified key is not already associated with a value associates it with the given value and returns empty List, else returns the current value (optional operation).
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be associated with the specified key
      Returns:
      the previous values associated with key, or empty List if there was no mapping for key.
    • putIfAbsent

      public List<String> putIfAbsent(String key, Iterable<String> values)
      Description copied from interface: Parameters
      If the specified key is not already associated with a value associates it with the given value and returns empty List, else returns the current value (optional operation).
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be associated with the specified key
      Returns:
      the previous values associated with key, or empty List if there was no mapping for key.
    • computeIfAbsent

      public List<String> computeIfAbsent(String key, Function<String,Iterable<String>> values)
      Description copied from interface: Parameters
      If the specified key is not already associated with a value computes new association using the given function and returns empty List, else returns the current value (optional operation).
      Specified by:
      computeIfAbsent in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be associated with the specified key
      Returns:
      the current (potentially computed) values associated with key, or empty List if function returns null
    • computeSingleIfAbsent

      public List<String> computeSingleIfAbsent(String key, Function<String,String> value)
      Description copied from interface: Parameters
      If the specified key is not already associated with a value computes new association using the given function and returns empty List, else returns the current value (optional operation).
      Specified by:
      computeSingleIfAbsent in interface Parameters
      Parameters:
      key - a key with which the specified value is to be associated
      value - a single value to be associated with the specified key
      Returns:
      the current (potentially computed) values associated with key, or empty List if function returns null
    • putAll

      public HashParameters putAll(Parameters parameters)
      Description copied from interface: Parameters
      Copies all of the mappings from the specified parameters to this instance replacing values of existing associations (optional operation).
      Specified by:
      putAll in interface Parameters
      Parameters:
      parameters - to copy.
      Returns:
      this instance of Parameters
    • add

      public HashParameters add(String key, String... values)
      Description copied from interface: Parameters
      Adds specified values to association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.
      Specified by:
      add in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be add to association with the specified key
      Returns:
      this instance of Parameters
    • add

      public HashParameters add(String key, Iterable<String> values)
      Description copied from interface: Parameters
      Adds specified values to association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.
      Specified by:
      add in interface Parameters
      Parameters:
      key - key with which the specified value is to be associated
      values - value to be add to association with the specified key. If null then noting will be add.
      Returns:
      this instance of Parameters
    • addAll

      public HashParameters addAll(Parameters parameters)
      Description copied from interface: Parameters
      Copies all of the mappings from the specified parameters to this instance adding values to existing associations (optional operation).
      Specified by:
      addAll in interface Parameters
      Parameters:
      parameters - to copy.
      Returns:
      this instance of Parameters
    • remove

      public List<String> remove(String key)
      Description copied from interface: Parameters
      Removes the mapping for a key if it is present (optional operation).
      Specified by:
      remove in interface Parameters
      Parameters:
      key - key whose mapping is to be removed.
      Returns:
      the previous value associated with key, or empty List.
    • toMap

      public Map<String,List<String>> toMap()
      Description copied from interface: Parameters
      Returns a copy of parameters as a Map. This interface should only be used when it is required to iterate over the entire set of parameters.
      Specified by:
      toMap in interface Parameters
      Returns:
      the Map
    • toString

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

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

      public int hashCode()
      Overrides:
      hashCode in class Object