cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r926142 - /cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java
Date Mon, 22 Mar 2010 15:38:30 GMT
Author: bluk
Date: Mon Mar 22 15:38:30 2010
New Revision: 926142

URL: http://svn.apache.org/viewvc?rev=926142&view=rev
Log:
Update MediaType for params/hashcode corrections

Modified:
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java

Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java?rev=926142&r1=926141&r2=926142&view=diff
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java (original)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/MediaType.java Mon
Mar 22 15:38:30 2010
@@ -20,7 +20,9 @@
 package javax.ws.rs.core;
 
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Map;
+import java.util.TreeMap;
 
 import javax.ws.rs.ext.RuntimeDelegate;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
@@ -122,7 +124,17 @@ public class MediaType {
         if (parameters == null) {
             this.params = Collections.emptyMap();
         } else {
-            this.params = Collections.unmodifiableMap(parameters);
+            // need to use a temporary map here since for some reason the ordering is important.
+            Map<String, String> temp = new TreeMap<String, String>(new Comparator<String>()
{
+                public int compare(String o1, String o2) {
+                    return o1.compareToIgnoreCase(o2);
+                }
+            });
+            // need to put in as all lower case keys for comparisons, hashcode, and output
+            for (String key : parameters.keySet()) {
+                temp.put(key.toLowerCase(), parameters.get(key));
+            }
+            this.params = Collections.unmodifiableMap(temp);
         }
     }
 
@@ -192,8 +204,12 @@ public class MediaType {
     @Override
     public int hashCode() {
         int result = 17;
-        result = 31 * result + getType().hashCode();
-        result = 31 * result + getSubtype().hashCode();
+        // be sure to lowercase for comparisions
+
+        // be careful about hash code. since not guaranteed that this is a final
+        // class, need to use methods. methods do not guarantee lowercase
+        result = 31 * result + getType().toLowerCase().hashCode();
+        result = 31 * result + getSubtype().toLowerCase().hashCode();
         result = 31 * result + getParameters().hashCode();
         return result;
     }



Mime
View raw message