TransformerConfig { public Set<Integer> findPeriod(String symbol, String interval) { String key = (symbol + interval).toLowerCase(); if (!periods.containsKey(key)) { Node<String> n1 = periodsTree.getOtherwiseChild(symbol, "*"); if (n1 == null) throw new IllegalArgumentException("No period configuration found for symbol " + symbol + " or *"); Node<String> n2 = n1.getOtherwiseChild(interval, "*"); if (n2 == null) throw new IllegalArgumentException( "No period configuration found for symbol " + n1.getData() + " with interval " + interval + " or *"); Set<String> vals = n2.getChildrensData(); Set<Integer> ints = vals.stream().map(s -> Integer.valueOf(s)).collect(Collectors.toSet()); periods.put(key, ints); } return periods.get(key); } TransformerConfig(List<Map<String, String>> map);  TransformerConfig(Set<SymbolConfig> symbolConfigs);  TransformerConfig(boolean isActive); boolean isActive(); Set<Integer> findPeriod(String symbol, String interval);  }
@Test public void testConfigureViaYaml() throws Exception { InputStream content = new DefaultResourceLoader().getResource("classpath:yml/sample.yml").getInputStream(); Map<String, Object> vals = new Yaml().loadAs(content, Map.class); Map<String, List<Map>> transformers = (Map) vals.get("transformers"); List<Map<String, String>> numchance = (List) transformers.get("numeric-change"); TransformerConfig config = new TransformerConfig(numchance); Assert.assertEquals(config.findPeriod("Goog", "1m"), com.google.common.collect.Sets.newHashSet(10)); Assert.assertEquals(config.findPeriod("Goog", "1d"), com.google.common.collect.Sets.newHashSet(5, 10)); Assert.assertEquals(config.findPeriod("Tol", "1m"), com.google.common.collect.Sets.newHashSet(10, 20, 30)); Assert.assertEquals(config.findPeriod("tol", "xzy"), com.google.common.collect.Sets.newHashSet(10, 20, 30)); numchance = (List) transformers.get("basic-stats"); config = new TransformerConfig(numchance); Assert.assertEquals(config.findPeriod("Goog", "1m"), com.google.common.collect.Sets.newHashSet(1, 10, 15, 30, 60, 90)); Assert.assertEquals(config.findPeriod("GOOG", "1d"), com.google.common.collect.Sets.newHashSet(1, 10, 15, 30, 60, 90)); Assert.assertEquals(config.findPeriod("TOL", "1m"), com.google.common.collect.Sets.newHashSet(1, 10, 15, 30, 60, 90)); Assert.assertEquals(config.findPeriod("tol", "xus"), com.google.common.collect.Sets.newHashSet(1, 10, 15, 30, 60, 90)); }
@Test public void constructSymbolConfig() throws Exception { SymbolConfig config = new SymbolConfig(); config.symbol.add("*"); config.interval.add("*"); config.periods.add("2"); TransformerConfig tc = new TransformerConfig(com.google.common.collect.Sets.newHashSet(config)); Set<Integer> periods = tc.findPeriod("TOL", "1m"); Assert.assertNotNull(periods); Assert.assertFalse(periods.isEmpty()); Assert.assertEquals(periods.iterator().next(), new Integer(2)); }