class XmlExternalIdValidator {

  public synchronized void validateExternalId(ExternalId externalSystemId, String tradeId) {
    if (_existingMappings.containsKey(externalSystemId)) {
      String previousTradeId = _existingMappings.get(externalSystemId);
      if (!previousTradeId.equals(tradeId)) {
        String message = MessageFormatter.arrayFormat(
            "External id '{}' already allocated to a different trade when processing this file. Previous trade id: '{}', this trade id: '{}'",
            new Object[] {externalSystemId, previousTradeId, tradeId }).getMessage();

        throw new OpenGammaRuntimeException(message);
      }
    }
    _existingMappings.put(externalSystemId, tradeId);
  }

}