|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javawebparts.core.CaseInsensitiveMap
A Map implementation that handles its keys in a case insensitive manner.
This is just a wrapper class, it uses another Map implementation of your
choice (HashMap by default) to actually store the entries.
The Map accepts only String objects as keys, it doesn't accept null keys,
but it accepts null values (even if the wrapped Map doesn't support null
values).
The Map implements all the methods defined by the Map interface, and
although it handles keys in a case insensitive manner, it maintains the
original headers as they were added. This means that if you use the
keySet()
or the entrSet()
methods to get a
Collection view of the keys(or Map.Entry objects respectively) you'll find
the keys with the same casing you added them (ie. they will not be converted
to all lower-case or upper-case characters).
Nested Class Summary | |
private class |
CaseInsensitiveMap.AbstractCollectionView
Abstract implementation having all the common functionality used by the collection view classes returned by keySet(), entrySet() and values() . |
private class |
CaseInsensitiveMap.EntrySet
Private Set implementation used to return a Set of entries
in the map. |
private static class |
CaseInsensitiveMap.FakeEntry
Our Map.Entry implementation used in the Set returned by the
entrySet() method.
|
private static class |
CaseInsensitiveMap.KeyAndValue
Inner class used to store a key-value pair. |
private class |
CaseInsensitiveMap.KeySet
Private Set implementation used to return a set of the keys
in the map. |
private class |
CaseInsensitiveMap.ValuesCollection
Private Collection implementation used to return a Collection of the values in the map. |
Field Summary | |
private java.util.Map |
map
Internal Map used to store the Entries. |
Constructor Summary | |
CaseInsensitiveMap()
Creates a new CaseInsensitiveMap that will use a HashMap internally to store the mappings. |
|
CaseInsensitiveMap(java.util.Map someOtherMap)
Creates a new CaseInsensitiveMap and adds the mappings defined in the passed in map. |
Method Summary | |
void |
clear()
Removes all the mappings from this map. |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified
key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps at least one key to the
specified value. |
java.util.Set |
entrySet()
Returns a set view of the mappings contained in this map. |
boolean |
equals(java.lang.Object obj)
Compares this map with the passed in object for equality. |
java.lang.Object |
get(java.lang.Object key)
Returns the value mapped to the specified key or null if the
specified key isn't mapped to any value. |
int |
hashCode()
Returns the hash code of this map. |
boolean |
isEmpty()
Return true if this map contains no entries. |
java.util.Set |
keySet()
Returns a set view of the keys contained in this map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key. |
void |
putAll(java.util.Map otherMap)
Iterates over all the mappings of the specified map and adds them with put(key, value) to this map. |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key from this map if present. |
int |
size()
Returns the number of entries in this map. |
java.lang.String |
toString()
Returns the string representation of this map. |
java.util.Collection |
values()
Returns a collection view of the values contained in this map. |
static CaseInsensitiveMap |
wrapExistingMap(java.util.Map someMap)
Wrap an existing map and make it case-insensitive. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
private java.util.Map map
Constructor Detail |
public CaseInsensitiveMap()
wrapExistingMap(Map)
method to add the case-insensitive
functionality to the Map you created.
wrapExistingMap(Map)
public CaseInsensitiveMap(java.util.Map someOtherMap)
putAll(Map)
method on it, passing in the Map you pass
in to this constructor.
someOtherMap
- a map containing the mappings to be addedCaseInsensitiveMap()
,
putAll(Map)
Method Detail |
public static CaseInsensitiveMap wrapExistingMap(java.util.Map someMap)
null
and non-string keys are ignored, and entries are
overwritten if their keys are equal (case-insensitive check).
So you could end up with less entries than in the passed in map.
someMap
- the map to wrap
public int size()
size
in interface java.util.Map
public boolean isEmpty()
true
if this map contains no entries.
isEmpty
in interface java.util.Map
true
if this map contains no entries.public boolean containsKey(java.lang.Object key)
true
if this map contains a mapping for the specified
key. The passed in key and the keys in the map are compared in a
case-insensitive way.
containsKey
in interface java.util.Map
key
- the key to check if it exists in this Map.
true
if this map contains a
mapping for the specified key.
java.lang.ClassCastException
- if the passed in key isn't a
String
public boolean containsValue(java.lang.Object value)
true
if this map maps at least one key to the
specified value.
containsValue
in interface java.util.Map
value
- the value to check if it exists in this Map
true
if this map maps at least one key to the
specified value.public java.lang.Object get(java.lang.Object key)
null
if the
specified key isn't mapped to any value. A return value of
null
does not necessarily indicate that the map
contains no mapping for the key; it is also possible that the map
explicitly maps the key to null
. The containsKey
method may be used to distinguish these two cases.
get
in interface java.util.Map
key
- the key whose associated value is to be returned
null
if the specified key isn't
mapped to any value.
java.lang.ClassCastException
- if the passed in key isn't a
String
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
key
- the key to be associated with the valuevalue
- the value to be associated with the key
null
if no
previous association existed.
Null
can also be returned if the
specified key was previously associated with
the null
value.
java.lang.NullPointerException
- if the passed in key is null
java.lang.ClassCastException
- if the passed in key isn't a
String
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
key
- the key whose mapping is to be removed from the
map
null
if there was no mapping for
the specified key. A value of null
can also be returned if the specified key was
associated with the null
value.
java.lang.ClassCastException
- if the passed in key isn't a
String
public void putAll(java.util.Map otherMap)
put(key, value)
to this map. The method ignores (doesn't add)
null and non-string keys.
putAll
in interface java.util.Map
otherMap
- Map containing the mappings to be added to
this mappublic void clear()
clear
in interface java.util.Map
public java.util.Set keySet()
Iterator.remove, Set.remove, removeAll,
retainAll,
and clear
operations.
It does not support the add
or addAll
operations.
keySet
in interface java.util.Map
public java.util.Collection values()
Iterator.remove, Collection.remove, removeAll, retainAll
and
clear
operations. It does not support the add
or
addAll
operations.
values
in interface java.util.Map
public java.util.Set entrySet()
Map.Entry
. The set is
backed by the map, so changes to the map are reflected in the set, and
vice-versa. The set supports element removal, which removes the
corresponding mapping from the map, via the Iterator.remove,
Set.remove, removeAll, retainAll
and clear
operations.
It does not support the add
or addAll
operations.
entrySet
in interface java.util.Map
public boolean equals(java.lang.Object obj)
true if the passed in object is also a
CaseInsensitiveMap and the entrySets of the two maps are equal.
- Specified by:
equals
in interface java.util.Map
- Overrides:
equals
in class java.lang.Object
- Parameters:
obj
- the object to compare with
- Returns:
true
if the passed in object and this map are
equal
public int hashCode()
hashCode
in interface java.util.Map
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |