class BloombergDataUtils {

  public static ExternalIdBundleWithDates parseIdentifiers(final FudgeMsg fieldData, final String firstTradeDateField, final String lastTradeDateField) {
    ArgumentChecker.notNull(fieldData, "fieldData");
    final String bbgUnique = fieldData.getString(FIELD_ID_BBG_UNIQUE);
    final String cusip = fieldData.getString(FIELD_ID_CUSIP);
    final String isin = fieldData.getString(FIELD_ID_ISIN);
    final String sedol1 = fieldData.getString(FIELD_ID_SEDOL1);
    final String securityIdentifier = fieldData.getString(FIELD_PARSEKYABLE_DES);
    final String validFromStr = firstTradeDateField != null ? fieldData.getString(firstTradeDateField) : null;
    final String validToStr = lastTradeDateField != null ? fieldData.getString(lastTradeDateField) : null;

    final Set<ExternalIdWithDates> identifiers = new HashSet<ExternalIdWithDates>();
    if (isValidField(bbgUnique)) {
      final ExternalId buid = ExternalSchemes.bloombergBuidSecurityId(bbgUnique);
      identifiers.add(ExternalIdWithDates.of(buid, null, null));
    }
    if (isValidField(cusip)) {
      final ExternalId cusipId = ExternalSchemes.cusipSecurityId(cusip);
      identifiers.add(ExternalIdWithDates.of(cusipId, null, null));
    }
    if (isValidField(sedol1)) {
      final ExternalId sedol1Id = ExternalSchemes.sedol1SecurityId(sedol1);
      identifiers.add(ExternalIdWithDates.of(sedol1Id, null, null));
    }
    if (isValidField(isin)) {
      final ExternalId isinId = ExternalSchemes.isinSecurityId(isin);
      identifiers.add(ExternalIdWithDates.of(isinId, null, null));
    }
    if (isValidField(securityIdentifier)) {
      final ExternalId tickerId = ExternalSchemes.bloombergTickerSecurityId(securityIdentifier.replaceAll("\\s+", " "));
      LocalDate validFrom = null;
      if (isValidField(validFromStr)) {
        try {
          validFrom = LocalDate.parse(validFromStr);
        } catch (final DateTimeParseException ex) {
          s_logger.warn("valid from date not in yyyy-mm-dd format - {}", validFromStr);
        }
      }
      LocalDate validTo = null;
      if (isValidField(validToStr)) {
        try {
          validTo = LocalDate.parse(validToStr);
        } catch (final DateTimeParseException ex) {
          s_logger.warn("valid to date not in yyyy-mm-dd format - {}", validToStr);
        }
      }
      identifiers.add(ExternalIdWithDates.of(tickerId, validFrom, validTo));
    }
    return new ExternalIdBundleWithDates(identifiers);
  }

  private  BloombergDataUtils();

}