<commit_before>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.conversion;

import com.opengamma.analytics.financial.instrument.index.IborIndex;
import com.opengamma.core.holiday.HolidaySource;
import com.opengamma.core.region.RegionSource;
import com.opengamma.financial.convention.ConventionSource;
import com.opengamma.financial.convention.IborIndexConvention;
import com.opengamma.financial.convention.calendar.Calendar;
import com.opengamma.financial.convention.percurrency.PerCurrencyConventionHelper;
import com.opengamma.financial.security.FinancialSecurity;
import com.opengamma.financial.security.FinancialSecurityVisitor;
import com.opengamma.financial.security.FinancialSecurityVisitorAdapter;
import com.opengamma.financial.security.fra.FRASecurity;
import com.opengamma.financial.security.swap.SwapSecurity;
import com.opengamma.util.money.Currency;

/**
 * 
 */
public class IborIndexConverter {
  private final ConventionSource _conventionSource;
  private final RegionSource _regionSource;
  private final HolidaySource _holidaySource;
  private final FinancialSecurityVisitor<IborIndex> _visitor = new MyVisitor();

  public IborIndexConverter(final ConventionSource conventionSource, final RegionSource regionSource, final HolidaySource holidaySource) {
    _conventionSource = conventionSource;
    _regionSource = regionSource;
    _holidaySource = holidaySource;
  }

  public IborIndex getConvention(final FinancialSecurity security, final ConventionSource conventionSource) {
    return security.accept(_visitor);
  }

  private class MyVisitor extends FinancialSecurityVisitorAdapter<IborIndex> {

    public MyVisitor() {
    }

    @Override
    public IborIndex visitFRASecurity(final FRASecurity security) {
      final Currency currency = security.getCurrency();
      final String conventionName = PerCurrencyConventionHelper.getConventionName(currency, PerCurrencyConventionHelper.VANILLA_IBOR_LEG);
      final IborIndexConvention convention = _conventionSource.getIborIndexConvention(PerCurrencyConventionHelper.simpleNameId(null));
      final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, convention.getRegionCalendar());
      return new IborIndex(currency, convention.getTenor().getPeriod(), convention.getDaysToSettle(), calendar, convention.getDayCount(),
          convention.getBusinessDayConvention(), convention.isIsEOM());
    }

    @Override
    public IborIndex visitSwapSecurity(final SwapSecurity security) {
      return null;
      //      return new IborIndex(currency, convention.getTenor().getPeriod(), convention.getDaysToSettle(), calendar, convention.getDayCount(),
      //          convention.getBusinessDayConvention(), convention.isIsEOM());
    }
  }
}<commit_msg>Forgot to add this file<commit_after>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.conversion;

import com.opengamma.analytics.financial.instrument.index.IborIndex;
import com.opengamma.core.holiday.HolidaySource;
import com.opengamma.core.region.RegionSource;
import com.opengamma.financial.convention.ConventionSource;
import com.opengamma.financial.convention.IborIndexConvention;
import com.opengamma.financial.convention.calendar.Calendar;
import com.opengamma.financial.convention.percurrency.PerCurrencyConventionHelper;
import com.opengamma.financial.security.FinancialSecurity;
import com.opengamma.financial.security.FinancialSecurityVisitor;
import com.opengamma.financial.security.FinancialSecurityVisitorAdapter;
import com.opengamma.financial.security.fra.FRASecurity;
import com.opengamma.financial.security.swap.SwapSecurity;
import com.opengamma.util.money.Currency;

/**
 * 
 */
public class IborIndexConverter {
  private final ConventionSource _conventionSource;
  private final RegionSource _regionSource;
  private final HolidaySource _holidaySource;
  private final FinancialSecurityVisitor<IborIndex> _visitor = new MyVisitor();

  public IborIndexConverter(final ConventionSource conventionSource, final RegionSource regionSource, final HolidaySource holidaySource) {
    _conventionSource = conventionSource;
    _regionSource = regionSource;
    _holidaySource = holidaySource;
  }

  public IborIndex getConvention(final FinancialSecurity security, final ConventionSource conventionSource) {
    return security.accept(_visitor);
  }

  private class MyVisitor extends FinancialSecurityVisitorAdapter<IborIndex> {

    public MyVisitor() {
    }

    @Override
    public IborIndex visitFRASecurity(final FRASecurity security) {
      final Currency currency = security.getCurrency();
      final String conventionName = PerCurrencyConventionHelper.getConventionName(currency, PerCurrencyConventionHelper.VANILLA_IBOR_LEG);
      final IborIndexConvention convention = _conventionSource.getIborIndexConvention(PerCurrencyConventionHelper.simpleNameId(null));
      final Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, convention.getRegionCalendar());
      return new IborIndex(currency, null, convention.getDaysToSettle(), calendar, convention.getDayCount(),
          convention.getBusinessDayConvention(), convention.isIsEOM());
    }

    @Override
    public IborIndex visitSwapSecurity(final SwapSecurity security) {
      return null;
      //      return new IborIndex(currency, convention.getTenor().getPeriod(), convention.getDaysToSettle(), calendar, convention.getDayCount(),
      //          convention.getBusinessDayConvention(), convention.isIsEOM());
    }
  }
}
{'fraction_non_alphanumeric': 0.08120770432066632, 'fraction_numerical': 0.0013881658858233559, 'mean_word_length': 5.648212226066898, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3529159', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1541, 'n_words': 308}