/** * Loads a report template from an .ini file. * * @param iniFile the .ini file containing the definition of a report template * @return the template defined in the .ini file * @throws RuntimeException if the ini file cannot be parsed */ public static ReportTemplate load(IniFile iniFile) { String settingsSectionKey = iniFile .sections() .stream() .filter(k -> k.toLowerCase().equals(ReportTemplateIniLoader.SETTINGS_SECTION)) .findFirst() .orElseThrow( () -> new IllegalArgumentException( Messages.format( "Report template INI file must contain a {} section", ReportTemplateIniLoader.SETTINGS_SECTION))); PropertySet settingsSection = iniFile.section(settingsSectionKey); String reportType = settingsSection.value(ReportTemplateIniLoader.SETTINGS_REPORT_TYPE); ReportTemplateIniLoader<? extends ReportTemplate> iniLoader = LOADERS .stream() .filter(loader -> loader.getReportType().toLowerCase().equals(reportType.toLowerCase())) .findFirst() .orElseThrow( () -> new IllegalArgumentException( Messages.format("Unsupported report type: {}", reportType))); return iniLoader.load(iniFile); }
// parse the config file FloatingRateName.ini private static ImmutableMap<String, FloatingRateName> parseIndices(IniFile ini) { ImmutableMap.Builder<String, FloatingRateName> builder = ImmutableMap.builder(); parseSection(ini.section("ibor"), "-", FloatingRateType.IBOR, builder); parseSection( ini.section("overnightCompounded"), "", FloatingRateType.OVERNIGHT_COMPOUNDED, builder); parseSection( ini.section("overnightAveraged"), "", FloatingRateType.OVERNIGHT_AVERAGED, builder); parseSection(ini.section("price"), "", FloatingRateType.PRICE, builder); return builder.build(); }