TenorUtils { public static Tenor plus(final Tenor tenor1, final Tenor tenor2) { if ((!tenor1.isBusinessDayTenor()) && (!tenor2.isBusinessDayTenor())) { return Tenor.of(tenor1.getPeriod().plus(tenor2.getPeriod())); } if (tenor1.equals(Tenor.of(Period.ZERO))) { return tenor2; } if (tenor2.equals(Tenor.of(Period.ZERO))) { return tenor1; } if ((tenor1.equals(Tenor.ON)) && (tenor1.equals(Tenor.ON))) { return Tenor.TN; } throw new IllegalArgumentException("Can not add " + tenor1 + " and " + tenor2); }  static ZonedDateTime adjustDateByTenor(final ZonedDateTime date, final Tenor tenor); static LocalDateTime adjustDateByTenor(final LocalDateTime date, final Tenor tenor); static LocalDate adjustDateByTenor(final LocalDate date, final Tenor tenor); static ZonedDateTime adjustDateByTenor(final ZonedDateTime date, final Tenor tenor, final Calendar calendar, final int spotDays); static LocalDateTime adjustDateByTenor(final LocalDateTime date, final Tenor tenor, final Calendar calendar, final int spotDays); static LocalDate adjustDateByTenor(final LocalDate date, final Tenor tenor, final Calendar calendar, final int spotDays); static Tenor plus(final Tenor tenor1, final Tenor tenor2);  }
@Test public void plus() { final Tenor d1 = Tenor.ONE_DAY; final Tenor d2 = Tenor.TWO_DAYS; final Tenor w1 = Tenor.ONE_WEEK; final Tenor m1 = Tenor.ONE_MONTH; final Tenor y3 = Tenor.THREE_YEARS; final Tenor on = Tenor.ON; final Tenor tn = Tenor.TN; final Tenor pZ = Tenor.of(Period.ZERO); final Tenor p0D = Tenor.of(Period.ofDays(0)); assertEquals("Tenor: plus", d2, TenorUtils.plus(d1, d1)); assertEquals("Tenor: plus", Tenor.of(Period.ofDays(8)), TenorUtils.plus(d1, w1)); assertEquals("Tenor: plus", Tenor.of(Period.of(3, 1, 0)), TenorUtils.plus(m1, y3)); assertEquals("Tenor: plus", Tenor.of(Period.of(3, 1, 0)), TenorUtils.plus(y3, m1)); assertEquals("Tenor: plus", tn, TenorUtils.plus(on, on)); assertEquals("Tenor: plus", pZ, p0D); assertEquals("Tenor: plus", y3, TenorUtils.plus(pZ, y3)); assertEquals("Tenor: plus", y3, TenorUtils.plus(y3, pZ)); assertEquals("Tenor: plus", y3, TenorUtils.plus(y3, p0D)); }