static Id addIfMissing()

in spectator-reg-atlas/src/main/java/com/netflix/spectator/atlas/AtlasMeter.java [34:56]


  static Id addIfMissing(Id id, Tag t1, Tag t2) {
    String k1 = t1.key();
    String k2 = t2.key();
    boolean hasT1 = false;
    boolean hasT2 = false;
    for (int i = 1; i < id.size(); ++i) {
      hasT1 = hasT1 || k1.equals(id.getKey(i));
      hasT2 = hasT2 || k2.equals(id.getKey(i));
      if (hasT1 && hasT2) {
        break;
      }
    }

    if (hasT1 && hasT2) {
      return id;
    } else if (!hasT1 && !hasT2) {
      return id.withTags(t1.key(), t1.value(), t2.key(), t2.value());
    } else if (!hasT1) {
      return id.withTag(t1);
    } else {
      return id.withTag(t2);
    }
  }