MultiSwapLegVisitor { public Pair<T, T> visit(final SwapSecurity swap) { final FixedFloatVisitor fixedFloatVisitor = new FixedFloatVisitor(); final SwapLeg payLeg = swap.getPayLeg(); final SwapLeg receiveLeg = swap.getReceiveLeg(); final boolean payFixed = payLeg.accept(fixedFloatVisitor); final boolean receiveFixed = receiveLeg.accept(fixedFloatVisitor); T firstValue; T secondValue; if (payFixed && receiveFixed) { firstValue = payLeg.accept(new FixedVisitor()); secondValue = receiveLeg.accept(new FixedVisitor()); return Pairs.of(firstValue, secondValue); } if (payFixed) { firstValue = payLeg.accept(new FixedVisitor()); secondValue = receiveLeg.accept(new OtherVisitor()); } else if (receiveFixed) { firstValue = receiveLeg.accept(new FixedVisitor()); secondValue = payLeg.accept(new OtherVisitor()); } else { firstValue = payLeg.accept(new FloatingPayVisitor()); secondValue = receiveLeg.accept(new OtherVisitor()); } return Pairs.of(firstValue, secondValue); }  Pair<T, T> visit(final SwapSecurity swap);  }
@Test public void payFixed() { final Frequency annual = SimpleFrequency.ANNUAL; final Frequency quarterly = SimpleFrequency.QUARTERLY; final SwapSecurity swap = swap(fixedLeg(annual), floatingLeg(quarterly)); final Pair<Frequency, Frequency> frequencies = new FrequencyVisitor().visit(swap); final Pair<Frequency, Frequency> expected = Pairs.of(annual, quarterly); assertEquals(expected, frequencies); }
@Test public void receiveFixed() { final Frequency annual = SimpleFrequency.ANNUAL; final Frequency quarterly = SimpleFrequency.QUARTERLY; final SwapSecurity swap = swap(floatingLeg(quarterly), fixedLeg(annual)); final Pair<Frequency, Frequency> frequencies = new FrequencyVisitor().visit(swap); final Pair<Frequency, Frequency> expected = Pairs.of(annual, quarterly); assertEquals(expected, frequencies); }
@Test public void floatFloat() { final Frequency annual = SimpleFrequency.ANNUAL; final Frequency quarterly = SimpleFrequency.QUARTERLY; final SwapSecurity swap = swap(floatingLeg(annual), floatingLeg(quarterly)); final Pair<Frequency, Frequency> frequencies = new FrequencyVisitor().visit(swap); final Pair<Frequency, Frequency> expected = Pairs.of(annual, quarterly); assertEquals(expected, frequencies); }
@Test public void inflationFixedFloat() { final Frequency annual = SimpleFrequency.ANNUAL; final Frequency quarterly = SimpleFrequency.QUARTERLY; final ZeroCouponInflationSwapSecurity swap = zciSwap(fixedInflationLeg(annual), indexInflationLeg(quarterly)); final Pair<Frequency, Frequency> frequencies = new FrequencyVisitor().visit(swap); final Pair<Frequency, Frequency> expected = Pairs.of(annual, quarterly); assertEquals(expected, frequencies); }
@Test public void inflationFloatFloat() { final Frequency annual = SimpleFrequency.ANNUAL; final Frequency quarterly = SimpleFrequency.QUARTERLY; final ZeroCouponInflationSwapSecurity swap = zciSwap(indexInflationLeg(annual), indexInflationLeg(quarterly)); final Pair<Frequency, Frequency> frequencies = new FrequencyVisitor().visit(swap); final Pair<Frequency, Frequency> expected = Pairs.of(annual, quarterly); assertEquals(expected, frequencies); }