/** * Parses roll convention from the input string. * <p> * Parsing is case insensitive. * It leniently handles a variety of known variants of roll conventions. * * @param str the string to parse * @return the parsed value * @throws IllegalArgumentException if the string cannot be parsed */ public static RollConvention parseRollConvention(String str) { return RollConvention.extendedEnum().findLenient(str) .orElseThrow(() -> new IllegalArgumentException( "Unknown RollConvention value, must be one of " + RollConvention.extendedEnum().lookupAllNormalized().keySet() + " but was '" + str + "'")); }
public void test_ofDayOfMonth_31() { assertEquals(RollConvention.ofDayOfMonth(31), EOM); }
@Test(dataProvider = "types") public void test_null(RollConvention type) { assertThrowsIllegalArg(() -> type.adjust(null)); assertThrowsIllegalArg(() -> type.matches(null)); assertThrowsIllegalArg(() -> type.next(date(2014, JULY, 1), null)); assertThrowsIllegalArg(() -> type.next(null, P3M)); assertThrowsIllegalArg(() -> type.previous(date(2014, JULY, 1), null)); assertThrowsIllegalArg(() -> type.previous(null, P3M)); }
public void test_ofDayOfMonth_matches_Day29() { assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2016, JANUARY, 30)), false); assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2016, JANUARY, 29)), true); assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2016, JANUARY, 30)), false); assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2016, FEBRUARY, 28)), false); assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2016, FEBRUARY, 29)), true); assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2015, FEBRUARY, 27)), false); assertEquals(RollConvention.ofDayOfMonth(29).matches(date(2015, FEBRUARY, 28)), true); }
public void test_ofDayOfWeek_matches() { assertEquals(RollConvention.ofDayOfWeek(TUESDAY).matches(date(2014, SEPTEMBER, 1)), false); assertEquals(RollConvention.ofDayOfWeek(TUESDAY).matches(date(2014, SEPTEMBER, 2)), true); assertEquals(RollConvention.ofDayOfWeek(TUESDAY).matches(date(2014, SEPTEMBER, 3)), false); }
public void test_ofDayOfMonth() { for (int i = 1; i < 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); assertEquals(test.adjust(date(2014, JULY, 1)), date(2014, JULY, i)); assertEquals(test.getName(), "Day" + i); assertEquals(test.toString(), "Day" + i); assertSame(RollConvention.of(test.getName()), test); assertSame(RollConvention.of("DAY" + i), test); } }
public void test_ofDayOfMonth_next_oneMonth() { for (int start = 1; start <= 5; start++) { for (int i = 1; i <= 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); LocalDate expected = date(2014, AUGUST, i); assertEquals(test.next(date(2014, JULY, start), P1M), expected); } } }
public void test_ofDayOfMonth_previous_oneMonth() { for (int start = 1; start <= 5; start++) { for (int i = 1; i <= 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); LocalDate expected = date(2014, JUNE, i); assertEquals(test.previous(date(2014, JULY, start), P1M), expected); } } }
public void test_ofDayOfMonth_adjust_Day30() { assertEquals(RollConvention.ofDayOfMonth(30).adjust(date(2014, FEBRUARY, 2)), date(2014, FEBRUARY, 28)); assertEquals(RollConvention.ofDayOfMonth(30).adjust(date(2016, FEBRUARY, 2)), date(2016, FEBRUARY, 29)); }
private static RollConvention impliedRollConvention( LocalDate date, LocalDate otherDate, Frequency frequency, boolean preferEndOfMonth) { if (frequency.isMonthBased()) { if (preferEndOfMonth && date.getDayOfMonth() == date.lengthOfMonth()) { return RollConventions.EOM; } return RollConvention.ofDayOfMonth(date.getDayOfMonth()); } else if (frequency.isWeekBased()) { return RollConvention.ofDayOfWeek(date.getDayOfWeek()); } else { // neither monthly nor weekly means no known roll convention return RollConventions.NONE; } }
public void test_ofDayOfWeek_next_oneDay() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.next(date(2014, AUGUST, 14), P1D), date(2014, AUGUST, 15).with(TemporalAdjusters.nextOrSame(dow))); } }
public void test_ofDayOfWeek_previous_oneMonth() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.previous(date(2014, AUGUST, 14), P1W), date(2014, AUGUST, 7).with(TemporalAdjusters.previousOrSame(dow))); } }
/** * Checks if this period is regular according to the specified frequency and roll convention. * <p> * A schedule period is normally created from a frequency and roll convention. * These can therefore be used to determine if the period is regular, which simply * means that the period end date can be generated from the start date and vice versa. * * @param frequency the frequency * @param rollConvention the roll convention * @return true if the period is regular */ public boolean isRegular(Frequency frequency, RollConvention rollConvention) { ArgChecker.notNull(frequency, "frequency"); ArgChecker.notNull(rollConvention, "rollConvention"); return rollConvention.next(unadjustedStartDate, frequency).equals(unadjustedEndDate) && rollConvention.previous(unadjustedEndDate, frequency).equals(unadjustedStartDate); }
if (rollConv.matches(start) == false) { throw new ScheduleException( schedule, "Date '{}' does not match roll convention '{}' when starting to roll forwards", start, rollConv); LocalDate temp = rollConv.next(start, frequency); while (temp.isBefore(end)) { dates.add(temp); temp = rollConv.next(temp, frequency);
public void test_ofDayOfWeek() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals(test.getName(), "Day" + CaseFormat.UPPER_UNDERSCORE.converterTo(CaseFormat.UPPER_CAMEL).convert(dow.toString()).substring(0, 3)); assertEquals(test.toString(), "Day" + CaseFormat.UPPER_UNDERSCORE.converterTo(CaseFormat.UPPER_CAMEL).convert(dow.toString()).substring(0, 3)); assertSame(RollConvention.of(test.getName()), test); assertSame(RollConvention.of("DAY" + dow.toString().substring(0, 3)), test); } }
@Test(dataProvider = "adjust") public void test_adjust(RollConvention conv, LocalDate input, LocalDate expected) { assertEquals(conv.adjust(input), expected); }
public void test_ofDayOfWeek_adjust() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.adjust(date(2014, AUGUST, 14)), date(2014, AUGUST, 14).with(TemporalAdjusters.nextOrSame(dow))); } }
private static List<LocalDate> generateBackwards( PeriodicSchedule schedule, LocalDate start, LocalDate end, Frequency frequency, RollConvention rollConv, StubConvention stubConv, LocalDate explicitStartDate) { // validate if (rollConv.matches(end) == false) { throw new ScheduleException( schedule, "Date '{}' does not match roll convention '{}' when starting to roll backwards", end, rollConv); } // generate BackwardsList dates = new BackwardsList(estimateNumberPeriods(start, end, frequency)); dates.addFirst(end); LocalDate temp = rollConv.previous(end, frequency); while (temp.isAfter(start)) { dates.addFirst(temp); temp = rollConv.previous(temp, frequency); } // convert to long stub, but only if we actually have a stub boolean stub = temp.equals(start) == false; if (stub && dates.size() > 1 && stubConv.isStubLong(start, dates.get(0))) { dates.removeFirst(); } dates.addFirst(explicitStartDate); return dates; }
ReferenceData refData) { int rollDom = rollConvention.getDayOfMonth(); LocalDate rollImpliedDate = rollConvention.adjust(baseDate);