LinkedCaseInsensitiveMap exposes its locale for key conversion

Issue: SPR-15752
(cherry picked from commit 9b5132c)
This commit is contained in:
Juergen Hoeller
2017-07-10 14:24:28 +02:00
parent a9a4d7cf78
commit 3802aca474
2 changed files with 34 additions and 15 deletions

View File

@@ -47,18 +47,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(Locale locale) {
this(16, locale);
@@ -66,10 +67,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);
@@ -77,11 +78,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, Locale locale) {
this.targetMap = new LinkedHashMap<String, V>(initialCapacity) {
@@ -113,6 +114,8 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
}
// Implementation of java.util.Map
@Override
public int size() {
return this.targetMap.size();
@@ -227,16 +230,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());
}
/**