MetricFactory { public Set<String> availableFunctionsFor(Class<?> javaType) { Set<String> functions = new HashSet<>(buildersByFunction.size()); for (Entry<String, Map<Class<?>, Function<?,?>>> entry : buildersByFunction.entrySet()) { if (entry.getValue().containsKey(javaType)) functions.add(entry.getKey()); } return functions; } private  MetricFactory(); void register(String functionId, Map<Class<?>, Function<?,?>> builders); Set<String> registeredFunctions(); Function<?,?> functionFor(String functionId, Class<?> javaType); Set<String> availableFunctionsFor(Class<?> javaType); void showOn(PrintStream out); static final MetricFactory Instance; }
@Test public void availableFunctionsFor() { MetricFactory mf = MetricFactory.Instance; List<String> expectedNumericFns = Arrays.asList(Summer.Id, Histogram.Id, Averager.Id, MinMax.Id, StdDeviation.Id); Set<String> functions = mf.availableFunctionsFor(Integer.class); assertTrue(expectedNumericFns.containsAll(functions)); functions = mf.availableFunctionsFor(Long.class); assertTrue(expectedNumericFns.containsAll(functions)); functions = mf.availableFunctionsFor(Float.class); assertTrue(expectedNumericFns.containsAll(functions)); functions = mf.availableFunctionsFor(Double.class); assertTrue(expectedNumericFns.containsAll(functions)); functions = mf.availableFunctionsFor(BigDecimal.class); assertTrue(expectedNumericFns.containsAll(functions)); }