/** * Returns a combined INI file formed by merging INI files with the specified name. * <p> * This finds the all files with the specified name in the configuration directories. * Each file is loaded, with the result being formed by merging the files into one. * See {@link #combinedIniFile(List)} for more details on the merge process. * * @param resourceName the resource name * @return the resource locators * @throws UncheckedIOException if an IO exception occurs * @throws IllegalStateException if there is a configuration error */ public static IniFile combinedIniFile(String resourceName) { ArgChecker.notNull(resourceName, "resourceName"); return ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(resourceName)); }
/** * Obtains an ordered list of resource locators. * <p> * This finds the all files with the specified name in the configuration directories. * The result is ordered from the lowest priority (base) file to the highest priority (application) file. * The result will always contain at least one file, but it may contain more than one. * * @param resourceName the resource name * @return the resource locators * @throws UncheckedIOException if an IO exception occurs * @throws IllegalStateException if there is a configuration error */ public static List<ResourceLocator> orderedResources(String resourceName) { ArgChecker.notNull(resourceName, "resourceName"); return Unchecked.wrap(() -> orderedResources0(resourceName)); }
private static ImmutableMap<String, SwapIndex> loadFromCsv() { List<ResourceLocator> resources = ResourceConfig.orderedResources("SwapIndexData.csv"); Map<String, SwapIndex> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { CsvFile csv = CsvFile.of(resource.getCharSource(), true); for (CsvRow row : csv.rows()) { SwapIndex parsed = parseSwapIndex(row); map.put(parsed.getName(), parsed); map.putIfAbsent(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Swap Index CSV file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
Loader() { ImmutableMap<String, FloatingRateName> names = ImmutableMap.of(); ImmutableMap<Currency, FloatingRateName> iborDefaults = ImmutableMap.of(); ImmutableMap<Currency, FloatingRateName> overnightDefaults = ImmutableMap.of(); try { IniFile ini = ResourceConfig.combinedIniFile(FLOATING_RATE_NAME_INI); names = parseIndices(ini); iborDefaults = parseIborDefaults(ini, names); overnightDefaults = parseOvernightDefaults(ini, names); } catch (RuntimeException ex) { // logging used because this is loaded in a static variable log.severe(Throwables.getStackTraceAsString(ex)); // return an empty instance to avoid ExceptionInInitializerError } this.names = names; this.iborDefaults = iborDefaults; this.overnightDefaults = overnightDefaults; }
private static ImmutableMap<String, FxIndex> loadFromCsv() { List<ResourceLocator> resources = ResourceConfig.orderedResources("FxIndexData.csv"); Map<String, FxIndex> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { CsvFile csv = CsvFile.of(resource.getCharSource(), true); for (CsvRow row : csv.rows()) { FxIndex parsed = parseFxIndex(row); map.put(parsed.getName(), parsed); map.putIfAbsent(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as FX Index CSV file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
/** * Obtains a combined extended enum instance. * <p> * Calling this method loads configuration files to determine which extended enums to combine. * The configuration file has the same simple name as the specified type and is a * {@linkplain IniFile INI file} with the suffix '.ini'. * * @param <R> the type of the enum * @param type the type to load * @return the extended enum */ public static <R extends Named> CombinedExtendedEnum<R> of(Class<R> type) { try { // load all matching files String name = type.getSimpleName() + ".ini"; IniFile config = ResourceConfig.combinedIniFile(name); // parse files ImmutableList<ExtendedEnum<? extends R>> children = parseChildren(config, type); log.fine(() -> "Loaded combined extended enum: " + name + ", providers: " + children); return new CombinedExtendedEnum<>(type, children); } catch (RuntimeException ex) { // logging used because this is loaded in a static variable log.severe("Failed to load CombinedExtendedEnum for " + type + ": " + Throwables.getStackTraceAsString(ex)); // return an empty instance to avoid ExceptionInInitializerError return new CombinedExtendedEnum<>(type, ImmutableList.of()); } }
/** * Loads the available currency pairs. * * @return the map of known currency pairs, where the value is the number of digits in the rate */ static ImmutableMap<CurrencyPair, Integer> loadPairs() { try { IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(PAIR_INI)); return parsePairs(ini); } catch (RuntimeException ex) { // logging used because this is loaded in a static variable log.severe(Throwables.getStackTraceAsString(ex)); // return an empty instance to avoid ExceptionInInitializerError return ImmutableMap.of(); } }
private static ImmutableMap<String, IborIndex> loadFromCsv() { List<ResourceLocator> resources = ResourceConfig.orderedResources("IborIndexData.csv"); Map<String, IborIndex> map = new HashMap<>(); // files are ordered lowest priority to highest, thus Map::put is used for (ResourceLocator resource : resources) { try { CsvFile csv = CsvFile.of(resource.getCharSource(), true); for (CsvRow row : csv.rows()) { IborIndex parsed = parseIborIndex(row); map.put(parsed.getName(), parsed); map.put(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Ibor Index CSV file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
IniFile config = ResourceConfig.combinedIniFile(name);
/** * Loads the available currencies. * * @param loadHistoric whether to load the historic or active currencies * @return the map of known currencies */ static ImmutableMap<String, Currency> loadCurrencies(boolean loadHistoric) { try { IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(CURRENCY_INI)); return parseCurrencies(ini, loadHistoric); } catch (RuntimeException ex) { // logging used because this is loaded in a static variable log.severe(Throwables.getStackTraceAsString(ex)); // return an empty instance to avoid ExceptionInInitializerError return ImmutableMap.of(); } }
private static ImmutableMap<String, PriceIndex> loadFromCsv() { List<ResourceLocator> resources = ResourceConfig.orderedResources("PriceIndexData.csv"); Map<String, PriceIndex> map = new HashMap<>(); // files are ordered lowest priority to highest, thus Map::put is used for (ResourceLocator resource : resources) { try { CsvFile csv = CsvFile.of(resource.getCharSource(), true); for (CsvRow row : csv.rows()) { PriceIndex parsed = parsePriceIndex(row); map.put(parsed.getName(), parsed); map.put(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Price Index CSV file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
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))); }
IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(CURRENCY_DATA_INI)); PropertySet section = ini.section("marketConventionPriority"); String list = section.value("ordering");
private static ImmutableMap<String, OvernightIndex> loadFromCsv() { List<ResourceLocator> resources = ResourceConfig.orderedResources("OvernightIndexData.csv"); Map<String, OvernightIndex> map = new HashMap<>(); // files are ordered lowest priority to highest, thus Map::put is used for (ResourceLocator resource : resources) { try { CsvFile csv = CsvFile.of(resource.getCharSource(), true); for (CsvRow row : csv.rows()) { OvernightIndex parsed = parseOvernightIndex(row); map.put(parsed.getName(), parsed); map.put(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as Overnight Index CSV file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
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))); }
@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); }
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))); }
@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_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_orderedResources_notFound() throws Exception { String captured = caputureSystemErr( () -> assertThrows(IllegalStateException.class, () -> ResourceConfig.orderedResources("NotFound.txt"))); assertTrue(captured.contains("No resource files found on the classpath")); }