users@jsr311.java.net

Re: Case insensitive map

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 02 Sep 2008 09:26:12 -0400

On Sep 2, 2008, at 3:52 AM, Paul Sandoz wrote:
>
> It is possible to support case-insensitive look up, i.e. not
> mandating that a developer convert to upper or lower case, and
> equality to other type equivalent maps if we mandate, as you point
> out, that keys are always lower cased. Thus a developer using
> another type equivalent map is required to put keys in lower case.
>
Would it be sufficient to say in the javadoc that, for the purposes of
identity, the returned map uses the lowercased versions of the keys.
Any key set or entry set returned by the map can also be case
insensitive wrt to keys without forcing the actual values to lowercase.

Marc.

>
> On Sep 1, 2008, at 12:11 PM, Reto Bachmann-Gmür wrote:
>
>> 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
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.