update method
- @override
override
Updates the value for the provided key
.
Returns the new value of the key.
If the key is present, invokes update
with the current value and stores
the new value in the map.
If the key is not present and ifAbsent
is provided, calls ifAbsent
and adds the key with the returned value to the map.
It's an error if the key is not present and ifAbsent
is not provided.
Implementation
@override
V update(K key, V update(V value), {V ifAbsent()}) {
V newValue;
if (containsKey(key)) {
newValue = update(this[key]);
} else {
if (ifAbsent == null)
throw new ArgumentError.value(key, 'key', 'Key not in map');
newValue = ifAbsent();
}
// Add this item to the MRU position.
_insertMru(_createEntry(key, newValue));
// Remove the LRU item if the size would be exceeded by adding this item.
if (length > maximumSize) {
assert(length == maximumSize + 1);
_removeLru();
}
return newValue;
}