Package com.twelvemonkeys.util
Class IgnoreCaseMap<V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
V>
public class IgnoreCaseMap<V>
extends AbstractDecoratedMap<String,V>
implements Serializable, Cloneable
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 String
s, it wil work as a normal
java.util.Map
.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.twelvemonkeys.util.AbstractDecoratedMap
AbstractDecoratedMap.BasicEntry<K,
V>, AbstractDecoratedMap.EntrySet, AbstractDecoratedMap.KeySet, AbstractDecoratedMap.Values Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Fields inherited from class com.twelvemonkeys.util.AbstractDecoratedMap
entries, modCount
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new emptyMap
.IgnoreCaseMap
(Map<String, ? extends V> pMap) Constructs a newMap
with the same key-value mappings as the givenMap
.IgnoreCaseMap
(Map pBacking, Map<String, ? extends V> pContents) Constructs a newMap
with the same key-value mappings as the givenMap
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(Object pKey) Tests if the specified object is a key in this map.Returns the value to which the specified key is mapped in this map.Maps the specified key to the specified value in this map.Removes the key (and its corresponding value) from this map.protected static Object
Converts the parameter to uppercase, if it's a String.private V
Methods inherited from class com.twelvemonkeys.util.AbstractDecoratedMap
clear, clone, containsValue, createEntry, entrySet, getEntry, init, isEmpty, keySet, removeEntry, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, putAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
IgnoreCaseMap
public IgnoreCaseMap()Constructs a new emptyMap
. The backing map will be aHashMap
-
IgnoreCaseMap
Constructs a newMap
with the same key-value mappings as the givenMap
. The backing map will be aHashMap
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:
pMap
- the map whose mappings are to be placed in this map.
-
IgnoreCaseMap
Constructs a newMap
with 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
- ifpBacking
isnull
IllegalArgumentException
- ifpBacking
differs frompContent
and 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. -
unwrap
-
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:
containsKey
in interfaceMap<String,
V> - Overrides:
containsKey
in classAbstractDecoratedMap<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
- Specified by:
newEntryIterator
in classAbstractDecoratedMap<String,
V>
-
newKeyIterator
- Specified by:
newKeyIterator
in classAbstractDecoratedMap<String,
V>
-
newValueIterator
- Specified by:
newValueIterator
in classAbstractDecoratedMap<String,
V>
-