private static ImmutableMap<CurrencyPair, Integer> parsePairs(IniFile ini) { ImmutableMap.Builder<CurrencyPair, Integer> builder = ImmutableMap.builder(); for (Entry<String, PropertySet> entry : ini.asMap().entrySet()) { String pairStr = entry.getKey(); if (CurrencyPair.REGEX_FORMAT.matcher(pairStr).matches()) { CurrencyPair pair = CurrencyPair.parse(pairStr); PropertySet properties = entry.getValue(); Integer rateDigits = Integer.parseInt(properties.value("rateDigits")); builder.put(pair, rateDigits); } } return builder.build(); }
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(); }
public void test_ofChained_chainToNowhere() { IniFile test = ResourceConfig.combinedIniFile("TestChain3.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "x", "b", "y"); assertEquals(test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1))); }
for (String sectionName : file.asMap().keySet()) { if (!sectionName.equals(CHAIN_SECTION)) { sectionMap.merge(sectionName, file.section(sectionName), PropertySet::overrideWith);
public void test_of_escaping() { IniFile test = IniFile.of(CharSource.wrap(INI4)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a=d=", "x"); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); }
public void test_ofChained_chainRemoveSections() { IniFile test = ResourceConfig.combinedIniFile("TestChain5.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "a"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("m", "n", "o", "z"); assertEquals( test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1), "two", PropertySet.of(keyValues2))); }
public void test_ofChained_chainNextFileTrue() { IniFile test = ResourceConfig.combinedIniFile("TestChain1.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "z", "b", "y"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("m", "n"); assertEquals( test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1), "two", PropertySet.of(keyValues2))); }
public void test_ofChained_autoChain() { IniFile test = ResourceConfig.combinedIniFile("TestChain4.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "z", "b", "y"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("m", "n"); assertEquals( test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1), "two", PropertySet.of(keyValues2))); }
public void test_ofChained_chainNextFileFalse() { IniFile test = ResourceConfig.combinedIniFile("TestChain2.ini"); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "z"); Multimap<String, String> keyValues2 = ImmutableListMultimap.of("m", "n"); assertEquals( test.asMap(), ImmutableMap.of("one", PropertySet.of(keyValues1), "two", PropertySet.of(keyValues2))); }
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]}}"); }
Multimap<String, String> keyValues2 = ImmutableListMultimap.of("a", "m", "b", "n"); assertEquals( test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1), "name", PropertySet.of(keyValues2)));