private static ImmutableMap<String, ImmutableMap<String, String>> parseExternals(IniFile config) { ImmutableMap.Builder<String, ImmutableMap<String, String>> builder = ImmutableMap.builder(); for (String sectionName : config.sections()) { if (sectionName.startsWith(EXTERNALS_SECTION)) { String group = sectionName.substring(EXTERNALS_SECTION.length()); builder.put(group, config.section(sectionName).asMap()); } } return builder.build(); }
private static ImmutableMap<String, FloatingRateName> parseIndices(IniFile ini) { HashMap<String, ImmutableFloatingRateName> map = new HashMap<>(); parseSection(ini.section("ibor"), "-", FloatingRateType.IBOR, map); parseFixingDateOffset(ini.section("iborFixingDateOffset"), map); parseSection(ini.section("overnightCompounded"), "", FloatingRateType.OVERNIGHT_COMPOUNDED, map); parseSection(ini.section("overnightAveraged"), "", FloatingRateType.OVERNIGHT_AVERAGED, map); parseSection(ini.section("price"), "", FloatingRateType.PRICE, map); return ImmutableMap.copyOf(map); }
private static ImmutableMap<String, String> parseAlternates(IniFile config) { if (!config.contains(ALTERNATES_SECTION)) { return ImmutableMap.of(); } Map<String, String> alternates = new HashMap<>(); for (Entry<String, String> entry : config.section(ALTERNATES_SECTION).asMap().entrySet()) { alternates.put(entry.getKey(), entry.getValue()); alternates.putIfAbsent(entry.getKey().toUpperCase(Locale.ENGLISH), entry.getValue()); } return ImmutableMap.copyOf(alternates); }
@Override public TradeReportTemplate load(IniFile iniFile) { List<TradeReportColumn> reportColumns = new ArrayList<TradeReportColumn>(); for (String columnName : iniFile.sections()) { if (columnName.toLowerCase(Locale.ENGLISH).equals(SETTINGS_SECTION)) { continue; } PropertySet properties = iniFile.section(columnName); reportColumns.add(parseColumn(columnName, properties)); } return TradeReportTemplate.builder() .columns(reportColumns) .build(); }
private static ImmutableList<Pair<Pattern, String>> parseLenientPatterns(IniFile config) { if (!config.contains(LENIENT_PATTERNS_SECTION)) { return ImmutableList.of(); } List<Pair<Pattern, String>> alternates = new ArrayList<>(); for (Entry<String, String> entry : config.section(LENIENT_PATTERNS_SECTION).asMap().entrySet()) { alternates.add(Pair.of(Pattern.compile(entry.getKey(), Pattern.CASE_INSENSITIVE), entry.getValue())); } return ImmutableList.copyOf(alternates); }
@VisibleForTesting static ImmutableMap<String, HolidayCalendar> loadFromIni(String filename) { List<ResourceLocator> resources = ResourceConfig.orderedResources(filename); Map<String, HolidayCalendar> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { IniFile ini = IniFile.of(resource.getCharSource()); for (String sectionName : ini.sections()) { PropertySet section = ini.section(sectionName); HolidayCalendar parsed = parseHolidayCalendar(sectionName, section); map.put(parsed.getName(), parsed); map.putIfAbsent(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Holiday Calendar INI file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
private static ImmutableMap<Currency, FloatingRateName> parseIborDefaults( IniFile ini, ImmutableMap<String, FloatingRateName> names) { ImmutableMap.Builder<Currency, FloatingRateName> map = ImmutableMap.builder(); PropertySet section = ini.section("currencyDefaultIbor"); for (String key : section.keys()) { FloatingRateName frname = names.get(section.value(key)); if (frname == null) { throw new IllegalArgumentException("Invalid default Ibor index for currency " + key); } map.put(Currency.of(key), frname); } return map.build(); }
/** * 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(Locale.ENGLISH).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().equalsIgnoreCase(reportType)) .findFirst() .orElseThrow(() -> new IllegalArgumentException(Messages.format("Unsupported report type: {}", reportType))); return iniLoader.load(iniFile); }
private static ImmutableMap<Currency, FloatingRateName> parseOvernightDefaults( IniFile ini, ImmutableMap<String, FloatingRateName> names) { ImmutableMap.Builder<Currency, FloatingRateName> map = ImmutableMap.builder(); PropertySet section = ini.section("currencyDefaultOvernight"); for (String key : section.keys()) { FloatingRateName frname = names.get(section.value(key)); if (frname == null) { throw new IllegalArgumentException("Invalid default Overnight index for currency " + key); } map.put(Currency.of(key), frname); } return map.build(); } }
return ImmutableList.of(); PropertySet section = config.section(TYPES_SECTION); ImmutableList.Builder<ExtendedEnum<? extends R>> builder = ImmutableList.builder(); for (String key : section.keys()) {
try { IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(CURRENCY_DATA_INI)); PropertySet section = ini.section("marketConventionPriority"); String list = section.value("ordering");
return ImmutableList.of(); PropertySet section = config.section(PROVIDERS_SECTION); ImmutableList.Builder<NamedLookup<R>> builder = ImmutableList.builder(); for (String key : section.keys()) {
@VisibleForTesting static ImmutableMap<Currency, HolidayCalendarId> loadDefaultsFromIni(String filename) { List<ResourceLocator> resources = ResourceConfig.orderedResources(filename); Map<Currency, HolidayCalendarId> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { IniFile ini = IniFile.of(resource.getCharSource()); PropertySet section = ini.section("defaultByCurrency"); for (String currencyCode : section.keys()) { map.put(Currency.of(currencyCode), HolidayCalendarId.of(section.value(currencyCode))); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Holiday Calendar Defaults INI file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
public void test_equalsHashCode_section() { IniFile a1 = IniFile.of(CharSource.wrap(INI1)); IniFile a2 = IniFile.of(CharSource.wrap(INI1)); IniFile b = IniFile.of(CharSource.wrap(INI2)); assertEquals(a1.section("name").equals(a1.section("name")), true); assertEquals(a1.section("name").equals(a2.section("name")), true); assertEquals(a1.section("name").equals(b.section("section")), false); assertEquals(a1.section("name").equals(null), false); assertEquals(a1.section("name").equals(ANOTHER_TYPE), false); assertEquals(a1.section("name").hashCode(), a2.section("name").hashCode()); }
public void test_of_list() { IniFile test = IniFile.of(CharSource.wrap(INI3)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "x", "a", "y"); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("a"), true); assertThrowsIllegalArg(() -> test.section("section").value("a")); assertEquals(test.section("section").valueList("a"), ImmutableList.of("x", "y")); assertEquals(test.section("section").contains("b"), false); assertEquals(test.section("section").keys(), ImmutableSet.of("a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "x", "a", "y")); assertEquals(test.toString(), "{section={a=[x, y]}}"); }
public void test_of_propertyNoEquals() { IniFile test = IniFile.of(CharSource.wrap("[section]\na\n")); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", ""); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("a"), true); assertEquals(test.section("section").valueList("a"), ImmutableList.of("")); assertEquals(test.section("section").contains("b"), false); assertEquals(test.section("section").keys(), ImmutableSet.of("a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "")); assertEquals(test.toString(), "{section={a=[]}}"); }
assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("c"), true); assertEquals(test.section("section").value("c"), "x"); assertEquals(test.section("section").valueList("c"), ImmutableList.of("x")); assertEquals(test.section("section").contains("b"), true); assertEquals(test.section("section").value("b"), "y"); assertEquals(test.section("section").valueList("b"), ImmutableList.of("y")); assertEquals(test.section("section").contains("a"), true); assertEquals(test.section("section").value("a"), "z"); assertEquals(test.section("section").valueList("a"), ImmutableList.of("z")); assertEquals(test.section("section").contains("d"), false); assertEquals(ImmutableList.copyOf(test.section("section").keys()), ImmutableList.of("c", "b", "a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("c", "x", "b", "y", "a", "z")); assertEquals(test.section("name"), PropertySet.of(keyValues2)); assertEquals(test.section("name").contains("a"), true); assertEquals(test.section("name").value("a"), "m"); assertEquals(test.section("name").valueList("a"), ImmutableList.of("m")); assertEquals(test.section("name").contains("b"), true); assertEquals(test.section("name").value("b"), "n"); assertEquals(test.section("name").valueList("b"), ImmutableList.of("n")); assertEquals(test.section("name").contains("c"), false); assertEquals(ImmutableList.copyOf(test.section("name").keys()), ImmutableList.of("a", "b")); assertEquals(test.section("name").asMultimap(), ImmutableListMultimap.of("a", "m", "b", "n")); assertThrowsIllegalArg(() -> test.section("unknown")); assertEquals(test.section("section").valueList("unknown"), ImmutableList.of()); assertThrowsIllegalArg(() -> test.section("section").value("unknown"));