addToMap static method

void addToMap({
  1. required MAJNode node,
  2. bool check = false,
})

adds a key and node reference to the map overwrites existing entries unless check == true if a key already exists and check == true an error is thrown

Implementation

static void addToMap({
  required MAJNode node,
  bool check = false,
}) {
  // check for overwrite throw error if will happen and check true
  if (check) {
    if (maps[node.mapKey]!.containsKey(node.path)) {
      throw Exception(
        "MAJProvider: Cannot add '$node.path' to map, because it already exists",
      );
    }
  }

  // add mapKey if doesn't already exist
  if (!maps.containsKey(node.mapKey)) {
    maps[node.mapKey] = {};
  }

  // add the node reference with path to the map
  maps[node.mapKey]![node.path] = node;
}