Package org.jdrupes.httpcodec.types
Class DefaultMultiValueConverter<T extends Iterable<V>,V>
java.lang.Object
org.jdrupes.httpcodec.types.DefaultMultiValueConverter<T,V>
- Type Parameters:
T- the container for the valuesV- the type of the values
- All Implemented Interfaces:
Converter<T>,MultiValueConverter<T,V>
public class DefaultMultiValueConverter<T extends Iterable<V>,V>
extends Object
implements MultiValueConverter<T,V>
Used by by converters that convert header fields with a list of values.
Minimal restrictions are imposed on the type used as container for the
values. It must be Iterable to provide read access. A supplier
and a function for appending values provide the required write access.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMultiValueConverter(Supplier<T> containerSupplier, BiConsumer<T, V> valueAdder, Converter<V> valueConverter, String delimiters, boolean separateValues) Create a new converter.DefaultMultiValueConverter(Supplier<T> containerSupplier, Converter<V> itemConverter) Create a new converter for a container that implementsCollection, does not generate separate header fields and uses a comma as separator.DefaultMultiValueConverter(Supplier<T> containerSupplier, Converter<V> valueConverter, String delimiters) Create a new converter for a container that implementsCollectionand does not generate separate header fields. -
Method Summary
Modifier and TypeMethodDescriptionasFieldValue(T value) Returns the representation of this value in a header field.Returns the container supplierfromFieldValue(String text) Parses the given text and returns the parsed value.booleanReturn whether values should be converted to separate header fields inConverter.asFieldValue(Object).BiConsumer<T,V> Returns the value adderDeprecated.valueConverter(T value) Returns the value converter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jdrupes.httpcodec.types.MultiValueConverter
asHeaderField
-
Constructor Details
-
DefaultMultiValueConverter
public DefaultMultiValueConverter(Supplier<T> containerSupplier, BiConsumer<T, V> valueAdder, Converter<V> valueConverter, String delimiters, boolean separateValues) Create a new converter.- Parameters:
containerSupplier- a function that creates a new empty containervalueAdder- a function that adds a value to the sequencevalueConverter- the converter for the individual valuesdelimiters- the delimitersseparateValues- indicates that each value should be represented by a header field of its own in a message header
-
DefaultMultiValueConverter
public DefaultMultiValueConverter(Supplier<T> containerSupplier, Converter<V> valueConverter, String delimiters) Create a new converter for a container that implementsCollectionand does not generate separate header fields.- Parameters:
containerSupplier- a function that creates a new empty listvalueConverter- the converter for the itemsdelimiters- the delimiters
-
DefaultMultiValueConverter
Create a new converter for a container that implementsCollection, does not generate separate header fields and uses a comma as separator.- Parameters:
containerSupplier- a function that creates a new empty listitemConverter- the converter for the items- See Also:
-
-
Method Details
-
separateValues
Description copied from interface:MultiValueConverterReturn whether values should be converted to separate header fields inConverter.asFieldValue(Object).- Specified by:
separateValuesin interfaceMultiValueConverter<T extends Iterable<V>,V> - Returns:
- the value
-
containerSupplier
Description copied from interface:MultiValueConverterReturns the container supplier- Specified by:
containerSupplierin interfaceMultiValueConverter<T extends Iterable<V>,V> - Returns:
- the container supplier
-
valueAdder
Description copied from interface:MultiValueConverterReturns the value adder- Specified by:
valueAdderin interfaceMultiValueConverter<T extends Iterable<V>,V> - Returns:
- the value adder
-
valueConverter
Deprecated.Description copied from interface:MultiValueConverterReturns the value converter.- Specified by:
valueConverterin interfaceMultiValueConverter<T extends Iterable<V>,V> - Returns:
- the value converter
-
valueConverter
Description copied from interface:MultiValueConverterReturns the value converter.In most cases, the result will be independent of the container type or instance. However, passing it makes the selection more flexible.
- Specified by:
valueConverterin interfaceMultiValueConverter<T extends Iterable<V>,V> - Returns:
- the value converter
-
asFieldValue
Description copied from interface:ConverterReturns the representation of this value in a header field.- Specified by:
asFieldValuein interfaceConverter<T extends Iterable<V>>- Parameters:
value- the value to be converted- Returns:
- the representation
-
fromFieldValue
Description copied from interface:ConverterParses the given text and returns the parsed value.- Specified by:
fromFieldValuein interfaceConverter<T extends Iterable<V>>- Parameters:
text- the value from the header field- Returns:
- the parsed value
- Throws:
ParseException- if the value cannot be parsed
-