Country.java

package com.tradecloud.domain.place;

import com.tradecloud.common.base.StaticDataEntityBase;
import com.tradecloud.domain.common.IntegratedStaticDataEntityBase;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "country", uniqueConstraints = {@UniqueConstraint(columnNames = {"code"})})
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Country")
//@Cacheable(value = "country")
public class Country extends IntegratedStaticDataEntityBase {

    private static final long serialVersionUID = 1L;
    private static final int COUNTRY_CODE_LENGTH = 2;
    private static final int COUNTRY_CODE_LENGTH_ISOALPHA3 = 3;

    @Enumerated(value = EnumType.STRING)
    private CountryPostalCode countryPostalCode;

    private String postalCodeMask;

    private String ISOAlpha3Code;

    public Country() {
    }

    public Country(String code) {
        this(code, null);
    }

    public Country(String code, String name) {
        if (code.length() != COUNTRY_CODE_LENGTH) {
            throw new IllegalArgumentException("Country code must be of length " + COUNTRY_CODE_LENGTH);
        }
        setCode(code);
        setName(name);
    }

    public Country(String code, String name, String ISOAlpha3Code) {
        if (ISOAlpha3Code.length() != COUNTRY_CODE_LENGTH_ISOALPHA3) {
            throw new IllegalArgumentException("Country code must be of length " + COUNTRY_CODE_LENGTH_ISOALPHA3);
        }
        setCode(code);
        setName(name);
        setISOAlpha3Code(ISOAlpha3Code);
    }

    @Override
    public int compareTo(StaticDataEntityBase o) {
        if (getName() != null && o.getName() != null) {
            return getName().compareToIgnoreCase(o.getName());
        }
        return 0;
    }

    public String getPostalCodeMask() {
        return postalCodeMask;
    }

    public void setPostalCodeMask(String postalCodeMask) {
        this.postalCodeMask = postalCodeMask;
    }

    public CountryPostalCode getCountryPostalCode() {
        return countryPostalCode;
    }

    public void setCountryPostalCode(CountryPostalCode countryPostalCode) {
        this.countryPostalCode = countryPostalCode;
    }

    public String getISOAlpha3Code() {
        return ISOAlpha3Code;
    }

    public void setISOAlpha3Code(String ISOAlpha3Code) {
        this.ISOAlpha3Code = ISOAlpha3Code;
    }
}