org.mule.util
Class CaseInsensitiveHashMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.apache.commons.collections.map.AbstractHashedMap
          extended by org.mule.util.CaseInsensitiveHashMap
All Implemented Interfaces:
Serializable, Map, org.apache.commons.collections.IterableMap
Direct Known Subclasses:
RegistryMap

public class CaseInsensitiveHashMap
extends org.apache.commons.collections.map.AbstractHashedMap
implements Serializable

A case-insensitive Map.

As entries are added to the map, keys hash values are lowercase hash codes of the key. the Real key case is preserved.

The keySet() method returns all keys in their original case

Note that CaseInsensitiveMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using Collections.synchronizedMap(Map). This class may throw exceptions when accessed by concurrent threads without synchronization.

Since:
3.0.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractHashedMap
org.apache.commons.collections.map.AbstractHashedMap.EntrySet, org.apache.commons.collections.map.AbstractHashedMap.EntrySetIterator, org.apache.commons.collections.map.AbstractHashedMap.HashEntry, org.apache.commons.collections.map.AbstractHashedMap.HashIterator, org.apache.commons.collections.map.AbstractHashedMap.HashMapIterator, org.apache.commons.collections.map.AbstractHashedMap.KeySet, org.apache.commons.collections.map.AbstractHashedMap.KeySetIterator, org.apache.commons.collections.map.AbstractHashedMap.Values, org.apache.commons.collections.map.AbstractHashedMap.ValuesIterator
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap
data, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, entrySet, GETKEY_INVALID, GETVALUE_INVALID, keySet, loadFactor, MAXIMUM_CAPACITY, modCount, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, size, threshold, values
 
Constructor Summary
CaseInsensitiveHashMap()
          Constructs a new empty map with default size and load factor.
CaseInsensitiveHashMap(int initialCapacity)
          Constructs a new, empty map with the specified initial capacity.
CaseInsensitiveHashMap(int initialCapacity, float loadFactor)
          Constructs a new, empty map with the specified initial capacity and load factor.
CaseInsensitiveHashMap(Map map)
          Constructor copying elements from another map.
 
Method Summary
 Object clone()
          Clones the map without cloning the keys or values.
protected  int hash(Object key)
          Creates a hash value from the lower case value of the key.
protected  boolean isEqualKey(Object key1, Object key2)
          Overloads the default behaviour to compare the keys without case sensitivity
 
Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap
addEntry, addMapping, calculateNewCapacity, calculateThreshold, checkCapacity, clear, containsKey, containsValue, convertKey, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, destroyEntry, doReadObject, doWriteObject, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, get, getEntry, hashCode, hashIndex, init, isEmpty, isEqualValue, keySet, mapIterator, put, putAll, remove, removeEntry, removeMapping, reuseEntry, size, toString, updateEntry, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CaseInsensitiveHashMap

public CaseInsensitiveHashMap()
Constructs a new empty map with default size and load factor.


CaseInsensitiveHashMap

public CaseInsensitiveHashMap(int initialCapacity)
                       throws IllegalArgumentException
Constructs a new, empty map with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity
Throws:
IllegalArgumentException - if the initial capacity is less than one

CaseInsensitiveHashMap

public CaseInsensitiveHashMap(int initialCapacity,
                              float loadFactor)
                       throws IllegalArgumentException
Constructs a new, empty map with the specified initial capacity and load factor.

Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor
Throws:
IllegalArgumentException - if the initial capacity is less than one
IllegalArgumentException - if the load factor is less than zero

CaseInsensitiveHashMap

public CaseInsensitiveHashMap(Map map)
Constructor copying elements from another map.

Keys will be converted to lower case strings, which may cause some entries to be removed (if string representation of keys differ only by character case).

Parameters:
map - the map to copy
Throws:
NullPointerException - if the map is null
Method Detail

hash

protected int hash(Object key)
Creates a hash value from the lower case value of the key. The same function will be used when querying a value in the map also

Overrides:
hash in class org.apache.commons.collections.map.AbstractHashedMap
Parameters:
key - the key value to hash
Returns:
a hash value for the lower case key

isEqualKey

protected boolean isEqualKey(Object key1,
                             Object key2)
Overloads the default behaviour to compare the keys without case sensitivity

Overrides:
isEqualKey in class org.apache.commons.collections.map.AbstractHashedMap
Parameters:
key1 - the first key
key2 - the key to compare against
Returns:
true is the keys match

clone

public Object clone()
Clones the map without cloning the keys or values.

Overrides:
clone in class org.apache.commons.collections.map.AbstractHashedMap
Returns:
a shallow clone


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.