class ProviderUtils {

  public static MulticurveProviderDiscount mergeDiscountingProviders(final Collection<MulticurveProviderDiscount> providers) {
    ArgumentChecker.notNull(providers, "providers");
    ArgumentChecker.notEmpty(providers, "providers");
    final MulticurveProviderDiscount result = new MulticurveProviderDiscount();
    FXMatrix matrix = new FXMatrix();
    int loop = 0;
    for (final MulticurveProviderDiscount provider : providers) {
      for (final Map.Entry<Currency, YieldAndDiscountCurve> entry : provider.getDiscountingCurves().entrySet()) {
        result.setCurve(entry.getKey(), entry.getValue());
      }
      for (final Map.Entry<IborIndex, YieldAndDiscountCurve> entry : provider.getForwardIborCurves().entrySet()) {
        result.setCurve(entry.getKey(), entry.getValue());
      }
      for (final Map.Entry<IndexON, YieldAndDiscountCurve> entry : provider.getForwardONCurves().entrySet()) {
        result.setCurve(entry.getKey(), entry.getValue());
      }
      if (loop == 0) {
        matrix = new FXMatrix(provider.getFxRates());
        loop++;
      } else {
        matrix = FXMatrixUtils.merge(matrix, provider.getFxRates());
      }
    }
    result.setForexMatrix(matrix);
    return result;
  }

}