LabelValuesExtraction { public static List<String> extractLabelValuesByPosition(String key, LabeledMetricConf labeledMetricConf) { List<String> keyParts = keyParts(key); Map<Integer, String> keyPartsByPosition = keyPartsByPosition(keyParts); return labeledMetricConf.getLabelConfs().stream() .map(LabelConf::getPattern) .map(pattern -> replacePatternTokens(pattern, keyPartsByPosition)) .collect(Collectors.toList()); } private  LabelValuesExtraction(); static List<String> extractLabelValuesByPosition(String key,
                                                            LabeledMetricConf labeledMetricConf);  }
@Test public void shouldExtractLabelValuesUsingPositionalPattern() { String key = "a.b.c.d"; LabeledMetricConf labeledMetricConf = new LabeledMetricConf("a", Arrays.asList(new LabelConf("label_name", "$1"), new LabelConf("label_name", "$2_$3"))); List<String> labelValues = LabelValuesExtraction.extractLabelValuesByPosition(key, labeledMetricConf); assertEquals(Arrays.asList("b", "c_d"), labelValues); }