// Path: src/main/java/org/weakref/jmx/ObjectNames.java
// static String quoteValueIfNecessary(String name)
// {
//     boolean needQuote = false;
//     StringBuilder builder = new StringBuilder("\"");
//     for (int i = 0; i < name.length(); ++i) {
//         char c = name.charAt(i);
//         switch (c) {
//             case ':':
//             case ',':
//             case '=':
//                 needQuote = true;
//                 builder.append(c);
//                 break;
//             case '\"':
//             case '?':
//             case '*':
//                 needQuote = true;
//                 builder.append('\\');
//                 builder.append(c);
//                 break;
//             case '\n':
//                 needQuote = true;
//                 builder.append("\\n");
//                 break;
//             case '\\':
//                 builder.append("\\\\");
//                 break;
//             default:
//                 builder.append(c);
//         }
//     }
// 
//     if (needQuote) {
//         name = builder.append('\"').toString();
//     }
//     return name;
// }


import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.weakref.jmx.ObjectNames.quoteValueIfNecessary;
package org.weakref.jmx;



public class ObjectNameBuilder
{
    private static final Pattern BAD_PACKAGENAME_PATTERN = Pattern.compile("[:?*]");
    private final StringBuilder objectName;
    private final Set<String> properties = new HashSet<>();

    public ObjectNameBuilder(String domain)
    {
        requireNonNull(domain, "domain is null");
        checkArgument(!BAD_PACKAGENAME_PATTERN.matcher(domain).find(), "domain is invalid");
        this.objectName = new StringBuilder(domain);
    }

    public ObjectNameBuilder withProperty(String name, String value)
    {
        checkArgument(!properties.contains(name), "Duplicate property name: %s", name);

        if (properties.isEmpty()) {
            objectName.append(":");
        }
        else {
            objectName.append(",");
        }

// Path: src/main/java/org/weakref/jmx/ObjectNames.java
// static String quoteValueIfNecessary(String name)
// {
//     boolean needQuote = false;
//     StringBuilder builder = new StringBuilder("\"");
//     for (int i = 0; i < name.length(); ++i) {
//         char c = name.charAt(i);
//         switch (c) {
//             case ':':
//             case ',':
//             case '=':
//                 needQuote = true;
//                 builder.append(c);
//                 break;
//             case '\"':
//             case '?':
//             case '*':
//                 needQuote = true;
//                 builder.append('\\');
//                 builder.append(c);
//                 break;
//             case '\n':
//                 needQuote = true;
//                 builder.append("\\n");
//                 break;
//             case '\\':
//                 builder.append("\\\\");
//                 break;
//             default:
//                 builder.append(c);
//         }
//     }
// 
//     if (needQuote) {
//         name = builder.append('\"').toString();
//     }
//     return name;
// }


// Path: src/main/java/org/weakref/jmx/ObjectNameBuilder.java
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.weakref.jmx.ObjectNames.quoteValueIfNecessary;

package org.weakref.jmx;



public class ObjectNameBuilder
{
    private static final Pattern BAD_PACKAGENAME_PATTERN = Pattern.compile("[:?*]");
    private final StringBuilder objectName;
    private final Set<String> properties = new HashSet<>();

    public ObjectNameBuilder(String domain)
    {
        requireNonNull(domain, "domain is null");
        checkArgument(!BAD_PACKAGENAME_PATTERN.matcher(domain).find(), "domain is invalid");
        this.objectName = new StringBuilder(domain);
    }

    public ObjectNameBuilder withProperty(String name, String value)
    {
        checkArgument(!properties.contains(name), "Duplicate property name: %s", name);

        if (properties.isEmpty()) {
            objectName.append(":");
        }
        else {
            objectName.append(",");
        }

        objectName.append(name).append('=').append(quoteValueIfNecessary(value));