/** * Constructs a Metadata object * * @param name The name of the metric * @param displayName The display (friendly) name of the metric * @param description The description of the metric * @param type The type of the metric * @param unit The units of the metric * @param tags The tags of the metric */ public Metadata(String name, String displayName, String description, MetricType type, String unit, String tags) { this(); this.name = name; this.displayName = displayName; this.description = description; this.type = type; this.unit = unit; addTags(tags); }
/** * Defines if the metric can have multiple objects and needs special * treatment or if it is a singleton. * <p/> */ Metadata() { String globalTagsFromEnv = System.getenv(GLOBAL_TAGS_VARIABLE); addTags(globalTagsFromEnv); }
/** * Constructs a Metadata object from a map with the following keys * <ul> * <li>{@code name} - The name of the metric</li> * <li>{@code displayName} - The display (friendly) name of the metric</li> * <li>{@code description} - The description of the metric</li> * <li>{@code type} - The type of the metric</li> * <li>{@code unit} - The units of the metric</li> * <li>{@code tags} - The tags of the metric - cannot be null</li> * <li>{@code reusable} - If <tt>true</tt>, this metric name is permitted to be used at multiple registration points. If * <tt>false</tt>, this metric name is only permitted to be used at one registration point per MetricRegistry.</li> * </ul> * * @param in a map of key/value pairs representing Metadata */ public Metadata(Map<String, String> in) { this(); this.name = (String) in.get("name"); this.description = (String) in.get("description"); this.displayName = (String) in.get("displayName"); this.setType((String) in.get("type")); this.setUnit((String) in.get("unit")); if (in.keySet().contains("tags")) { String tagString = (String) in.get("tags"); addTags(tagString); } this.setReusable(Boolean.parseBoolean(in.get("reusable"))); }
@Test public void addTagsTest() { metadata.addTags("colour=green,size=medium"); metadata.addTag("number=5"); Assert.assertNotNull(metadata); Assert.assertTrue(metadata.getTags().containsKey("size")); Assert.assertTrue(metadata.getTags().containsValue("green")); Assert.assertFalse(metadata.getTags().containsValue("blue")); Assert.assertTrue(metadata.getTags().containsKey("number")); }