/** * Returns the property set as a map, throwing an exception if any key has multiple values. * <p> * The iteration order of the map matches that of the input data. * * @return the key-value map */ public ImmutableMap<String, String> asMap() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); for (String key : keys()) { builder.put(key, value(key)); } return builder.build(); }
private static void parseFixingDateOffset(PropertySet section, HashMap<String, ImmutableFloatingRateName> mutableMap) { // find our names from the RHS of the key/value pairs for (String key : section.keys()) { Integer days = Integer.parseInt(section.value(key)); ImmutableFloatingRateName name = mutableMap.get(key.toUpperCase(Locale.ENGLISH)); ImmutableFloatingRateName updated = name.toBuilder().fixingDateOffsetDays(days).build(); mutableMap.put(key.toUpperCase(Locale.ENGLISH), updated); } }
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(); }
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(); } }
private static void parseSection( PropertySet section, String indexNameSuffix, FloatingRateType type, HashMap<String, ImmutableFloatingRateName> mutableMap) { // find our names from the RHS of the key/value pairs for (String key : section.keys()) { ImmutableFloatingRateName name = ImmutableFloatingRateName.of(key, section.value(key) + indexNameSuffix, type); mutableMap.put(key, name); mutableMap.putIfAbsent(key.toUpperCase(Locale.ENGLISH), name); } }
private static ImmutableMap<String, Currency> parseCurrencies(IniFile ini, boolean loadHistoric) { ImmutableMap.Builder<String, Currency> builder = ImmutableMap.builder(); for (Entry<String, PropertySet> entry : ini.asMap().entrySet()) { String currencyCode = entry.getKey(); if (currencyCode.length() == 3 && Currency.CODE_MATCHER.matchesAllOf(currencyCode)) { PropertySet properties = entry.getValue(); boolean isHistoric = (properties.keys().contains("historic") && Boolean.parseBoolean(properties.value("historic"))); if (isHistoric == loadHistoric) { int minorUnits = Integer.parseInt(properties.value("minorUnitDigits")); String triangulationCurrency = properties.value("triangulationCurrency"); builder.put(currencyCode, new Currency(currencyCode, minorUnits, triangulationCurrency)); } } } return builder.build(); }
for (String key : section.keys()) { Class<?> cls; try {
for (String key : section.keys()) { Class<?> cls; try {
private static HolidayCalendar parseHolidayCalendar(String calendarName, PropertySet section) { String weekendStr = section.value(WEEKEND_KEY); Set<DayOfWeek> weekends = parseWeekends(weekendStr); List<LocalDate> holidays = new ArrayList<>(); for (String key : section.keys()) { if (key.equals(WEEKEND_KEY)) { continue; } String value = section.value(key); if (key.length() == 4) { int year = Integer.parseInt(key); holidays.addAll(parseYearDates(year, value)); } else { holidays.add(LocalDate.parse(key)); } } // build result return ImmutableHolidayCalendar.of(HolidayCalendarId.of(calendarName), holidays, weekends); }
@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_of_map() { Map<String, String> keyValues = ImmutableMap.of("a", "x", "b", "y"); PropertySet test = PropertySet.of(keyValues); assertEquals(test.isEmpty(), false); assertEquals(test.contains("a"), true); assertEquals(test.value("a"), "x"); assertEquals(test.valueList("a"), ImmutableList.of("x")); assertEquals(test.contains("b"), true); assertEquals(test.value("b"), "y"); assertEquals(test.valueList("b"), ImmutableList.of("y")); assertEquals(test.contains("c"), false); assertEquals(test.keys(), ImmutableSet.of("a", "b")); assertEquals(test.asMap(), ImmutableMap.of("a", "x", "b", "y")); assertEquals(test.asMultimap(), ImmutableListMultimap.of("a", "x", "b", "y")); assertEquals(test.valueList("unknown"), ImmutableSet.of()); assertThrowsIllegalArg(() -> test.value("unknown")); assertEquals(test.toString(), "{a=[x], b=[y]}"); }
public void test_of_multimap() { Multimap<String, String> keyValues = ImmutableMultimap.of("a", "x", "a", "y", "b", "z"); PropertySet test = PropertySet.of(keyValues); assertEquals(test.isEmpty(), false); assertEquals(test.contains("a"), true); assertThrowsIllegalArg(() -> test.value("a")); assertEquals(test.valueList("a"), ImmutableList.of("x", "y")); assertEquals(test.contains("b"), true); assertEquals(test.value("b"), "z"); assertEquals(test.valueList("b"), ImmutableList.of("z")); assertEquals(test.contains("c"), false); assertEquals(test.keys(), ImmutableSet.of("a", "b")); assertEquals(test.asMultimap(), ImmutableListMultimap.of("a", "x", "a", "y", "b", "z")); assertEquals(test.valueList("unknown"), ImmutableSet.of()); assertThrowsIllegalArg(() -> test.asMap()); assertThrowsIllegalArg(() -> test.value("unknown")); assertEquals(test.toString(), "{a=[x, y], b=[z]}"); }
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=[]}}"); }
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]}}"); }
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").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"));