camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [5/6] camel git commit: CAMEL-8095: CaseInsensitiveMap for Camel headers should preserve original key cases in keySet
Date Sun, 30 Nov 2014 16:53:43 GMT
CAMEL-8095: CaseInsensitiveMap for Camel headers should preserve original key cases in keySet


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b2938951
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b2938951
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b2938951

Branch: refs/heads/master
Commit: b2938951562c220fc1328046acd80c38f6e162cb
Parents: 4309dd1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Nov 30 17:26:45 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Nov 30 17:26:45 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/util/CaseInsensitiveMap.java   | 35 ++++++++++++++++++++
 .../camel/util/CaseInsensitiveMapTest.java      | 15 +++++----
 .../language/jxpath/JXPathFilterHeaderTest.java |  2 +-
 3 files changed, 45 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b2938951/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java b/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
index b4852d7..0ed2245 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
@@ -16,8 +16,10 @@
  */
 package org.apache.camel.util;
 
+import java.util.AbstractSet;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -159,4 +161,37 @@ public class CaseInsensitiveMap extends HashMap<String, Object>
{
 
         return entrySetView;
     }
+
+    @Override
+    public Set<String> keySet() {
+        return new CaseInsensitiveKeySet();
+    }
+
+    /**
+     * To use the original keys but support checking if a key exist using case insensitive.
+     */
+    private final class CaseInsensitiveKeySet extends AbstractSet<String> {
+
+        public Iterator<String> iterator() {
+            // use the original case keys, which is stored in as values
+            return originalKeys.values().iterator();
+        }
+
+        public int size() {
+            return CaseInsensitiveMap.this.size();
+        }
+
+        public boolean contains(Object o) {
+            return CaseInsensitiveMap.this.containsKey(o);
+        }
+
+        public boolean remove(Object o) {
+            return CaseInsensitiveMap.this.remove(o) != null;
+        }
+
+        public void clear() {
+            CaseInsensitiveMap.this.clear();
+        }
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b2938951/camel-core/src/test/java/org/apache/camel/util/CaseInsensitiveMapTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/CaseInsensitiveMapTest.java b/camel-core/src/test/java/org/apache/camel/util/CaseInsensitiveMapTest.java
index f1c2ab6..17d78bd 100644
--- a/camel-core/src/test/java/org/apache/camel/util/CaseInsensitiveMapTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/CaseInsensitiveMapTest.java
@@ -300,6 +300,10 @@ public class CaseInsensitiveMapTest extends TestCase {
         assertEquals(true, map.containsKey("FOO"));
 
         assertEquals(true, map.keySet().contains("FOO"));
+        assertEquals(true, map.keySet().contains("FoO"));
+        assertEquals(true, map.keySet().contains("Foo"));
+        assertEquals(true, map.keySet().contains("foo"));
+        assertEquals(true, map.keySet().contains("fOO"));
 
         map.put("FOO", "cake");
         assertEquals(1, map.size());
@@ -427,17 +431,16 @@ public class CaseInsensitiveMapTest extends TestCase {
 
         Map<String, Object> other = new HashMap<String, Object>();
 
-        // this is wrong!!! you should use entrySet
         for (String key : map.keySet()) {
             Object value = map.get(key);
             other.put(key, value);
         }
 
-        // now the keys will be in lower case
-        assertEquals(true, other.containsKey("foo"));
-        assertEquals(false, other.containsKey("Foo"));
-        assertEquals(true, other.containsKey("bar"));
-        assertEquals(false, other.containsKey("BAR"));
+        // the original case of the keys should be preserved
+        assertEquals(false, other.containsKey("foo"));
+        assertEquals(true, other.containsKey("Foo"));
+        assertEquals(false, other.containsKey("bar"));
+        assertEquals(true, other.containsKey("BAR"));
         assertEquals(2, other.size());
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b2938951/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterHeaderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterHeaderTest.java
b/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterHeaderTest.java
index 3e2d28d..56de439 100644
--- a/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterHeaderTest.java
+++ b/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterHeaderTest.java
@@ -48,7 +48,7 @@ public class JXPathFilterHeaderTest extends CamelTestSupport {
             public void configure() {
                 // START SNIPPET: example
                 from("direct:start").
-                        filter().jxpath("headers/fooBarBaz='Carlsberg'").
+                        filter().jxpath("in/headers/fooBarBaz='Carlsberg'").
                         to("mock:result");
                 // END SNIPPET: example
             }


Mime
View raw message