// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;

/**
 * @author mortent
 */
public class AthenzDomain {

    private final String name;

    private AthenzDomain(String name) {
        this.name = name;
    }

    public static AthenzDomain from(String value) {
        return new AthenzDomain(value);
    }

    public String value() { return name; }

    @Override
    public String toString() {
        return "AthenzDomain{" +
               "name='" + name + '\'' +
               '}';
    }

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

        AthenzDomain that = (AthenzDomain) o;

        return name != null ? name.equals(that.name) : that.name == null;
    }

    @Override
    public int hashCode() {
        return name != null ? name.hashCode() : 0;
    }
}

@@ -149,16 +149,49 @@
 ision;%0A%0A
+import java.util.regex.Pattern;%0A%0A
 /**%0A * @
@@ -254,93 +254,435 @@
 ate 
-final String name;%0A%0A    private AthenzDomain(String name) %7B%0A        this.name = name;
+static final Pattern PATTERN = Pattern.compile(%22%5Ba-zA-Z0-9_%5D%5Ba-zA-Z0-9_%5C%5C-.%5D*%5Ba-zA-Z0-9_%5D%22);%0A%0A    private final String name;%0A%0A    private AthenzDomain(String name) %7B%0A        validateName(name);%0A        this.name = name;%0A    %7D%0A%0A    private static void validateName(String name) %7B%0A        if (!PATTERN.matcher(name).matches()) %7B%0A            throw new IllegalArgumentException(%22Not a valid domain name: '%22 + name + %22'%22);%0A        %7D
 %0A   

Validate domain name