users@jsr311.java.net

Case insensitive map

From: Reto Bachmann-Gmür <reto_at_gmuer.ch>
Date: Mon, 01 Sep 2008 12:11:03 +0200

HttpHeaders.getRequestHeaders has to return a
MultivaluedMap<java.lang.String,java.lang.String> that is
case-insensitive with regards to keys. I'm not sure how such a case
insensitive map is supposed to work exactly (e.g. what does keySet
return?) and I think that it might be quite hard to have a definition
compatible the the API for the java.util.Map (which is extended by
MultivaluedMap).

An issue is map identity. The javadoc for java.util.Map.equals says:
"Returns true if the given object is also a map and the two maps
represent the same mappings." as the mapping of keys with different
casing is the same I would think that two maps are equals is they differ
only by the casing of the keys, however the text more specifically says:
"More formally, two maps m1 and m2 represent the same mappings if
m1.entrySet().equals(m2.entrySet())." The latter condition is only met
if the EntryS contains the key with the same casing (or if the keyset is
expanded to contain possible casings of a key), but this is not defined
by the jax-rs spec.

I think jax-rs should not introduce a case-insensitive map but rather
either specify that all-lower (or upper) case strings are to be used as
keys or introduce a class like "CaseInsensitiveString" used as key in
the map.

Reto