@Override public String toString() { return getKey() + KEY_VALUE_SEPARATOR + getValue(); } }
/** * Converts a {@link List} of {@link Tag}s to a {@link Map} of key, value pairs. * * @param tags a {@link List} of {@link Tag}s that should be converted to key, value pairs * * @return a {@link Map} of key, value pairs */ public static <T> Map<? extends String, T> toMap(List<Tag<T>> tags) { ImmutableMap.Builder<String, T> tagsMapBuilder = ImmutableMap.builder(); for (Tag<T> tag : tags) { tagsMapBuilder.put(tag.getKey(), tag.getValue()); } return tagsMapBuilder.build(); }
/** * Add tags. * @param tags List of {@link gobblin.metrics.Tag} * @return {@code this} */ public T withTags(List<Tag<?>> tags) { for(Tag<?> tag : tags) { this.tags.put(tag.getKey(), tag.getValue().toString()); } return self(); }
public static Map<String, String> dumpTags(MetricContext context) { Map<String, String> output = new HashMap<>(); for (Tag<?> tag : context.getTags()) { output.put(tag.getKey(), tag.getValue().toString()); } return output; }
/** * Converts a wildcard {@link Tag} to a {@link String} {@link Tag}. This method uses the {@link Object#toString()} * method to convert the wildcard type to a {@link String}. * * @param tag a {@link Tag} that should be converted to a {@link Tag} with value of type {@link String} * * @return a {@link Tag} with a {@link String} value */ public static Tag<String> tagValueToString(Tag<?> tag) { return new Tag<>(tag.getKey(), tag.getValue().toString()); }