/** * Loads one or more CSV format FX rate files for a specific date. * <p> * Only those rates that match the specified date will be loaded. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param marketDataDate the date to load * @param resources the CSV resources * @return the loaded FX rates, mapped by {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<FxRateId, FxRate> load(LocalDate marketDataDate, ResourceLocator... resources) { return load(marketDataDate, Arrays.asList(resources)); }
/** * Loads one or more CSV format FX rate files. * <p> * All dates that are found will be returned. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param resources the CSV resources * @return the loaded FX rates, mapped by {@link LocalDate} and {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<FxRateId, FxRate>> loadAllDates(ResourceLocator... resources) { return loadAllDates(Arrays.asList(resources)); }
/** * Loads one or more CSV format FX rate files. * <p> * All dates that are found will be returned. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param resources the CSV resources * @return the loaded FX rates, mapped by {@link LocalDate} and {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<FxRateId, FxRate>> loadAllDates( Collection<ResourceLocator> resources) { Collection<CharSource> charSources = resources.stream().map(r -> r.getCharSource()).collect(toList()); return parse(d -> true, charSources); }
/** * Parses one or more CSV format FX rate files. * <p> * A predicate is specified that is used to filter the dates that are returned. * This could match a single date, a set of dates or all dates. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param datePredicate the predicate used to select the dates * @param charSources the CSV character sources * @return the loaded FX rates, mapped by {@link LocalDate} and {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<FxRateId, FxRate>> parse( Predicate<LocalDate> datePredicate, Collection<CharSource> charSources) { // builder ensures keys can only be seen once Map<LocalDate, ImmutableMap.Builder<FxRateId, FxRate>> mutableMap = new HashMap<>(); for (CharSource charSource : charSources) { parseSingle(datePredicate, charSource, mutableMap); } ImmutableMap.Builder<LocalDate, ImmutableMap<FxRateId, FxRate>> builder = ImmutableMap.builder(); for (Entry<LocalDate, Builder<FxRateId, FxRate>> entry : mutableMap.entrySet()) { builder.put(entry.getKey(), entry.getValue().build()); } return builder.build(); }
/** * Loads one or more CSV format FX rate files for a set of dates. * <p> * Only those rates that match one of the specified dates will be loaded. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param marketDataDates the set of dates to load * @param resources the CSV resources * @return the loaded FX rates, mapped by {@link LocalDate} and {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<FxRateId, FxRate>> load( Set<LocalDate> marketDataDates, ResourceLocator... resources) { return load(marketDataDates, Arrays.asList(resources)); }
public void test_load_alLDates_file1_date1() { Map<LocalDate, ImmutableMap<FxRateId, FxRate>> map = FxRatesCsvLoader.loadAllDates(RATES_1); assertEquals(map.size(), 2); assertFile1Date1(map.get(DATE1)); assertFile1Date2(map.get(DATE2)); }
/** * Loads one or more CSV format FX rate files for a set of dates. * <p> * Only those rates that match one of the specified dates will be loaded. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param marketDataDates the dates to load * @param resources the CSV resources * @return the loaded FX rates, mapped by {@link LocalDate} and {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<FxRateId, FxRate>> load( Set<LocalDate> marketDataDates, Collection<ResourceLocator> resources) { Collection<CharSource> charSources = resources.stream().map(r -> r.getCharSource()).collect(toList()); return parse(d -> marketDataDates.contains(d), charSources); }
public void test_load_oneDate_file1_date1() { Map<FxRateId, FxRate> map = FxRatesCsvLoader.load(DATE1, RATES_1); assertEquals(map.size(), 2); assertFile1Date1(map); }
/** * Loads one or more CSV format FX rate files for a specific date. * <p> * Only those rates that match the specified date will be loaded. * <p> * If the files contain a duplicate entry an exception will be thrown. * * @param marketDataDate the date to load * @param resources the CSV resources * @return the loaded FX rates, mapped by {@linkplain FxRateId rate ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<FxRateId, FxRate> load(LocalDate marketDataDate, Collection<ResourceLocator> resources) { Collection<CharSource> charSources = resources.stream().map(r -> r.getCharSource()).collect(toList()); return parse(d -> marketDataDate.equals(d), charSources).getOrDefault(marketDataDate, ImmutableMap.of()); }
public void test_load_oneDate_file1_date2() { Map<FxRateId, FxRate> map = FxRatesCsvLoader.load(DATE2, ImmutableList.of(RATES_1)); assertEquals(map.size(), 2); assertFile1Date2(map); }
public void test_invalidDuplicate() { assertThrowsIllegalArg(() -> FxRatesCsvLoader.load(DATE1, RATES_INVALID_DUPLICATE)); }
public void test_load_dateSet_file1_date1() { Map<LocalDate, ImmutableMap<FxRateId, FxRate>> map = FxRatesCsvLoader.load(ImmutableSet.of(DATE1, DATE2), RATES_1); assertEquals(map.size(), 2); assertFile1Date1(map.get(DATE1)); assertFile1Date2(map.get(DATE2)); }
public void test_load_oneDate_file1file2_date1() { Map<FxRateId, FxRate> map = FxRatesCsvLoader.load(DATE1, ImmutableList.of(RATES_1, RATES_2)); assertEquals(map.size(), 3); assertFile1Date1(map); assertFile2Date1(map); }
public void test_load_oneDate_invalidDate() { assertThrows( () -> FxRatesCsvLoader.load(date(2015, 10, 2), RATES_INVALID_DATE), IllegalArgumentException.class, "Error processing resource as CSV file: .*"); }