/*
 * Copyright 2014-2017 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.netflix.spectator.api.patterns;

import com.netflix.spectator.api.BasicTag;
import com.netflix.spectator.api.Tag;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Base class used for builders that need to allow for additional tagging to be
 * added onto a base id. This is typically used in conjunction with {@link IdBuilder}.
 */
@SuppressWarnings("unchecked")
public class TagsBuilder<T extends TagsBuilder<T>> {

  /** Create a new instance. */
  protected TagsBuilder() {
    // This class is only intended to be created by a sub-class. Since there are no
    // abstract methods at this time it is documented via the protected constructor
    // rather than making the class abstract.
  }

  /** Set of extra tags that the sub-class should add in to the id. */
  protected final List<Tag> extraTags = new ArrayList<>();

  /** Add an additional tag value. */
  T withTag(String k, String v) {
    extraTags.add(new BasicTag(k, v));
    return (T) this;
  }

  /** Add an additional tag value. */
  T withTag(String k, Boolean v) {
    extraTags.add(new BasicTag(k, Boolean.toString(v)));
    return (T) this;
  }

  /** Add an additional tag value. */
  T withTag(Tag t) {
    extraTags.add(t);
    return (T) this;
  }

  /** Add additional tag values. */
  T withTags(String... tags) {
    for (int i = 0; i < tags.length; i += 2) {
      extraTags.add(new BasicTag(tags[0], tags[1]));
    }
    return (T) this;
  }

  /** Add additional tag values. */
  T withTags(Tag... tags) {
    Collections.addAll(extraTags, tags);
    return (T) this;
  }

  /** Add additional tag values. */
  T withTags(Iterable<Tag> tags) {
    for (Tag t : tags) {
      extraTags.add(t);
    }
    return (T) this;
  }

  /** Add additional tag values. */
  T withTags(Map<String, String> tags) {
    for (Map.Entry<String, String> entry : tags.entrySet()) {
      extraTags.add(new BasicTag(entry.getKey(), entry.getValue()));
    }
    return (T) this;
  }
}

@@ -1528,32 +1528,39 @@
 tag value. */%0A  
+public 
 T withTag(String
@@ -1571,24 +1571,24 @@
 String v) %7B%0A
-
     extraTag
@@ -1672,32 +1672,39 @@
 tag value. */%0A  
+public 
 T withTag(String
@@ -1839,24 +1839,31 @@
 value. */%0A  
+public 
 T withTag(Ta
@@ -1947,32 +1947,39 @@
 ag values. */%0A  
+public 
 T withTags(Strin
@@ -2153,32 +2153,39 @@
 ag values. */%0A  
+public 
 T withTags(Tag..
@@ -2291,32 +2291,39 @@
 ag values. */%0A  
+public 
 T withTags(Itera
@@ -2456,18 +2456,25 @@
 ues. */%0A
-
   
+public 
 T withTa

fix visibility for methods on TagsBuilder (#482)