containsKey method

  1. @override
bool containsKey(
  1. Object? key
)
override

Whether this map contains the given key.

Returns true if any of the keys in the map are equal to key according to the equality used by the map.

final moonCount = <String, int>{'Mercury': 0, 'Venus': 0, 'Earth': 1,
  'Mars': 2, 'Jupiter': 79, 'Saturn': 82, 'Uranus': 27, 'Neptune': 14 };
final containsUranus = moonCount.containsKey('Uranus'); // true
final containsPluto = moonCount.containsKey('Pluto'); // false

Implementation

@override
bool containsKey(Object? key) {
  if (key is K) {
    var current = _root;
    // Navigate to the right node.
    for (final part in _getParts(key)) {
      final node = current.getChild(part);
      if (node == null) {
        return false;
      }
      current = node;
    }
    // Verify we found a value node.
    return current.hasKeyAndValue;
  }
  return false;
}