DruidUtils { public static String genTranquilityMetricsSpec(Class... classList) { if (classList == null || classList.length <= 0) return ""; String metricsSpecPrefix, metricsSpecMiddle; if (StrUtils.isEmpty(metricsSpecPrefix = p.getProperty("metrics.spec.prefix")) || StrUtils.isEmpty(metricsSpecMiddle = p.getProperty("metrics.spec.middle"))) throw new RuntimeException("Properties [metrics.spec.prefix/middle] is empty!"); String fieldName; StringBuilder strBuilder = new StringBuilder(metricsSpecPrefix); LinkedHashSet<String> checkExists = new LinkedHashSet<>(); for (Class clazz : classList) for (Field field : BeanUtils.getAllFields(clazz)) { if (checkExists.contains(fieldName = field.getName())) continue; buildMiddlePart(strBuilder, field, fieldName, metricsSpecMiddle, checkExists); } return strBuilder.append("]}").toString().replaceAll(",]", "]"); } private  DruidUtils(); static String genTranquilityMetricsSpec(Class... classList);  }
@Test public void genTranquilityMetricsSpec() { assertEquals("{\"metricsSpec\":[{\"name\":\"count\",\"type\":\"count\"}," + "{\"fieldName\":\"b\",\"name\":\"b_min\",\"type\":\"longMin\"}," + "{\"fieldName\":\"b\",\"name\":\"b_max\",\"type\":\"longMax\"}," + "{\"fieldName\":\"c\",\"name\":\"c_min\",\"type\":\"doubleMin\"}," + "{\"fieldName\":\"c\",\"name\":\"c_max\",\"type\":\"doubleMax\"}]}", DruidUtils.genTranquilityMetricsSpec(B.class)); }