Class CaseInsensitiveMap<T>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<java.lang.String,T>
-
- com.saperion.common.lang.collection.CaseInsensitiveMap<T>
-
- Type Parameters:
T
- the type of mapped values
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.String,T>
public class CaseInsensitiveMap<T> extends java.util.HashMap<java.lang.String,T>
A
CaseInsensitiveMap
is a specializedHashMap
with case insensitive keys of typeString
.All keys will be converted with
String.toLowerCase(Locale)
withLocale.ENGLISH
.The keys are stored internally in lower case and all requests convert the specified key first and than compare it with the stored key as usual with
Object.equals(Object)
.This implementation is not synchronized. If used by different threads concurrently, external synchronization is necessary.
- Author:
- chm, agz
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CaseInsensitiveMap()
Constructs an emptyCaseInsensitiveMap
with the default initial capacity (16) and the default load factor (0.75).CaseInsensitiveMap(int initialCapacity)
Constructs an emptyCaseInsensitiveMap
with the specified initial capacity and the default load factor (0.75).CaseInsensitiveMap(int initialCapacity, float loadFactor)
Constructs an emptyCaseInsensitiveMap
with the specified initial capacity and load factor.CaseInsensitiveMap(java.util.Map<? extends java.lang.String,? extends T> map)
Constructs a newCaseInsensitiveMap
with the same mappings as the specifiedMap
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(java.lang.Object key)
T
get(java.lang.Object key)
T
getOrDefault(java.lang.Object key, T defaultValue)
T
put(java.lang.String key, T value)
void
putAll(java.util.Map<? extends java.lang.String,? extends T> m)
T
remove(java.lang.Object key)
-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsValue, entrySet, forEach, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
-
-
-
Constructor Detail
-
CaseInsensitiveMap
public CaseInsensitiveMap()
Constructs an emptyCaseInsensitiveMap
with the default initial capacity (16) and the default load factor (0.75).
-
CaseInsensitiveMap
public CaseInsensitiveMap(int initialCapacity, float loadFactor)
Constructs an emptyCaseInsensitiveMap
with the specified initial capacity and load factor.- Parameters:
initialCapacity
- the initial capacityloadFactor
- the load factor- Throws:
java.lang.IllegalArgumentException
- if the initial capacity is negative or the load factor is non-positive
-
CaseInsensitiveMap
public CaseInsensitiveMap(int initialCapacity)
Constructs an emptyCaseInsensitiveMap
with the specified initial capacity and the default load factor (0.75).- Parameters:
initialCapacity
- the initial capacity.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity is negative.
-
CaseInsensitiveMap
public CaseInsensitiveMap(java.util.Map<? extends java.lang.String,? extends T> map)
Constructs a newCaseInsensitiveMap
with the same mappings as the specifiedMap
. TheCaseInsensitiveMap
is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specifiedMap
.- Parameters:
map
- theMap
whose mappings are to be placed in this map- Throws:
java.lang.NullPointerException
- if the specified map isnull
-
-
Method Detail
-
containsKey
public boolean containsKey(java.lang.Object key)
The key is interpreted case-insensitive.
-
get
public T get(java.lang.Object key)
The key is interpreted case-insensitive.
-
put
public T put(java.lang.String key, T value)
The key is converted to lower case before the mapping is stored.
-
remove
public T remove(java.lang.Object key)
The key is interpreted case-insensitive.
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,? extends T> m)
The keys in the given map are interpreted case-insensitive.
-
-