Top Description Fields Constructors Methods
org.apache.commons.collections4.map

public Class CaseInsensitiveMap<K, V>

extends AbstractHashedMap<K, V>
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.Map

A case-insensitive Map.

Before keys are added to the map or compared to other existing keys, they are converted to all lowercase in a locale-independent fashion by using information from the Unicode data file.

Null keys are supported.

The keySet() method returns all lowercase keys, or nulls.

Example:


 Map<String, String> map = new CaseInsensitiveMap<String, String>();
 map.put("One", "One");
 map.put("Two", "Two");
 map.put(null, "Three");
 map.put("one", "Four");

The example above creates a CaseInsensitiveMap with three entries.

map.get(null) returns "Three" and map.get("ONE") returns "Four". The Set returned by keySet() equals {"one", "two", null}.

This map will violate the detail of various Map and map view contracts. As a general rule, don't compare this map to other maps. In particular, you can't use decorators like ListOrderedMap on it, which silently assume that these contracts are fulfilled.

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 java.util.Collections#synchronizedMap(Map). This class may throw exceptions when accessed by concurrent threads without synchronization.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serialisation version

Inherited from org.apache.commons.collections4.map.AbstractHashedMap:
dataDEFAULT_CAPACITYDEFAULT_LOAD_FACTORDEFAULT_THRESHOLDentrySetGETKEY_INVALIDGETVALUE_INVALIDkeySetloadFactorMAXIMUM_CAPACITYmodCountNO_NEXT_ENTRYNO_PREVIOUS_ENTRYNULLREMOVE_INVALIDSETVALUE_INVALIDsizethresholdvalues

Constructor Summary

AccessConstructor and Description
public
CaseInsensitiveMap()

Constructs a new empty map with default size and load factor.

public
CaseInsensitiveMap(final int
the initial capacity
initialCapacity
)

Constructs a new, empty map with the specified initial capacity.

public
CaseInsensitiveMap(final int
the initial capacity
initialCapacity
,
final float
the load factor
loadFactor
)

Constructs a new, empty map with the specified initial capacity and load factor.

public
CaseInsensitiveMap(final Map<? extends K, ? extends V>
the map to copy
map
)

Constructor copying elements from another map.

Method Summary

Modifier and TypeMethod and Description
public CaseInsensitiveMap<K, V>

Returns:

a shallow clone
clone
()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.clone.

Clones the map without cloning the keys or values.
protected Object

Returns:

the converted key
convertKey
(final Object
the key convert
key
)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.convertKey.

Overrides convertKey() from AbstractHashedMap to convert keys to lower case.
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the map in using a custom routine.

private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the map out using a custom routine.

Inherited from org.apache.commons.collections4.map.AbstractHashedMap:
addEntryaddMappingcalculateNewCapacitycalculateThresholdcheckCapacityclearcontainsKeycontainsValuecreateEntrycreateEntrySetIteratorcreateKeySetIteratorcreateValuesIteratordestroyEntrydoReadObjectdoWriteObjectensureCapacityentryHashCodeentryKeyentryNextentrySetentryValueequalsgetgetEntryhashhashCodehashIndexinitisEmptyisEqualKeyisEqualValuekeySetmapIteratorputputAllremoveremoveEntryremoveMappingreuseEntrysizetoStringupdateEntryvalues

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serialisation version

Constructor Detail

CaseInsensitiveMapback to summary
public CaseInsensitiveMap()

Constructs a new empty map with default size and load factor.

CaseInsensitiveMapback to summary
public CaseInsensitiveMap(final int initialCapacity)

Constructs a new, empty map with the specified initial capacity.

Parameters
initialCapacity:int

the initial capacity

Exceptions
IllegalArgumentException:
if the initial capacity is negative
CaseInsensitiveMapback to summary
public CaseInsensitiveMap(final int initialCapacity, final float loadFactor)

Constructs a new, empty map with the specified initial capacity and load factor.

Parameters
initialCapacity:int

the initial capacity

loadFactor:float

the load factor

Exceptions
IllegalArgumentException:
  • if the initial capacity is negative
  • if the load factor is less than zero
CaseInsensitiveMapback to summary
public CaseInsensitiveMap(final Map<? extends K, ? extends V> 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:Map<? extends K, ? extends V>

the map to copy

Exceptions
NullPointerException:
if the map is null

Method Detail

cloneback to summary
public CaseInsensitiveMap<K, V> clone()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.clone.

Clones the map without cloning the keys or values.

Returns:CaseInsensitiveMap<K, V>

a shallow clone

Annotations
@Override
convertKeyback to summary
protected Object convertKey(final Object key)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.convertKey.

Overrides convertKey() from AbstractHashedMap to convert keys to lower case.

Returns AbstractHashedMap#NULL if key is null.

Parameters
key:Object

the key convert

Returns:Object

the converted key

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the map in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the map out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream