Meta implements Comparable<Meta> { public List<Key> toKeys() { List<Key> keys = new ArrayList<>(); if (StringUtils.isNotBlank(metric)) { keys.add(new Key(METRIC_PREFIX + metric)); } if (StringUtils.isNotBlank(tagKey)) { keys.add(new Key(TAG_PREFIX + metric, tagKey)); } if (StringUtils.isNotBlank(tagKey) && StringUtils.isNotBlank(tagValue)) { keys.add(new Key(VALUE_PREFIX + metric, tagKey, tagValue)); } return keys; } Meta(String metric, String tagKey, String tagValue); String getMetric(); void setMetric(String metric); String getTagKey(); void setTagKey(String tagKey); String getTagValue(); void setTagValue(String tagValue); List<Key> toKeys(); static String prefix(Key key); static Meta parse(Key key); static Meta parse(Key key, Value value); static Meta parse(Key k, Value v, String prefix); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); @Override int compareTo(Meta o); static final String METRIC_PREFIX; static final String TAG_PREFIX; static final String VALUE_PREFIX; }
@Test public void testToKeys() { Meta one = new Meta("sys.cpu.user", "tag1", "value1"); List<Key> keys = one.toKeys(); Assert.assertTrue(keys.contains(new Key("m:sys.cpu.user"))); Assert.assertTrue(keys.contains(new Key("t:sys.cpu.user", "tag1"))); Assert.assertTrue(keys.contains(new Key("v:sys.cpu.user", "tag1", "value1"))); }