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 String
s, 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 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 TypeMethodDescriptionvoid
clear()
protected Object
clone()
Returns a shallow copy of thisAbstractMap
instance: the keys and values themselves are not cloned.boolean
containsKey
(Object pKey) Tests if the specified object is a key in this map.boolean
containsValue
(Object pValue) Returnstrue
if 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 void
init()
Default implementation, does nothing.boolean
isEmpty()
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.int
size()
protected static Object
Converts the parameter to uppercase, if it's a String.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
-
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 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. -
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> - 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:
size
in interfaceMap<K,
V> - Overrides:
size
in classAbstractMap<K,
V>
-
clear
public void clear()- Specified by:
clear
in interfaceMap<K,
V> - Overrides:
clear
in classAbstractMap<K,
V>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceMap<K,
V> - Overrides:
isEmpty
in classAbstractMap<K,
V>
-
containsValue
Returnstrue
if this map maps one or more keys to the specified pValue. More formally, returnstrue
if and only if this map contains at least one mapping to a pValuev
such that(pValue==null ? v==null : pValue.equals(v))
.This implementation requires time linear in the map size for this operation.
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classAbstractMap<K,
V> - Parameters:
pValue
- pValue whose presence in this map is to be tested.- Returns:
true
if this map maps one or more keys to the specified pValue.
-
values
- Specified by:
values
in interfaceMap<K,
V> - Overrides:
values
in classAbstractMap<K,
V>
-
entrySet
- Specified by:
entrySet
in interfaceMap<K,
V> - Specified by:
entrySet
in classAbstractMap<K,
V>
-
keySet
- Specified by:
keySet
in interfaceMap<K,
V> - Overrides:
keySet
in classAbstractMap<K,
V>
-
clone
Returns a shallow copy of thisAbstractMap
instance: the keys and values themselves are not cloned.- Overrides:
clone
in 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
null
if nothing was removed.
-