Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What use is Java 6 interface MultivaluedMap?

What use is Java 6 interface MultivaluedMap?

like image 792
Malatesh Avatar asked Mar 11 '14 11:03

Malatesh


2 Answers

The interface does not belong to "Java", meaning that the interface is not a part of the core libraries. It is a part of the javax.ws.rs hierarchy which is part of the JAX-RS specification. It is used by frameworks implementing the specification such as Jersey. It is used whenever maps should refer to not only a single value but to any number of values. An example for the use would be for example the storage of a request header where you one might want to add several values per key. Or even no keys in some cases where it is easier to handle an empty list compared to a null value.

Take this HTTP-header for example:

Accept-Encoding: compress;q=0.5, gzip;q=1.0

You would model this by

MultivaluedMap<String, String> map = ...
map.add("Accept-Encoding", "compress;q=0.5");
map.add("Accept-Encoding", "gzip;q=1.0");

internally in Jersey. This type of multiple value storage is a common problem in Java that is addressed by other implementors of maps such as Guava.

This is basically what the javadoc says:

A map of key-values pairs. Each key can have zero or more values.

like image 164
Rafael Winterhalter Avatar answered Oct 03 '22 04:10

Rafael Winterhalter


Its a map of key-values pairs. Each key can have zero or multiple values

public interface MultivaluedMap<K,V> extends java.util.Map<K,java.util.List<V>>
like image 36
Arjit Avatar answered Oct 03 '22 02:10

Arjit