Package com.twelvemonkeys.util
Class IgnoreCaseMap<V>
java.lang.Object
java.util.AbstractMap<K,V>
com.twelvemonkeys.util.IgnoreCaseMap<V>
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,V>
A
Map decorator that makes the mappings in the backing map
case insensitive
(this is implemented by converting all keys to uppercase),
if the keys used are Strings. If the keys
used are not Strings, it wil work as a normal
java.util.Map.- Author:
- Harald Kuhr
- 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> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new emptyMap.IgnoreCaseMap(Map<String, ? extends V> pMap) Constructs a newMapwith the same key-value mappings as the givenMap.IgnoreCaseMap(Map pBacking, Map<String, ? extends V> pContents) Constructs a newMapwith the same key-value mappings as the givenMap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()protected Objectclone()Returns a shallow copy of thisAbstractMapinstance: the keys and values themselves are not cloned.booleancontainsKey(Object pKey) Tests if the specified object is a key in this map.booleancontainsValue(Object pValue) Returnstrueif this map maps one or more keys to the specified pValue.entrySet()Returns the value to which the specified key is mapped in this map.protected voidinit()Default implementation, does nothing.booleanisEmpty()keySet()Maps the specified key to the specified value in this map.Removes the key (and its corresponding value) from this map.removeEntry(Map.Entry<String, V> pEntry) Removes the given entry from the Map.intsize()protected static ObjectConverts the parameter to uppercase, if it's a String.values()Methods inherited from class java.util.AbstractMap
equals, hashCode, putAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
entries
-
modCount
protected transient volatile int modCount
-
-
Constructor Details
-
IgnoreCaseMap
public IgnoreCaseMap()Constructs a new emptyMap. The backing map will be aHashMap -
IgnoreCaseMap
Constructs a newMapwith the same key-value mappings as the givenMap. The backing map will be aHashMapNOTE: As the keys in the given map parameter will be converted to uppercase (if they are strings), any duplicate key/value pair where
key instanceof String && key.equalsIgnoreCase(otherKey)is true, will be lost.- Parameters:
pMap- the map whose mappings are to be placed in this map.
-
IgnoreCaseMap
Constructs a newMapwith the same key-value mappings as the givenMap.NOTE: The backing map is structuraly cahnged, and it should NOT be accessed directly, after the wrapped map is created.
NOTE: As the keys in the given map parameter will be converted to uppercase (if they are strings), any duplicate key/value pair where
key instanceof String && key.equalsIgnoreCase(otherKey)is true, will be lost.- Parameters:
pBacking- the backing map of this map. Must be either empty, or the same map aspContents.pContents- the map whose mappings are to be placed in this map. May benull- Throws:
IllegalArgumentException- ifpBackingisnullIllegalArgumentException- ifpBackingdiffers frompContentand is not empty.
-
-
Method Details
-
put
Maps the specified key to the specified value in this map. Note: If the key used is a string, the key will not be case-sensitive. -
get
Returns the value to which the specified key is mapped in this map. Note: If the key used is a string, the key will not be case-sensitive. -
remove
Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map. Note: If the key used is a string, the key will not be case-sensitive. -
containsKey
Tests if the specified object is a key in this map. Note: If the key used is a string, the key will not be case-sensitive.- Specified by:
containsKeyin interfaceMap<String,V> - Parameters:
pKey- possible key.- Returns:
- true if and only if the specified object is a key in this map, as determined by the equals method; false otherwise.
-
toUpper
Converts the parameter to uppercase, if it's a String. -
newEntryIterator
-
newKeyIterator
-
newValueIterator
-
init
protected void init()Default implementation, does nothing. -
size
public int size()- Specified by:
sizein interfaceMap<K,V> - Overrides:
sizein classAbstractMap<K,V>
-
clear
public void clear()- Specified by:
clearin interfaceMap<K,V> - Overrides:
clearin classAbstractMap<K,V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<K,V> - Overrides:
isEmptyin classAbstractMap<K,V>
-
containsValue
Returnstrueif this map maps one or more keys to the specified pValue. More formally, returnstrueif and only if this map contains at least one mapping to a pValuevsuch that(pValue==null ? v==null : pValue.equals(v)).This implementation requires time linear in the map size for this operation.
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classAbstractMap<K,V> - Parameters:
pValue- pValue whose presence in this map is to be tested.- Returns:
trueif this map maps one or more keys to the specified pValue.
-
values
- Specified by:
valuesin interfaceMap<K,V> - Overrides:
valuesin classAbstractMap<K,V>
-
entrySet
- Specified by:
entrySetin interfaceMap<K,V> - Specified by:
entrySetin classAbstractMap<K,V>
-
keySet
- Specified by:
keySetin interfaceMap<K,V> - Overrides:
keySetin classAbstractMap<K,V>
-
clone
Returns a shallow copy of thisAbstractMapinstance: the keys and values themselves are not cloned.- Overrides:
clonein classAbstractMap<K,V> - Returns:
- a shallow copy of this map.
- Throws:
CloneNotSupportedException
-
removeEntry
Removes the given entry from the Map.- Parameters:
pEntry- the entry to be removed- Returns:
- the removed entry, or
nullif nothing was removed.
-