ValidCharacters { public static Metric toValidValue(Metric metric) { MonitorConfig cfg = metric.getConfig(); MonitorConfig.Builder cfgBuilder = MonitorConfig.builder(toValidCharset(cfg.getName())); for (Tag orig : cfg.getTags()) { final String key = orig.getKey(); if (RELAXED_GROUP_KEYS.contains(key)) { cfgBuilder.withTag(key, toValidCharsetTable(CHARS_ALLOWED_GROUPS, orig.getValue())); } else { cfgBuilder.withTag(toValidCharset(key), toValidCharset(orig.getValue())); } } cfgBuilder.withPublishingPolicy(cfg.getPublishingPolicy()); return new Metric(cfgBuilder.build(), metric.getTimestamp(), metric.getValue()); } private  ValidCharacters(); static boolean hasInvalidCharacters(String str); static String toValidCharset(String str); static Metric toValidValue(Metric metric); static List<Metric> toValidValues(List<Metric> metrics); static void tagToJson(JsonGenerator gen, Tag tag);  }
@Test public void testValidValue() throws Exception { MonitorConfig cfg = MonitorConfig.builder("foo^bar") .withTag("nf.asg", "foo~1") .withTag("nf.cluster", "foo^1.0") .withTag("key^1.0", "val~1.0") .build(); Metric metric = new Metric(cfg, 0, 0.0); Metric fixed = ValidCharacters.toValidValue(metric); Metric expected = new Metric("foo_bar", BasicTagList.of("nf.asg", "foo~1", "nf.cluster", "foo^1.0", "key_1.0", "val_1.0"), 0, 0.0); assertEquals(fixed, expected); }