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 emptyCaseInsensitiveMapwith the default initial capacity (16) and the default load factor (0.75).CaseInsensitiveMap(int initialCapacity) Constructs an emptyCaseInsensitiveMapwith the specified initial capacity and the default load factor (0.75).CaseInsensitiveMap(int initialCapacity, float loadFactor) Constructs an emptyCaseInsensitiveMapwith the specified initial capacity and load factor.CaseInsensitiveMap(Map<? extends String, ? extends T> map) Constructs a newCaseInsensitiveMapwith 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, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
CaseInsensitiveMap
public CaseInsensitiveMap()Constructs an emptyCaseInsensitiveMapwith the default initial capacity (16) and the default load factor (0.75). -
CaseInsensitiveMap
public CaseInsensitiveMap(int initialCapacity, float loadFactor) Constructs an emptyCaseInsensitiveMapwith 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 emptyCaseInsensitiveMapwith 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 newCaseInsensitiveMapwith the same mappings as the specifiedMap. TheCaseInsensitiveMapis created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specifiedMap.- Parameters:
map- theMapwhose 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:
containsKeyin interfaceMap<String,T> - Overrides:
containsKeyin 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:
getOrDefaultin interfaceMap<String,T> - Overrides:
getOrDefaultin classHashMap<String,T>
-