Package io.helidon.common.http
Interface Parameters
-
- All Known Subinterfaces:
FormParams
,Headers
,RequestHeaders
,ResponseHeaders
- All Known Implementing Classes:
ReadOnlyParameters
public interface Parameters
Parameters representskey : value
pairs wherekey
is aString
with potentially multiple values.This structure represents query parameters, headers and path parameters in e.g.
HttpRequest
.Interface focus on most convenient use cases in HTTP Request and Response processing, like
// Get and map with default .first("count").map(Integer::new).orElse(0); // Find max in multiple values .all("counts").stream().mapToInt(Integer::valueOf).max().orElse(0);
Mutable operations are defined in two forms:
put...
create or replace association.add...
create association or add values to existing association.
It is possible to use
toMap()
method to get immutable map view of data.Various static factory methods can be used to create common implementations.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
add(String key, Iterable<String> values)
Adds specified values tu association with the specified key (optional operation).void
add(String key, String... values)
Adds specified values tu association with the specified key (optional operation).void
addAll(Parameters parameters)
Copies all of the mappings from the specifiedparameters
to this instance adding values to existing associations (optional operation).List<String>
all(String name)
Returns an unmodifiable List of all of the values of the given named parameter.List<String>
computeIfAbsent(String key, Function<String,Iterable<String>> values)
If the specified key is not already associated with a value computes new association using the given function and returns emptyList
, else returns the current value (optional operation).List<String>
computeSingleIfAbsent(String key, Function<String,String> value)
If the specified key is not already associated with a value computes new association using the given function and returns emptyList
, else returns the current value (optional operation).Optional<String>
first(String name)
Returns anOptional
containing the first value of the given parameter (and possibly multi-valued) parameter.List<String>
put(String key, Iterable<String> values)
Associates specified values with the specified key (optional operation).List<String>
put(String key, String... values)
Associates specified values with the specified key (optional operation).void
putAll(Parameters parameters)
Copies all of the mappings from the specifiedparameters
to this instance replacing values of existing associations (optional operation).List<String>
putIfAbsent(String key, Iterable<String> values)
If the specified key is not already associated with a value associates it with the given value and returns emptyList
, else returns the current value (optional operation).List<String>
putIfAbsent(String key, String... values)
If the specified key is not already associated with a value associates it with the given value and returns emptyList
, else returns the current value (optional operation).List<String>
remove(String key)
Removes the mapping for a key if it is present (optional operation).Map<String,List<String>>
toMap()
Returns a copy of parameters as a Map.static Parameters
toUnmodifiableParameters(Parameters parameters)
Returns an unmodifiable view.
-
-
-
Method Detail
-
toUnmodifiableParameters
static Parameters toUnmodifiableParameters(Parameters parameters)
Returns an unmodifiable view.- Parameters:
parameters
- a parameters for unmodifiable view.- Returns:
- An unmodifiable view.
- Throws:
NullPointerException
- if parameterparameters
is null.
-
first
Optional<String> first(String name)
Returns anOptional
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.- Parameters:
name
- the parameter name- Returns:
- an
Optional<V>
for the first named value - Throws:
NullPointerException
- if name isnull
-
all
List<String> all(String name)
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.- Parameters:
name
- the parameter name- Returns:
- a
List
of values with zero or greater size - Throws:
NullPointerException
- if name isnull
-
put
List<String> put(String key, String... values)
Associates specified values with the specified key (optional operation). If parameters previously contained a mapping for the key, the old values fully replaced.- Parameters:
key
- key with which the specified value is to be associatedvalues
- 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. - Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
put
List<String> put(String key, Iterable<String> values)
Associates specified values with the specified key (optional operation). If parameters previously contained a mapping for the key, the old values fully replaced.- Parameters:
key
- key with which the specified value is to be associatedvalues
- value to be associated with the specified key. Ifnull
then association will be removed.- Returns:
- the previous values associated with key, or empty
List
if there was no mapping for key. - Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
putIfAbsent
List<String> putIfAbsent(String key, String... values)
If the specified key is not already associated with a value associates it with the given value and returns emptyList
, else returns the current value (optional operation).- Parameters:
key
- key with which the specified value is to be associatedvalues
- 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. - Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
putIfAbsent
List<String> putIfAbsent(String key, Iterable<String> values)
If the specified key is not already associated with a value associates it with the given value and returns emptyList
, else returns the current value (optional operation).- Parameters:
key
- key with which the specified value is to be associatedvalues
- 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. - Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
computeIfAbsent
List<String> computeIfAbsent(String key, Function<String,Iterable<String>> values)
If the specified key is not already associated with a value computes new association using the given function and returns emptyList
, else returns the current value (optional operation).- Parameters:
key
- key with which the specified value is to be associatedvalues
- value to be associated with the specified key- Returns:
- the current (potentially computed) values associated with key,
or empty
List
if function returnsnull
- Throws:
NullPointerException
- if the specified key is nullUnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters)IllegalStateException
- if the computation detectably attempts a recursive update to this map that would otherwise never completeRuntimeException
- or Error if the mappingFunction does so, in which case the mapping is left unestablished
-
computeSingleIfAbsent
List<String> computeSingleIfAbsent(String key, Function<String,String> value)
If the specified key is not already associated with a value computes new association using the given function and returns emptyList
, else returns the current value (optional operation).- Parameters:
key
- a key with which the specified value is to be associatedvalue
- a single value to be associated with the specified key- Returns:
- the current (potentially computed) values associated with key,
or empty
List
if function returnsnull
- Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).IllegalStateException
- if the computation detectably attempts a recursive update to this map that would otherwise never completeRuntimeException
- or Error if the mappingFunction does so, in which case the mapping is left unestablished
-
putAll
void putAll(Parameters parameters)
Copies all of the mappings from the specifiedparameters
to this instance replacing values of existing associations (optional operation).- Parameters:
parameters
- to copy.- Throws:
NullPointerException
- if the specifiedparameters
are null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
add
void add(String key, String... values)
Adds specified values tu association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.- Parameters:
key
- key with which the specified value is to be associatedvalues
- value to be add to association with the specified key- Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
add
void add(String key, Iterable<String> values)
Adds specified values tu association with the specified key (optional operation). If parameters doesn't contains mapping, new mapping is created.- Parameters:
key
- key with which the specified value is to be associatedvalues
- value to be add to association with the specified key. Ifnull
then noting will be add.- Throws:
NullPointerException
- if the specified key is null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
addAll
void addAll(Parameters parameters)
Copies all of the mappings from the specifiedparameters
to this instance adding values to existing associations (optional operation).- Parameters:
parameters
- to copy.- Throws:
NullPointerException
- if the specifiedparameters
are null.UnsupportedOperationException
- if put operation is not supported (unmodifiable Parameters).
-
remove
List<String> remove(String key)
Removes the mapping for a key if it is present (optional operation).- Parameters:
key
- key whose mapping is to be removed.- Returns:
- the previous value associated with key, or empty
List
.
-
-