class DispatchingSwapPaymentPeriodPricer implements SwapPaymentPeriodPricer<SwapPaymentPeriod> {

  @Override
  public double presentValue(SwapPaymentPeriod paymentPeriod, RatesProvider provider) {
    // dispatch by runtime type
    if (paymentPeriod instanceof RatePaymentPeriod) {
      return ratePaymentPeriodPricer.presentValue((RatePaymentPeriod) paymentPeriod, provider);
    } else if (paymentPeriod instanceof KnownAmountSwapPaymentPeriod) {
      return knownAmountPaymentPeriodPricer.presentValue((KnownAmountSwapPaymentPeriod) paymentPeriod, provider);
    } else {
      throw new IllegalArgumentException("Unknown PaymentPeriod type: " + paymentPeriod.getClass().getSimpleName());
    }
  }

  public  DispatchingSwapPaymentPeriodPricer(
      SwapPaymentPeriodPricer<RatePaymentPeriod> ratePaymentPeriodPricer,
      SwapPaymentPeriodPricer<KnownAmountSwapPaymentPeriod> knownAmountPaymentPeriodPricer);

}