|
|
|
|
@ -49,18 +49,19 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
@@ -49,18 +49,19 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new LinkedCaseInsensitiveMap for the default Locale. |
|
|
|
|
* @see java.lang.String#toLowerCase() |
|
|
|
|
* Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys |
|
|
|
|
* according to the default Locale (by default in lower case). |
|
|
|
|
* @see #convertKey(String) |
|
|
|
|
*/ |
|
|
|
|
public LinkedCaseInsensitiveMap() { |
|
|
|
|
this((Locale) null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new LinkedCaseInsensitiveMap that stores lower-case keys |
|
|
|
|
* according to the given Locale. |
|
|
|
|
* @param locale the Locale to use for lower-case conversion |
|
|
|
|
* @see java.lang.String#toLowerCase(java.util.Locale) |
|
|
|
|
* Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys |
|
|
|
|
* according to the given Locale (by default in lower case). |
|
|
|
|
* @param locale the Locale to use for case-insensitive key conversion |
|
|
|
|
* @see #convertKey(String) |
|
|
|
|
*/ |
|
|
|
|
public LinkedCaseInsensitiveMap(@Nullable Locale locale) { |
|
|
|
|
this(16, locale); |
|
|
|
|
@ -68,10 +69,10 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
@@ -68,10 +69,10 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new LinkedCaseInsensitiveMap that wraps a {@link LinkedHashMap} |
|
|
|
|
* with the given initial capacity and stores lower-case keys according |
|
|
|
|
* to the default Locale. |
|
|
|
|
* with the given initial capacity and stores case-insensitive keys |
|
|
|
|
* according to the default Locale (by default in lower case). |
|
|
|
|
* @param initialCapacity the initial capacity |
|
|
|
|
* @see java.lang.String#toLowerCase() |
|
|
|
|
* @see #convertKey(String) |
|
|
|
|
*/ |
|
|
|
|
public LinkedCaseInsensitiveMap(int initialCapacity) { |
|
|
|
|
this(initialCapacity, null); |
|
|
|
|
@ -79,11 +80,11 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
@@ -79,11 +80,11 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new LinkedCaseInsensitiveMap that wraps a {@link LinkedHashMap} |
|
|
|
|
* with the given initial capacity and stores lower-case keys according |
|
|
|
|
* to the given Locale. |
|
|
|
|
* with the given initial capacity and stores case-insensitive keys |
|
|
|
|
* according to the given Locale (by default in lower case). |
|
|
|
|
* @param initialCapacity the initial capacity |
|
|
|
|
* @param locale the Locale to use for lower-case conversion |
|
|
|
|
* @see java.lang.String#toLowerCase(java.util.Locale) |
|
|
|
|
* @param locale the Locale to use for case-insensitive key conversion |
|
|
|
|
* @see #convertKey(String) |
|
|
|
|
*/ |
|
|
|
|
public LinkedCaseInsensitiveMap(int initialCapacity, @Nullable Locale locale) { |
|
|
|
|
this.targetMap = new LinkedHashMap<String, V>(initialCapacity) { |
|
|
|
|
@ -115,6 +116,8 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
@@ -115,6 +116,8 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Implementation of java.util.Map
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int size() { |
|
|
|
|
return this.targetMap.size(); |
|
|
|
|
@ -159,7 +162,7 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
@@ -159,7 +162,7 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public V put(String key, V value) { |
|
|
|
|
public V put(String key, @Nullable V value) { |
|
|
|
|
String oldKey = this.caseInsensitiveKeys.put(convertKey(key), key); |
|
|
|
|
if (oldKey != null && !oldKey.equals(key)) { |
|
|
|
|
this.targetMap.remove(oldKey); |
|
|
|
|
@ -229,16 +232,29 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
@@ -229,16 +232,29 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Specific to LinkedCaseInsensitiveMap
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the locale used by this {@code LinkedCaseInsensitiveMap}. |
|
|
|
|
* Used for case-insensitive key conversion. |
|
|
|
|
* @since 4.3.10 |
|
|
|
|
* @see #LinkedCaseInsensitiveMap(Locale) |
|
|
|
|
* @see #convertKey(String) |
|
|
|
|
*/ |
|
|
|
|
public Locale getLocale() { |
|
|
|
|
return this.locale; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Convert the given key to a case-insensitive key. |
|
|
|
|
* <p>The default implementation converts the key |
|
|
|
|
* to lower-case according to this Map's Locale. |
|
|
|
|
* @param key the user-specified key |
|
|
|
|
* @return the key to use for storing |
|
|
|
|
* @see java.lang.String#toLowerCase(java.util.Locale) |
|
|
|
|
* @see String#toLowerCase(Locale) |
|
|
|
|
*/ |
|
|
|
|
protected String convertKey(String key) { |
|
|
|
|
return key.toLowerCase(this.locale); |
|
|
|
|
return key.toLowerCase(getLocale()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|