com.mockrunner.util.common
Class CaseAwareMap

java.lang.Object
  extended by com.mockrunner.util.common.CaseAwareMap
All Implemented Interfaces:
java.util.Map

public class CaseAwareMap
extends java.lang.Object
implements java.util.Map

Implementation of a Map that recognizes the case of the keys, if the keys are strings. If isCaseSensitive is true it behaves exactly like a HashMap. If isCaseSensitive is false (which is the default), it considers same strings with different case as equal. I.e. if you do

put("test", "1");
put("TEST", "2");

the second put overwrites the value of the first one, because the keys are considered to be equal. With

get("TesT");

you'll get the result "2". If you iterate through the keys (using either keySet or entrySet), you'll get the first added version of the key, in the above case, you'll get "test". It is allowed to use non-strings as keys. In this case the Map behaves like a usual HashMap.
Note: This class is similar to a TreeMap(String.CASE_INSENSITIVE_ORDER) except that non-strings do not throw a ClassCastException and that keys are not sorted.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
CaseAwareMap()
           
CaseAwareMap(boolean isCaseSensitive)
           
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 boolean isCaseSensitive()
          Returns if keys are case sensitive.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map map)
           
 java.lang.Object remove(java.lang.Object key)
           
 void setCaseSensitive(boolean isCaseSensitive)
          Sets if keys are case sensitive.
 int size()
           
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CaseAwareMap

public CaseAwareMap()

CaseAwareMap

public CaseAwareMap(boolean isCaseSensitive)
Method Detail

isCaseSensitive

public boolean isCaseSensitive()
Returns if keys are case sensitive. Defaults to false.

Returns:
are keys case sensitive

setCaseSensitive

public void setCaseSensitive(boolean isCaseSensitive)
Sets if keys are case sensitive. If set to true this implementation behaves like a HashMap. Please note, that all entries are cleared when switching case sensitivity. It's not possible to switch and keep the entries.

Parameters:
isCaseSensitive - are keys case sensitive

clear

public void clear()
Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

putAll

public void putAll(java.util.Map map)
Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

size

public int size()
Specified by:
size in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map