dev@jsr311.java.net

Re: JSR311: hashCode and equals mismatch for MediaType

From: Bill Burke <bburke_at_redhat.com>
Date: Mon, 09 Mar 2009 11:50:16 -0400

Marc Hadley wrote:
> On Mar 6, 2009, at 7:54 PM, Bill Burke wrote:
>
>> equals does not take MediaType parameters into account, while hashCode
>> uses the parameters to create a map.
>>
>> 1) I think equals should compare parameters. IMO
>> text/plain;charset=ISO != text/plain;charset=UTF-8
>> 2) hashCode should use the same elements to create the hash as equals
>> whether or not you agree with #1
>>
> Perhaps you are looking at an older version of the code, here's the
> relevant line from equals:
>

K, got an old snapshot


>>
>> If you agree with #1, the "q" parameter should be extracted from the
>> parameter map of MediaType when it is created. When a "q" parameter
>> exists it should be stored as a specific attribute within MediaType.
>> i.e. float MediaType.getAcceptQualifier(). Since q value is never
>> extracted, this makes it very difficult to use MediaTypes created from
>> an Accept header and use as keys to a Map.
>>
> Are you suggesting to remove the q parameter from consideration in the
> equals and hashCode methods. I.e. a q-value wouldn't be part of the map
> returned from getParameters ?
>



Yes and also remove it altogether from the parameter map. Also have a
specific attribute on MediaType.

float getAcceptQualifier()


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com