diff --git a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java index 480037581e6..d87078b6e61 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,6 +85,10 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable */ public LinkedCaseInsensitiveMap(int initialCapacity, Locale locale) { this.targetMap = new LinkedHashMap(initialCapacity) { + @Override + public boolean containsKey(Object key) { + return LinkedCaseInsensitiveMap.this.containsKey(key); + } @Override protected boolean removeEldestEntry(Map.Entry eldest) { boolean doRemove = LinkedCaseInsensitiveMap.this.removeEldestEntry(eldest); @@ -120,23 +124,35 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - public boolean containsValue(Object value) { - return this.targetMap.containsValue(value); + public boolean containsKey(Object key) { + return (key instanceof String && this.caseInsensitiveKeys.containsKey(convertKey((String) key))); } @Override - public Set keySet() { - return this.targetMap.keySet(); + public boolean containsValue(Object value) { + return this.targetMap.containsValue(value); } @Override - public Collection values() { - return this.targetMap.values(); + public V get(Object key) { + if (key instanceof String) { + String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey((String) key)); + if (caseInsensitiveKey != null) { + return this.targetMap.get(caseInsensitiveKey); + } + } + return null; } @Override - public Set> entrySet() { - return this.targetMap.entrySet(); + public V getOrDefault(Object key, V defaultValue) { + if (key instanceof String) { + String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey((String) key)); + if (caseInsensitiveKey != null) { + return this.targetMap.get(caseInsensitiveKey); + } + } + return defaultValue; } @Override @@ -158,33 +174,6 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } } - @Override - public boolean containsKey(Object key) { - return (key instanceof String && this.caseInsensitiveKeys.containsKey(convertKey((String) key))); - } - - @Override - public V get(Object key) { - if (key instanceof String) { - String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey((String) key)); - if (caseInsensitiveKey != null) { - return this.targetMap.get(caseInsensitiveKey); - } - } - return null; - } - - @Override - public V getOrDefault(Object key, V defaultValue) { - if (key instanceof String) { - String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey((String) key)); - if (caseInsensitiveKey != null) { - return this.targetMap.get(caseInsensitiveKey); - } - } - return defaultValue; - } - @Override public V remove(Object key) { if (key instanceof String) { @@ -202,6 +191,20 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable this.targetMap.clear(); } + @Override + public Set keySet() { + return this.targetMap.keySet(); + } + + @Override + public Collection values() { + return this.targetMap.values(); + } + + @Override + public Set> entrySet() { + return this.targetMap.entrySet(); + } @Override public LinkedCaseInsensitiveMap clone() { diff --git a/spring-core/src/test/java/org/springframework/util/LinkedCaseInsensitiveMapTests.java b/spring-core/src/test/java/org/springframework/util/LinkedCaseInsensitiveMapTests.java index d9bd2b2d4f8..369e1b50266 100644 --- a/spring-core/src/test/java/org/springframework/util/LinkedCaseInsensitiveMapTests.java +++ b/spring-core/src/test/java/org/springframework/util/LinkedCaseInsensitiveMapTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,12 @@ public class LinkedCaseInsensitiveMapTests { assertEquals("value3", map.get("key")); assertEquals("value3", map.get("KEY")); assertEquals("value3", map.get("Key")); + assertTrue(map.containsKey("key")); + assertTrue(map.containsKey("KEY")); + assertTrue(map.containsKey("Key")); + assertTrue(map.keySet().contains("key")); + assertTrue(map.keySet().contains("KEY")); + assertTrue(map.keySet().contains("Key")); } @Test @@ -48,6 +54,12 @@ public class LinkedCaseInsensitiveMapTests { assertEquals("value3", map.get("key")); assertEquals("value3", map.get("KEY")); assertEquals("value3", map.get("Key")); + assertTrue(map.containsKey("key")); + assertTrue(map.containsKey("KEY")); + assertTrue(map.containsKey("Key")); + assertTrue(map.keySet().contains("key")); + assertTrue(map.keySet().contains("KEY")); + assertTrue(map.keySet().contains("Key")); } @Test