public class CaseAwareMap extends Object implements Map
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");
put overwrites the value of the first one,
because the keys are considered to be equal. With
get("TesT");
"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.TreeMap(String.CASE_INSENSITIVE_ORDER)
except that non-strings do not throw a ClassCastException
and that keys are not sorted.| Constructor and Description |
|---|
CaseAwareMap() |
CaseAwareMap(boolean isCaseSensitive) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set |
entrySet() |
Object |
get(Object key) |
boolean |
isCaseSensitive()
Returns if keys are case sensitive.
|
boolean |
isEmpty() |
Set |
keySet() |
Object |
put(Object key,
Object value) |
void |
putAll(Map map) |
Object |
remove(Object key) |
void |
setCaseSensitive(boolean isCaseSensitive)
Sets if keys are case sensitive.
|
int |
size() |
Collection |
values() |
public CaseAwareMap()
public CaseAwareMap(boolean isCaseSensitive)
public boolean isCaseSensitive()
false.public void setCaseSensitive(boolean isCaseSensitive)
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.isCaseSensitive - are keys case sensitivepublic boolean containsKey(Object key)
containsKey in interface Mappublic boolean containsValue(Object value)
containsValue in interface Mappublic Collection values()
Copyright © 2003-2016. All Rights Reserved.