Spaces:
Sleeping
Sleeping
File size: 912 Bytes
f5cd2d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | package com.rods.backtestingstrategies.strategy;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class StrategyFactory {
// Finds all Strategy beans
//
// Injects them as a List<Strategy>
//
// Factory maps them by StrategyType
private final Map<StrategyType, Strategy> strategies;
public StrategyFactory(List<Strategy> strategyList) {
this.strategies = strategyList.stream()
.collect(Collectors.toMap(
Strategy::getType,
s -> s
));
}
public Strategy getStrategy(StrategyType type) {
Strategy strategy = strategies.get(type);
if (strategy == null) {
throw new IllegalArgumentException("Unsupported strategy: " + type);
}
return strategy;
}
}
|