MeterId { public List<Label> transformTags() { if (labels != null) { return labels; } return labels = tags.stream() .map(t -> Label.newBuilder().setName(t.getKey()).setValue(t.getValue()).build()) .collect(Collectors.toList()); } MeterId(String name, MeterType type, List<MeterTag> tags); String getName(); List<MeterTag> getTags(); MeterType getType(); List<Label> transformTags(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testTransformTags() { MeterId meterId = new MeterId("test", MeterType.COUNTER, Arrays.asList(new MeterTag("k1", "v1"))); List<Label> labels = meterId.transformTags(); Assert.assertEquals(1, labels.size()); final Label label = labels.get(0); Assert.assertEquals("k1", label.getName()); Assert.assertEquals("v1", label.getValue()); Assert.assertEquals(MeterType.COUNTER, meterId.getType()); final List<Label> cacheLabels = (List<Label>) Whitebox.getInternalState(meterId, "labels"); Assert.assertEquals(labels, cacheLabels); meterId = new MeterId("test", MeterType.COUNTER, Collections.emptyList()); labels = meterId.transformTags(); Assert.assertEquals(0, labels.size()); }