use of name.abuchen.portfolio.ui.util.CacheKey in project portfolio by buchen.
the class AbstractTradesWidget method getUpdateTask.
@Override
public Supplier<TradeDetailsView.Input> getUpdateTask() {
Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval(LocalDate.now());
ClientFilter clientFilter = get(ClientFilterConfig.class).getSelectedFilter();
CacheKey key = new CacheKey(TradeCollector.class, clientFilter, interval);
return () -> {
TradeDetailsView.Input input = (TradeDetailsView.Input) getDashboardData().getCache().computeIfAbsent(key, k -> {
Client filteredClient = clientFilter.filter(getClient());
TradeCollector collector = new TradeCollector(filteredClient, getDashboardData().getCurrencyConverter());
List<Trade> trades = new ArrayList<>();
List<TradeCollectorException> errors = new ArrayList<>();
getClient().getSecurities().forEach(s -> {
try {
trades.addAll(collector.collect(s));
} catch (TradeCollectorException error) {
errors.add(error);
}
});
return new TradeDetailsView.Input(interval, trades, errors);
});
return new TradeDetailsView.Input(input.getInterval(), input.getTrades().stream().filter(getFilter(interval)).collect(Collectors.toList()), input.getErrors());
};
}
use of name.abuchen.portfolio.ui.util.CacheKey in project portfolio by buchen.
the class DataSeriesCache method lookup.
public PerformanceIndex lookup(DataSeries series, Interval reportingPeriod) {
// Every data series is cached separately except the for the client. The
// client data series are created out of the same PerformanceIndex
// instance, e.g. accumulated and delta performance.
// $NON-NLS-1$
String uuid = series.getType() == DataSeries.Type.CLIENT ? "$client$" : series.getUUID();
CacheKey key = new CacheKey(uuid, reportingPeriod);
// #computeIfAbsent leads to a ConcurrentMapModificdation b/c #calculate
// might call #lookup to calculate other cache entries
PerformanceIndex result = cache.get(key);
if (result != null)
return result;
result = calculate(series, reportingPeriod);
cache.put(key, result);
return result;
}
use of name.abuchen.portfolio.ui.util.CacheKey in project portfolio by buchen.
the class ActivityWidget method getUpdateTask.
@SuppressWarnings("unchecked")
@Override
public Supplier<List<TransactionPair<?>>> getUpdateTask() {
Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval(LocalDate.now());
ClientFilter clientFilter = get(ClientFilterConfig.class).getSelectedFilter();
CacheKey key = new CacheKey(TransactionPair.class, clientFilter, interval);
return () -> (List<TransactionPair<?>>) getDashboardData().getCache().computeIfAbsent(key, k -> clientFilter.filter(getClient()).getAllTransactions());
}
Aggregations