PrefixHierarchicalNameMapper implements HierarchicalNameMapper { String stripCharacters(String input){ return Optional.ofNullable(Strings.emptyToNull(stripCharacters)) .map(pattern -> input.replaceAll("[" + pattern + "]", "")) .orElse(input); } PrefixHierarchicalNameMapper(String namePrefix,
                                        String tagKeyPrefix,
                                        String stripCharacters,
                                        @Nullable NamingConvention nameConventionOverride); @Override String toHierarchicalName(Meter.Id id, NamingConvention namingConvention);  }
@Test public void stripCharacters(){ PrefixHierarchicalNameMapper mapper1 = new PrefixHierarchicalNameMapper("prefix", "", null, NamingConvention.snakeCase); PrefixHierarchicalNameMapper mapper2 = new PrefixHierarchicalNameMapper("prefix", "", "", NamingConvention.snakeCase); PrefixHierarchicalNameMapper mapper3 = new PrefixHierarchicalNameMapper("prefix", "", "{}", NamingConvention.snakeCase); PrefixHierarchicalNameMapper mapper4 = new PrefixHierarchicalNameMapper("prefix", "", "$%", NamingConvention.snakeCase); PrefixHierarchicalNameMapper mapper5 = new PrefixHierarchicalNameMapper("prefix", "", "pre", NamingConvention.snakeCase); assertEquals(mapper1.stripCharacters(""), ""); assertEquals(mapper1.stripCharacters("test"), "test"); assertEquals(mapper1.stripCharacters("@#$"), "@#$"); assertEquals(mapper2.stripCharacters(""), ""); assertEquals(mapper2.stripCharacters("test"), "test"); assertEquals(mapper2.stripCharacters("@#$"), "@#$"); assertEquals(mapper3.stripCharacters(""), ""); assertEquals(mapper3.stripCharacters("test"), "test"); assertEquals(mapper3.stripCharacters("@#$"), "@#$"); assertEquals(mapper3.stripCharacters("@#${"), "@#$"); assertEquals(mapper3.stripCharacters("@#$}"), "@#$"); assertEquals(mapper3.stripCharacters("@#${}"), "@#$"); assertEquals(mapper4.stripCharacters("test"), "test"); assertEquals(mapper4.stripCharacters("%@#$"), "@#"); assertEquals(mapper4.stripCharacters("@%#${"), "@#{"); assertEquals(mapper4.stripCharacters("@#%$}"), "@#}"); assertEquals(mapper4.stripCharacters("@#$%{}"), "@#{}"); assertEquals(mapper5.stripCharacters("test"), "tst"); assertEquals(mapper5.stripCharacters("pre%@#$"), "%@#$"); assertEquals(mapper5.stripCharacters("prefix"), "fix"); assertEquals(mapper5.stripCharacters("prefixrep"), "fix"); }