Skip to content

UTIL_Map.CaseInsensitiveMap

Class

apex
global inherited sharing class UTIL_Map.CaseInsensitiveMap

A Map implementation that performs case-insensitive key lookups. Keys are normalised to lower case for internal storage and retrieval, but the original casing is retained for display and export operations.

Since: 1.0

Example:

apex
UTIL_Map.CaseInsensitiveMap ciMap = new UTIL_Map.CaseInsensitiveMap();
ciMap.put('Acme Ltd', myAccount);
Account a = (Account) ciMap.get('ACME LTD');

Methods

MethodDescription
global CaseInsensitiveMap()Constructs an empty CaseInsensitiveMap.
global CaseInsensitiveMap(Map<String, Object> sourceMap)Constructs a new CaseInsensitiveMap pre-populated with entries from the provided standard map.
global void clear()Empties this map, discarding all stored entries.
global Boolean containsKey(String key)Checks whether this map holds an entry for the specified key, ignoring letter case.
global UTIL_Map.CaseInsensitiveMap copy()Produces a shallow copy of this CaseInsensitiveMap.
global Object get(String key)Retrieves the value mapped to the supplied key using a case-insensitive comparison.
global Boolean isEmpty()Indicates whether this map is empty, containing zero entries.
global Set keySet()Returns the set of keys in their original, caller-supplied casing.
global void put(String key, Object value)Stores a value under the given key.
global void putAll(Map<String, Object> sourceMap)Inserts all entries from the supplied map into this map.
global Object remove(String key)Deletes the entry for the given key (case-insensitive match) and returns the previously associated value.
global Integer size()Returns the current number of key-value mappings stored in this map.
global Map toMap()Exports the contents of this map to a standard Map, restoring the original key casing.
global List values()Returns all values stored in this map as an ordered list.

Method Details

CaseInsensitiveMap

apex
global CaseInsensitiveMap()

Constructs an empty CaseInsensitiveMap.

Since: 1.0

Example:

apex
UTIL_Map.CaseInsensitiveMap instance = new UTIL_Map.CaseInsensitiveMap();

CaseInsensitiveMap

apex
global CaseInsensitiveMap(Map<String, Object> sourceMap)

Constructs a new CaseInsensitiveMap pre-populated with entries from the provided standard map.

Parameters:

  • sourceMap (Map) - The map whose entries are to be placed into this map.

Since: 1.0

Example:

apex
UTIL_Map.CaseInsensitiveMap instance = new UTIL_Map.CaseInsensitiveMap(new Map<String, Object>{'key' => 'value'});

clear

apex
global void clear()

Empties this map, discarding all stored entries.

Since: 1.0

Example:

apex
instance.clear();

containsKey

apex
global Boolean containsKey(String key)

Checks whether this map holds an entry for the specified key, ignoring letter case.

Parameters:

  • key (String) - The key whose presence in this map is to be tested.

Returns: Boolean - Boolean true if this map contains a mapping for the specified key, otherwise false.

Since: 1.0

Example:

apex
Boolean result = instance.containsKey('value');

copy

apex
global UTIL_Map.CaseInsensitiveMap copy()

Produces a shallow copy of this CaseInsensitiveMap. The returned instance is independent; mutations do not propagate between the original and the copy.

Returns: UTIL_Map.CaseInsensitiveMap - A new CaseInsensitiveMap instance that is a copy of this one.

Since: 1.0

Example:

apex
CaseInsensitiveMap result = instance.copy();

get

apex
global Object get(String key)

Retrieves the value mapped to the supplied key using a case-insensitive comparison. Returns null when no mapping exists.

Parameters:

  • key (String) - The key whose associated value is to be returned.

Returns: Object - The value associated with the key, or null if no mapping exists.

Since: 1.0

Example:

apex
Object result = instance.get('value');

isEmpty

apex
global Boolean isEmpty()

Indicates whether this map is empty, containing zero entries.

Returns: Boolean - Boolean true if the map is empty, otherwise false.

Since: 1.0

Example:

apex
Boolean result = instance.isEmpty();

keySet

apex
global Set<String> keySet()

Returns the set of keys in their original, caller-supplied casing.

Returns: String - A Set of the original keys in the map.

Since: 1.0

Example:

apex
Set<String> result = instance.keySet();

put

apex
global void put(String key, Object value)

Stores a value under the given key. If a mapping already exists for the same key (regardless of letter case), it is replaced.

Parameters:

  • key (String) - The key with which the specified value is to be associated.
  • value (Object) - The value to be associated with the specified key.

Since: 1.0

Example:

apex
instance.put('value', 'value');

putAll

apex
global void putAll(Map<String, Object> sourceMap)

Inserts all entries from the supplied map into this map. Existing mappings whose keys match (case-insensitively) are overwritten.

Parameters:

  • sourceMap (Map) - The map whose entries are to be placed into this map.

Since: 1.0

Example:

apex
instance.putAll(new Map<String, Object>{'key' => 'value'});

remove

apex
global Object remove(String key)

Deletes the entry for the given key (case-insensitive match) and returns the previously associated value.

Parameters:

  • key (String) - The key whose mapping is to be removed from the map.

Returns: Object - The previous value associated with the key, or null if there was no mapping for the key.

Since: 1.0

Example:

apex
Object result = instance.remove('value');

size

apex
global Integer size()

Returns the current number of key-value mappings stored in this map.

Returns: Integer - The number of entries in the map.

Since: 1.0

Example:

apex
Integer result = instance.size();

toMap

apex
global Map<String, Object> toMap()

Exports the contents of this map to a standard Map , restoring the original key casing.

Returns: Object - A new Map<String, Object> containing all entries from this map.

Since: 1.0

Example:

apex
Map<String, Object> result = instance.toMap();

values

apex
global List<Object> values()

Returns all values stored in this map as an ordered list.

Returns: Object - A List of the values in the map.

Since: 1.0

Example:

apex
List<Object> result = instance.values();