/** * Loads one or more CSV format quote files for a set of dates. * <p> * Only those quotes 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 quotes, mapped by {@link LocalDate} and {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<QuoteId, Double>> load( Set<LocalDate> marketDataDates, ResourceLocator... resources) { return load(marketDataDates, Arrays.asList(resources)); }
/** * Loads one or more CSV format quote 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 quotes, mapped by {@link LocalDate} and {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<QuoteId, Double>> loadAllDates(ResourceLocator... resources) { return loadAllDates(Arrays.asList(resources)); }
/** * Loads one or more CSV format quote 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 quotes, mapped by {@link LocalDate} and {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<QuoteId, Double>> 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 quote 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 quotes, mapped by {@link LocalDate} and {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<QuoteId, Double>> parse( Predicate<LocalDate> datePredicate, Collection<CharSource> charSources) { // builder ensures keys can only be seen once Map<LocalDate, ImmutableMap.Builder<QuoteId, Double>> mutableMap = new HashMap<>(); for (CharSource charSource : charSources) { parseSingle(datePredicate, charSource, mutableMap); } ImmutableMap.Builder<LocalDate, ImmutableMap<QuoteId, Double>> builder = ImmutableMap.builder(); for (Entry<LocalDate, Builder<QuoteId, Double>> entry : mutableMap.entrySet()) { builder.put(entry.getKey(), entry.getValue().build()); } return builder.build(); }
/** * Loads one or more CSV format quote files for a specific date. * <p> * Only those quotes 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 quotes, mapped by {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<QuoteId, Double> load(LocalDate marketDataDate, ResourceLocator... resources) { return load(marketDataDate, Arrays.asList(resources)); }
public void test_load_alLDates_file1_date1() { Map<LocalDate, ImmutableMap<QuoteId, Double>> map = QuotesCsvLoader.loadAllDates(QUOTES_1); assertEquals(map.size(), 2); assertFile1Date1(map.get(DATE1)); assertFile1Date2(map.get(DATE2)); }
/** * Loads one or more CSV format quote files for a set of dates. * <p> * Only those quotes 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 quotes, mapped by {@link LocalDate} and {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<LocalDate, ImmutableMap<QuoteId, Double>> 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_noFiles() { Map<QuoteId, Double> map = QuotesCsvLoader.load(DATE1); assertEquals(map.size(), 0); }
/** * Loads one or more CSV format quote files for a specific date. * <p> * Only those quotes 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 quotes, mapped by {@linkplain QuoteId quote ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<QuoteId, Double> 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_date1() { Map<QuoteId, Double> map = QuotesCsvLoader.load(DATE1, QUOTES_1); assertEquals(map.size(), 2); assertFile1Date1(map); }
public void test_load_oneDate_file1_date1date2() { Map<LocalDate, ImmutableMap<QuoteId, Double>> map = QuotesCsvLoader.load(ImmutableSet.of(DATE1, DATE2), QUOTES_1); assertEquals(map.size(), 2); assertFile1Date1Date2(map); }
public void test_load_oneDate_file1_date2() { Map<QuoteId, Double> map = QuotesCsvLoader.load(DATE2, ImmutableList.of(QUOTES_1)); assertEquals(map.size(), 2); assertFile1Date2(map); }
public void test_invalidDuplicate() { assertThrowsIllegalArg(() -> QuotesCsvLoader.load(DATE1, QUOTES_INVALID_DUPLICATE)); }
public void test_load_dateSet_file1_date1() { Map<LocalDate, ImmutableMap<QuoteId, Double>> map = QuotesCsvLoader.load(ImmutableSet.of(DATE1, DATE2), QUOTES_1); assertEquals(map.size(), 2); assertFile1Date1(map.get(DATE1)); assertFile1Date2(map.get(DATE2)); }
public void test_load_oneDate_file1file2_date1() { Map<QuoteId, Double> map = QuotesCsvLoader.load(DATE1, ImmutableList.of(QUOTES_1, QUOTES_2)); assertEquals(map.size(), 3); assertFile1Date1(map); assertFile2Date1(map); }
public void test_load_oneDate_invalidDate() { assertThrows( () -> QuotesCsvLoader.load(date(2015, 10, 2), QUOTES_INVALID_DATE), IllegalArgumentException.class, "Error processing resource as CSV file: .*"); }