/** * Parses business day convention from the input string. * <p> * Parsing is case insensitive. * It leniently handles a variety of known variants of business day conventions. * * @param str the string to parse * @return the parsed value * @throws IllegalArgumentException if the string cannot be parsed */ public static BusinessDayConvention parseBusinessDayConvention(String str) { return BusinessDayConvention.extendedEnum().findLenient(str) .orElseThrow(() -> new IllegalArgumentException( "Unknown BusinessDayConvention value, must be one of " + BusinessDayConvention.extendedEnum().lookupAllNormalized().keySet() + " but was '" + str + "'")); }
/** * Converts an FpML business day convention string to a {@code BusinessDayConvention}. * * @param fmplBusinessDayConventionName the business day convention name used by FpML * @return the business day convention * @throws IllegalArgumentException if the business day convention is not known */ public BusinessDayConvention convertBusinessDayConvention(String fmplBusinessDayConventionName) { return BusinessDayConvention.extendedEnum().externalNames(ENUM_FPML).lookup(fmplBusinessDayConventionName); }
/** * Obtains an instance from the specified unique name. * * @param uniqueName the unique name * @return the business convention * @throws IllegalArgumentException if the name is not known */ @FromString public static BusinessDayConvention of(String uniqueName) { return extendedEnum().lookup(uniqueName); }
@Test(dataProvider = "name") public void test_extendedEnum(BusinessDayConvention convention, String name) { ImmutableMap<String, BusinessDayConvention> map = BusinessDayConvention.extendedEnum().lookupAll(); assertEquals(map.get(name), convention); }
@Test(dataProvider = "name") public void test_lenientLookup_standardNames(BusinessDayConvention convention, String name) { assertEquals(BusinessDayConvention.extendedEnum().findLenient(name.toLowerCase(Locale.ENGLISH)).get(), convention); }
@Test(dataProvider = "lenient") public void test_lenientLookup_specialNames(String name, BusinessDayConvention convention) { assertEquals(BusinessDayConvention.extendedEnum().findLenient(name.toLowerCase(Locale.ENGLISH)), Optional.of(convention)); }
.orElse(PeriodAdditionConventions.NONE); BusinessDayConvention tenorBusinessConvention = BusinessDayConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)) .orElse(isEndOfMonth(periodAdditionConvention) ? MODIFIED_FOLLOWING : FOLLOWING); BusinessDayAdjustment adj = BusinessDayAdjustment.of(tenorBusinessConvention, effectiveCal);