class Locales {

	public static Locale forName(String localeName) {
		Args.notEmpty(localeName,"locale name");
        int len = localeName.length();
        if (len != 2 && len != 5 && len < 7) {
            throw new IllegalArgumentException("Invalid locale format: " + localeName);
        }
        char ch0 = localeName.charAt(0);
        char ch1 = localeName.charAt(1);
        if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z') {
            throw new IllegalArgumentException("Invalid locale format: " + localeName);
        }
        if (len == 2) {
            return new Locale(localeName, "");
        } else {
            if (localeName.charAt(2) != '_') {
                throw new IllegalArgumentException("Invalid locale format: " + localeName);
            }
            char ch3 = localeName.charAt(3);
            if (ch3 == '_') {
                return new Locale(localeName.substring(0, 2), "", localeName.substring(4));
            }
            char ch4 = localeName.charAt(4);
            if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z') {
                throw new IllegalArgumentException("Invalid locale format: " + localeName);
            }
            if (len == 5) {
                return new Locale(localeName.substring(0, 2), localeName.substring(3, 5));
            } else {
                if (localeName.charAt(5) != '_') {
                    throw new IllegalArgumentException("Invalid locale format: " + localeName);
                }
                return new Locale(localeName.substring(0, 2), localeName.substring(3, 5), localeName.substring(6));
            }
        }
	}

	protected  Locales();

}