Validate the country property

@param country
@return
766069
public static String validateCountry(String country) {
        if (country.length() > DEFAULT_COUNTRY_LEN) {
            return country.substring(0, DEFAULT_COUNTRY_LEN);
        }

        return country;
    }
1009610
public CountryCodeDataType.Enum getCountryCodeDataType(String countryCode) {
		CountryCodeDataType.Enum countryCodeDataType = null;
		CountryContract country = s2SLocationService.getCountryFromCode(countryCode);
		if (country != null) {
			StringBuilder countryDetail = new StringBuilder();
			countryDetail.append(country.getAlternateCode());
			countryDetail.append(": ");
			countryDetail.append(country.getName().toUpperCase());
			countryCodeDataType = CountryCodeDataType.Enum
					.forString(countryDetail.toString());
		}
		return countryCodeDataType;
	}
867640
public static Locale getLocale(String country)
    {
        if(country == null || country.length() == 0)
            country = Locale.getDefault().getCountry();
        List<Locale> locales = LocaleUtils.languagesByCountry(country);
        Locale locale = Locale.getDefault();
        if(locales.size() > 0)
            locale = locales.get(0); // Use the first locale that matches the country
        return locale;
    }
949305
def validate
      return [] unless country
      country.validations.select do |validation|
        normalized_number.match?(Regexp.new("^(#{validation.pattern})$"))
      end.map(&:name)
    end
618606
public function country($country)
    {
        $countries = is_array($country) ? $country : func_get_args();

        $this->countries = array_merge($this->countries, $countries);

        return $this;
    }
1180957
@Override
	public boolean validate(final Problems problems, final String compName, final String model) {
		final Matcher m = ADDRESS_PATTERN.matcher(model);
		String realName = null;
		String address;
		if (m.lookingAt()) {
			if (m.groupCount() == 2) {
				address = m.group(2);
				realName = m.group(1);
			} else {
				address = m.group(1);
			}
		} else {
			address = model;
		}
		return validate(realName, address, problems, compName);
	}
725482
public static function make(string $country = null)
    {
        if (empty($country)) {
            $country = config('default');
        }

        return (new static() )->setCurrency($country);
    }
1099049
public function setCountry(\Core\Entity\Country $country = null)
    {
        $this->country = $country;

        return $this;
    }
767775
public function ofCountry($country)
    {
        $countries = is_array($country) ? $country : func_get_args();

        $instance = clone $this;
        $instance->countries = array_unique(
            array_merge($instance->countries, static::parseCountries($countries))
        );

        return $instance;
    }
1101289
@Override
	public boolean validate(Object value) {
		if(constraints == null) {
			return false;
		}

		IConstraintChecker checker;
		for(BeanProperty constraint : constraints) {
			checker = checkers.get(constraint.getPropertyName());
			if(checker == null) {
				throw new RuntimeException("No checker found for constraint "
						+ "'" + constraint.getPropertyName() + "'"
				);
			}
			checker.check(value, constraint);
		}
		return true;
	}
553146
public function setCountry(Country $country = null)
    {
        if ($this->country !== $country) {
            $this->country = $country;
        }

        return $this;
    }
937067
public function isValidLocale($language, $country)
    {
        return ($this->getLanguage() === $language && $this->getCountry() === $country)
            || (empty($this->getLanguage()) && empty($this->getCountry()));
    }
1321708
@Override
  public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    final String valueAsString = Objects.toString(pvalue, null);
    if (StringUtils.isEmpty(valueAsString)) {
      // empty field is ok
      return true;
    }
    if (valueAsString.length() < IBAN_LENGTH_MIN || valueAsString.length() > IBAN_LENGTH_MAX) {
      // to short or to long, but it's handled by size validator!
      return true;
    }
    final String countryCode = valueAsString.substring(0, 2);
    final IbanLengthDefinition validIbanLength = IBAN_LENGTH_MAP.ibanLengths().get(countryCode);
    if (validIbanLength == null || valueAsString.replaceAll("\\s", StringUtils.EMPTY)
        .length() != validIbanLength.getLength()) {
      // unknown country or wrong length for the country!
      return false;
    }
    if (!valueAsString.matches("^[A-Z]{2}[0-9A-Z]{2} ([0-9A-Z]{4}[ ])+[0-9A-Z]{1,4}$")) {
      // wrong format
      return false;
    }

    return CHECK_IBAN.isValid(IbanUtil.ibanCompress(valueAsString));
  }
654602
protected function validateCountryAddress()
    {
        $field = 'country';
        $value = $this->getSubmitted($field);

        if (!isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $country = $this->country->get($value);
        $label = $this->translation->text('Country');

        if (empty($country)) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        return true;
    }
550460
@Override
    public CountryContract getCountryFromCode(String countryCode) {
        if(StringUtils.isBlank(countryCode)) return null;
        CountryContract country = getKcCountryService().getCountryByAlternateCode(countryCode);
        if(country==null){
            country = getKcCountryService().getCountry(countryCode);
        }
        return country;
    }
131687
@Override
  public String validateInProperty(String unit, String property) {
		assert checkStringParam(unit) : paramError("validate", "unit", "must not be null or empty");
		assert checkStringParam(property) : paramError("validateInProperty", "property", "must not be null or empty");
		try {
			Term term = new ExpressionParser(model).parse(unit);
			Canonical can = new Converter(model, handlers).convert(term);
			String cu = new ExpressionComposer().compose(can, false);
			if (can.getUnits().size() == 1) {
					if (property.equals(can.getUnits().get(0).getBase().getProperty()))
						return null;
					else
						return "unit "+unit+" is of the property type "+can.getUnits().get(0).getBase().getProperty()+" ("+cu+"), not "+property+" as required.";
			}
			// defined special case
			if ("concentration".equals(property) && ("g/L".equals(cu) || "mol/L".equals(cu)))
				return null;
			
			return "unit "+unit+" has the base units "+cu+", and are not from the property "+property+" as required.";
		} catch (Exception e) {
			return e.getMessage();
		}
	}
1254929
def countries(instance):
    
    if (instance['type'] == 'location' and 'country' in instance and not
            instance['country'].upper() in enums.COUNTRY_CODES):

        return JSONError("Location `country` should be a valid ISO 3166-1 "
                         "ALPHA-2 Code.",
                         instance['id'], 'marking-definition-type')