MetricFactory { public Function<?,?> functionFor(String functionId, Class<?> javaType) { Map<Class<?>, Function<?,?>> builders = buildersByFunction.get(functionId); if (builders == null) return null; return builders.get(javaType); } 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 functionFor() { assertEquals(Summer.IntegerSum, mf.functionFor(Summer.Id, Integer.class)); assertEquals(Summer.LongSum, mf.functionFor(Summer.Id, Long.class)); assertEquals(Summer.FloatSum, mf.functionFor(Summer.Id, Float.class)); assertEquals(Summer.DoubleSum, mf.functionFor(Summer.Id, Double.class)); assertEquals(Summer.BigDecimalSum, mf.functionFor(Summer.Id, BigDecimal.class)); assertEquals(MinMax.Integer, mf.functionFor(MinMax.Id, Integer.class)); assertEquals(MinMax.Long, mf.functionFor(MinMax.Id, Long.class)); assertEquals(MinMax.Float, mf.functionFor(MinMax.Id, Float.class)); assertEquals(MinMax.Double, mf.functionFor(MinMax.Id, Double.class)); assertEquals(MinMax.BigDecimal, mf.functionFor(MinMax.Id, BigDecimal.class)); }