<commit_before>package com.github.mizool.core.validation;

import java.util.Locale;
import java.util.Set;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.google.common.collect.ImmutableSet;

public class CheckCountryCode implements ConstraintValidator<CountryCode, Object>
{
    private static final Set<String> COUNTRY_CODES = ImmutableSet.copyOf(Locale.getISOCountries());

    private boolean mandatory;

    @Override
    public void initialize(CountryCode countryCode)
    {
        mandatory = countryCode.mandatory();
    }

    @Override
    public boolean isValid(Object validationObject, ConstraintValidatorContext constraintValidatorContext)
    {
        return ConstraintValidators.isValid(validationObject, mandatory, this::isValidValue);
    }

    private boolean isValidValue(Object validationObject)
    {
        boolean valid = false;
        if (validationObject instanceof String)
        {
            String validationString = (String) validationObject;
            return !validationString.isEmpty() && COUNTRY_CODES.contains(validationString);
        }
        return valid;
    }
}<commit_msg>Refactored early return.<commit_after>package com.github.mizool.core.validation;

import java.util.Locale;
import java.util.Set;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.google.common.collect.ImmutableSet;

public class CheckCountryCode implements ConstraintValidator<CountryCode, Object>
{
    private static final Set<String> COUNTRY_CODES = ImmutableSet.copyOf(Locale.getISOCountries());

    private boolean mandatory;

    @Override
    public void initialize(CountryCode countryCode)
    {
        mandatory = countryCode.mandatory();
    }

    @Override
    public boolean isValid(Object validationObject, ConstraintValidatorContext constraintValidatorContext)
    {
        return ConstraintValidators.isValid(validationObject, mandatory, this::isValidValue);
    }

    private boolean isValidValue(Object validationObject)
    {
        boolean valid = false;
        if (validationObject instanceof String)
        {
            String validationString = (String) validationObject;
            valid = !validationString.isEmpty() && COUNTRY_CODES.contains(validationString);
        }
        return valid;
    }
}
{'fraction_non_alphanumeric': 0.07653490328006729, 'fraction_numerical': 0.0, 'mean_word_length': 3.885010266940452, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4942211', 'n_tokens_mistral': 592, 'n_tokens_neox': 590, 'n_words': 132}