errorCodeByUniqueName function

ErrorCode errorCodeByUniqueName (
  1. String uniqueName
)

Return the ErrorCode with the given uniqueName, or null if not found.

Implementation

ErrorCode errorCodeByUniqueName(String uniqueName) {
  if (_uniqueNameToCodeMap == null) {
    _uniqueNameToCodeMap = HashMap<String, ErrorCode>();
    for (ErrorCode errorCode in errorCodeValues) {
      var uniqueName = errorCode.uniqueName;
      assert(() {
        if (_uniqueNameToCodeMap.containsKey(uniqueName)) {
          throw StateError('Not unique: $uniqueName');
        }
        return true;
      }());
      _uniqueNameToCodeMap[uniqueName] = errorCode;
    }
  }
  return _uniqueNameToCodeMap[uniqueName];
}