Class CaseInsensitiveMap<T>
- Type Parameters:
T
- the type of mapped values
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
T>
A CaseInsensitiveMap
is a specialized HashMap
with case insensitive keys of type String
.
All keys will be converted with String.toLowerCase(Locale)
with Locale.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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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
(Map<? extends String, ? extends T> map) Constructs a newCaseInsensitiveMap
with the same mappings as the specifiedMap
. -
Method Summary
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
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
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:
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:
IllegalArgumentException
- if the initial capacity is negative.
-
CaseInsensitiveMap
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:
NullPointerException
- if the specified map isnull
-
-
Method Details
-
containsKey
The key is interpreted case-insensitive.- Specified by:
containsKey
in interfaceMap<String,
T> - Overrides:
containsKey
in classHashMap<String,
T>
-
get
The key is interpreted case-insensitive. -
put
The key is converted to lower case before the mapping is stored. -
remove
The key is interpreted case-insensitive. -
putAll
The keys in the given map are interpreted case-insensitive. -
getOrDefault
- Specified by:
getOrDefault
in interfaceMap<String,
T> - Overrides:
getOrDefault
in classHashMap<String,
T>
-