commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1713181 - in /commons/proper/collections/branches/COLLECTIONS_3_2_X/src: changes/changes.xml java/org/apache/commons/collections/map/CaseInsensitiveMap.java test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
Date Sat, 07 Nov 2015 21:17:01 GMT
Author: tn
Date: Sat Nov  7 21:17:00 2015
New Revision: 1713181

URL: http://svn.apache.org/viewvc?rev=1713181&view=rev
Log:
Backport COLLECTIONS-294 to 3.2.2.

Modified:
    commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml
    commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/map/CaseInsensitiveMap.java
    commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java

Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml?rev=1713181&r1=1713180&r2=1713181&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml (original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml Sat Nov
 7 21:17:00 2015
@@ -29,6 +29,10 @@
     <action issue="COLLECTIONS-335" dev="jochen" type="fix" due-to="sebb">
       Fixed cache assignment for "TreeBidiMap#entrySet".
     </action>
+    <action issue="COLLECTIONS-294" dev="bayard" type="fix" due-to="Benjamin Bentmann">
+      "CaseInsensitiveMap" will now convert input strings to lower-case in a
+      locale-independent manner.
+    </action>
     <action issue="COLLECTIONS-266" dev="bayard" type="fix" due-to="Joerg Schaible">
       "MultiKey" will now be correctly serialized/de-serialized.
     </action>
@@ -71,10 +75,6 @@
     <action issue="COLLECTIONS-304" dev="bayard" type="fix" due-to="Rafał Figas,Bjorn
Townsend">
       "SetUniqueList#set(int, Object)" will now correctly enforce the uniqueness constraint.
     </action>
-    <action issue="COLLECTIONS-294" dev="bayard" type="fix" due-to="Benjamin Bentmann">
-      "CaseInsensitiveMap" will now convert input strings to lower-case in a
-      locale-independant manner.
-    </action>
     <action issue="COLLECTIONS-261" dev="bayard" type="fix" due-to="ori">
       "Flat3Map#remove(Object)" will now return the correct value mapped to the removed key
       if the size of the map is less or equal 3.

Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/map/CaseInsensitiveMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/map/CaseInsensitiveMap.java?rev=1713181&r1=1713180&r2=1713181&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/map/CaseInsensitiveMap.java
(original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/map/CaseInsensitiveMap.java
Sat Nov  7 21:17:00 2015
@@ -25,9 +25,9 @@ import java.util.Map;
 /**
  * A case-insensitive <code>Map</code>.
  * <p>
- * As entries are added to the map, keys are converted to all lowercase. A new 
- * key is compared to existing keys by comparing <code>newKey.toString().toLower()</code>
- * to the lowercase values in the current <code>KeySet.</code>
+ * Before keys are added to the map or compared to other existing keys, they are converted
+ * to all lowercase in a locale-independent fashion by using information from the Unicode
+ * data file.
  * <p>
  * Null keys are supported.  
  * <p>
@@ -111,14 +111,18 @@ public class CaseInsensitiveMap extends
      * Overrides convertKey() from {@link AbstractHashedMap} to convert keys to 
      * lower case.
      * <p>
-     * Returns null if key is null.
-     * 
+     * Returns {@link AbstractHashedMap#NULL} if key is null.
+     *
      * @param key  the key convert
      * @return the converted key
      */
     protected Object convertKey(Object key) {
         if (key != null) {
-            return key.toString().toLowerCase();
+            char[] chars = key.toString().toCharArray();
+            for (int i = chars.length - 1; i >= 0; i--) {
+                chars[i] = Character.toLowerCase(Character.toUpperCase(chars[i]));
+            }
+            return new String(chars);
         } else {
             return AbstractHashedMap.NULL;
         }

Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java?rev=1713181&r1=1713180&r2=1713181&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
(original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
Sat Nov  7 21:17:00 2015
@@ -17,6 +17,7 @@
 package org.apache.commons.collections.map;
 
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -108,7 +109,32 @@ public class TestCaseInsensitiveMap exte
         assertEquals(map.size(), cloned.size());
         assertSame(map.get("1"), cloned.get("1"));
     }
-    
+
+    // COLLECTIONS-294
+    public void testLocaleIndependence() {
+        Locale orig = Locale.getDefault();
+        Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
+        String[][] data = { 
+            { "i", "I" },
+            { "\u03C2", "\u03C3" },
+            { "\u03A3", "\u03C2" },
+            { "\u03A3", "\u03C3" },
+        };
+        try {
+            for (int i = 0; i < locales.length; i++) {
+                Locale.setDefault(locales[i]);
+                for (int j = 0; j < data.length; j++) {
+                    assertTrue("Test data corrupt: " + j, data[j][0].equalsIgnoreCase(data[j][1]));
+                    CaseInsensitiveMap map = new CaseInsensitiveMap();
+                    map.put(data[j][0], "value");
+                    assertEquals(Locale.getDefault() + ": " + j, "value", map.get(data[j][1]));
+                }
+            }
+        } finally {
+            Locale.setDefault(orig);
+        }
+    }
+
     /*
     public void testCreate() throws Exception {
         resetEmpty();



Mime
View raw message