BloombergDataUtils { public static ExternalIdBundleWithDates addTwoDigitYearCode(final ExternalIdBundleWithDates bundleWithDates) { ArgumentChecker.notNull(bundleWithDates, "bundleWithDates"); final Set<ExternalIdWithDates> identifiers = new HashSet<ExternalIdWithDates>(); for (final ExternalIdWithDates identifierWithDates : bundleWithDates) { final ExternalId identifier = identifierWithDates.toExternalId(); final String identifierValue = identifier.getValue(); if (identifierValue.contains(BloombergConstants.MARKET_SECTOR_COMDTY) && identifierValue.indexOf(' ') == identifierValue.lastIndexOf(' ')) { final int splitIndex = identifierValue.lastIndexOf(' '); final String secCode = identifierValue.substring(0, splitIndex); final int length = secCode.length(); String yearStr = secCode.substring(length - 2); try { Integer.parseInt(yearStr); identifiers.add(ExternalIdWithDates.of(identifierWithDates.toExternalId(), identifierWithDates.getValidTo().plusDays(1), null)); final StringBuilder buf = new StringBuilder(secCode.substring(0, secCode.indexOf(yearStr))); buf.append(yearStr.charAt(yearStr.length() - 1)); buf.append(identifierValue.substring(splitIndex)); final ExternalId singleYearId = ExternalSchemes.bloombergTickerSecurityId(buf.toString()); identifiers.add(ExternalIdWithDates.of(singleYearId, identifierWithDates.getValidFrom(), identifierWithDates.getValidTo())); } catch (final NumberFormatException ex) { yearStr = secCode.substring(length - 1); try { Integer.parseInt(yearStr); identifiers.add(identifierWithDates); final LocalDate validTo = identifierWithDates.getValidTo(); final String endYear = String.valueOf(validTo.getYear()); final StringBuilder buf = new StringBuilder(secCode.substring(0, secCode.indexOf(yearStr))); buf.append(endYear.substring(endYear.length() - 2)); buf.append(identifierValue.substring(splitIndex)); final ExternalId doubleDigitYearId = ExternalSchemes.bloombergTickerSecurityId(buf.toString()); identifiers.add(ExternalIdWithDates.of(doubleDigitYearId, identifierWithDates.getValidTo().plusDays(1), null)); } catch (final NumberFormatException ex2) { s_logger.warn("cannot make out year code for {}", identifier); } } } else { identifiers.add(identifierWithDates); } } return new ExternalIdBundleWithDates(identifiers); } private  BloombergDataUtils(); static Collection<NormalizationRuleSet> getDefaultNormalizationRules(final ReferenceDataProvider referenceDataProvider, final CacheManager cacheManager, ExternalScheme bbgScheme); static HistoricalTimeSeriesFieldAdjustmentMap createFieldAdjustmentMap(final ReferenceDataProvider referenceDataProvider, final CacheManager cacheManager); static MarketDataAvailabilityFilter createAvailabilityFilter(); static FudgeMsg parseElement(final Element element); static Object parseValue(final Element valueElement); static String getSingleBUID(final ReferenceDataProvider refDataProvider, final String securityDes); static Map<String, String> getBUID(final ReferenceDataProvider refDataProvider, final Set<String> bloombergKeys); static Set<String> getIndexMembers(final ReferenceDataProvider refDataProvider, final String indexTicker); static Set<ExternalId> getOptionChain(final ReferenceDataProvider refDataProvider, final String securityID); static Set<ExternalId> getFuturechain(final ReferenceDataProvider refDataProvider, final String securityID); static boolean isValidField(final String name); static ExternalIdBundleWithDates parseIdentifiers(final FudgeMsg fieldData, final String firstTradeDateField, final String lastTradeDateField); static ExternalIdBundleWithDates addTwoDigitYearCode(final ExternalIdBundleWithDates bundleWithDates); static Set<ExternalIdBundle> getCurrentIdentifiers(final PositionMaster positionMaster); static String removeDuplicateWhiteSpace(final String field, final String replacement); static Set<ExternalId> identifierLoader(final Reader reader); static BiMap<String, ExternalIdBundle> convertToBloombergBuidKeys(final Collection<ExternalIdBundle> identifiers, final ReferenceDataProvider refDataProvider); static Pair<String, String> splitTickerAtMarketSector(final String ticker); static boolean isValidBloombergTicker(final String ticker); static ExternalId generateEquityOptionTicker(final String underlyingTicker, final Expiry expiry, final OptionType optionType, final double strike); static String dateToBbgCode(final LocalDate date); static ExternalId ricToBbgFuture(final String ric); static ExternalId ricToBbgFutureOption(final String ric, final boolean isCall, final double strike, final LocalDate expiry); static ExternalId futureBundleToGenericFutureTicker(ExternalIdBundle bundle, ZonedDateTime now, OffsetTime futureExpiryTime, ZoneId futureExpiryTimeZone); static String resolveDataProvider(final String dataProvider); static String resolveObservationTime(String dataProvider); static String toBloombergDate(LocalDate localDate); static String futureMonthCode(final Month month); static final List<String> STANDARD_FIELDS_LIST; static final Set<String> STANDARD_FIELDS_SET; }
@Test public void addTwoDigitYearCode() throws Exception { Set<ExternalIdWithDates> identifiers = Sets.newHashSet( ExternalIdWithDates.of(ExternalSchemes.bloombergTickerSecurityId("EDU0 Comdty"), LocalDate.of(2010, Month.SEPTEMBER, 14), LocalDate.of(2020, Month.SEPTEMBER, 14)), ExternalIdWithDates.of(ExternalSchemes.bloombergBuidSecurityId("IX11084074-0"), null, null)); ExternalIdBundleWithDates withTwoDigits = BloombergDataUtils.addTwoDigitYearCode(new ExternalIdBundleWithDates(identifiers)); assertTrue(withTwoDigits.size() == 3); for (ExternalIdWithDates identifierWithDates : identifiers) { assertTrue(withTwoDigits.contains(identifierWithDates)); } assertTrue(withTwoDigits.contains(ExternalIdWithDates.of( ExternalSchemes.bloombergTickerSecurityId("EDU20 Comdty"), LocalDate.of(2010, Month.SEPTEMBER, 14), LocalDate.of(2020, Month.SEPTEMBER, 14)))); identifiers = Sets.newHashSet( ExternalIdWithDates.of(ExternalSchemes.bloombergTickerSecurityId("EDU09 Comdty"), LocalDate.of(1999, Month.SEPTEMBER, 14), LocalDate.of(2009, Month.SEPTEMBER, 14)), ExternalIdWithDates.of(ExternalSchemes.bloombergBuidSecurityId("IX9471080-0"), null, null)); withTwoDigits = BloombergDataUtils.addTwoDigitYearCode(new ExternalIdBundleWithDates(identifiers)); assertTrue(withTwoDigits.size() == 3); for (ExternalIdWithDates identifierWithDates : identifiers) { assertTrue(withTwoDigits.contains(identifierWithDates)); } assertTrue(withTwoDigits.contains(ExternalIdWithDates.of( ExternalSchemes.bloombergTickerSecurityId("EDU9 Comdty"), LocalDate.of(1999, Month.SEPTEMBER, 14), LocalDate.of(2009, Month.SEPTEMBER, 14)))); }