<commit_before>package com.wavefront.common;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.yammer.metrics.core.MetricName;

import javax.management.ObjectName;
import java.util.Collections;
import java.util.Map;

/**
 * A taggable metric name.
 *
 * @author <NAME> (<EMAIL>)
 */
public class TaggedMetricName extends MetricName {

  private final Map<String, String> tags;

  /**
   * A simple metric that would be concatenated when reported, e.g. "jvm", "name" would become jvm.name.
   *
   * @param group Prefix of the metric.
   * @param name  The name of the metric.
   */
  public TaggedMetricName(String group, String name) {
    super(group, "", name);
    tags = Collections.emptyMap();
  }

  public TaggedMetricName(String group, String name, String... tagAndValues) {
    this(group, name, makeTags(tagAndValues));
  }

  public TaggedMetricName(String group, String name, Map<String, String> tags) {
    this(group, name, makeTags(tags));
  }

  public TaggedMetricName(String group, String name, Pair<String, String>... tags) {
    super(group, "", name, null, createMBeanName(group, "", name, tags));
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (Pair<String, String> tag : tags) {
      if (tag != null && tag._1 != null && tag._2 != null) {
        builder.put(tag._1, tag._2);
      }
    }
    this.tags = builder.build();
  }

  public Map<String, String> getTags() {
    return tags;
  }

  private static Pair<String, String>[] makeTags(Map<String, String> tags) {
    Pair<String, String>[] toReturn = new Pair[tags.size()];
    int i = 0;
    for (Map.Entry<String, String> entry : tags.entrySet()) {
      toReturn[i] = new Pair<String, String>(entry.getKey(), entry.getValue());
      i++;
    }<commit_msg>Adds equals/hashcode and updatePointBuilder to TaggedMetricNames<commit_after>package com.wavefront.common;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.yammer.metrics.core.MetricName;
import sunnylabs.report.ReportPoint;

import javax.annotation.Nonnull;
import javax.management.ObjectName;
import java.util.Collections;
import java.util.Map;

/**
 * A taggable metric name.
 *
 * @author <NAME> (<EMAIL>)
 */
public class TaggedMetricName extends MetricName {
  @Nonnull
  private final Map<String, String> tags;

  /**
   * A simple metric that would be concatenated when reported, e.g. "jvm", "name" would become jvm.name.
   *
   * @param group Prefix of the metric.
   * @param name  The name of the metric.
   */
  public TaggedMetricName(String group, String name) {
    super(group, "", name);
    tags = Collections.emptyMap();
  }

  public TaggedMetricName(String group, String name, String... tagAndValues) {
    this(group, name, makeTags(tagAndValues));
  }

  public TaggedMetricName(String group, String name, Map<String, String> tags) {
    this(group, name, makeTags(tags));
  }

  public TaggedMetricName(String group, String name, Pair<String, String>... tags) {
    super(group, "", name, null, createMBeanName(group, "", name, tags));
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (Pair<String, String> tag : tags) {
      if (tag != null && tag._1 != null && tag._2 != null) {
        builder.put(tag._1, tag._2);
      }
    }
    this.tags = builder.build();
  }

  public Map<String, String> getTags() {
    return tags;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    if (!super.equals(o)) return false;

    TaggedMetricName that = (TaggedMetricName) o;

    return getTags().equals(that.getTags());

  }

  @Override
  public int hashCode() {
    int result = super.hashCode();
    result = 31 * result + getTags().hashCode();
    return result;
  }

  public void updatePointBuilder(ReportPoint.Builder builder) {
    builder.getAnnotations().putAll(tags);
  }

  private static Pair<String, String>[] makeTags(Map<String, String> tags) {
    Pair<String, String>[] toReturn = new Pair[tags.size()];
    int i = 0;
    for (Map.Entry<String, String> entry : tags.entrySet()) {
      toReturn[i] = new Pair<String, String>(entry.getKey(), entry.getValue());
      i++;
    }
{'fraction_non_alphanumeric': 0.13985691207015924, 'fraction_numerical': 0.0027694438033694898, 'mean_word_length': 3.640256959314775, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4229983', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1352, 'n_words': 365}