@Test void should_allow_empty_list() { assertThat(validate(new ArrayList<>())).isEmpty(); }
public static List<String> validate(List<String> countryCodes) { List<String> upperCaseCountries = Objects.requireNonNull(countryCodes).stream() .map(String::toUpperCase) .collect(toList()); List<String> invalidCodes = upperCaseCountries.stream() .filter(s -> CountryCode.getByAlpha2Code(s) == null) .collect(toList()); if (!invalidCodes.isEmpty()) { throw new IllegalArgumentException( "Following elements (" + invalidCodes + ") are not valid ISO 3166-1 alpha-2 country codes"); } List<String> uniqueCountries = upperCaseCountries.stream().distinct().collect(toList()); if (uniqueCountries.size() < countryCodes.size()) { logger.warn("Duplicate items were removed from {}", countryCodes); } return uniqueCountries; }
CountryCodeValidator { public static List<String> validate(List<String> countryCodes) { List<String> upperCaseCountries = Objects.requireNonNull(countryCodes).stream() .map(String::toUpperCase) .collect(toList()); List<String> invalidCodes = upperCaseCountries.stream() .filter(s -> CountryCode.getByAlpha2Code(s) == null) .collect(toList()); if (!invalidCodes.isEmpty()) { throw new IllegalArgumentException( "Following elements (" + invalidCodes + ") are not valid ISO 3166-1 alpha-2 country codes"); } List<String> uniqueCountries = upperCaseCountries.stream().distinct().collect(toList()); if (uniqueCountries.size() < countryCodes.size()) { logger.warn("Duplicate items were removed from {}", countryCodes); } return uniqueCountries; } }
CountryCodeValidator { public static List<String> validate(List<String> countryCodes) { List<String> upperCaseCountries = Objects.requireNonNull(countryCodes).stream() .map(String::toUpperCase) .collect(toList()); List<String> invalidCodes = upperCaseCountries.stream() .filter(s -> CountryCode.getByAlpha2Code(s) == null) .collect(toList()); if (!invalidCodes.isEmpty()) { throw new IllegalArgumentException( "Following elements (" + invalidCodes + ") are not valid ISO 3166-1 alpha-2 country codes"); } List<String> uniqueCountries = upperCaseCountries.stream().distinct().collect(toList()); if (uniqueCountries.size() < countryCodes.size()) { logger.warn("Duplicate items were removed from {}", countryCodes); } return uniqueCountries; } private  CountryCodeValidator(); }
CountryCodeValidator { public static List<String> validate(List<String> countryCodes) { List<String> upperCaseCountries = Objects.requireNonNull(countryCodes).stream() .map(String::toUpperCase) .collect(toList()); List<String> invalidCodes = upperCaseCountries.stream() .filter(s -> CountryCode.getByAlpha2Code(s) == null) .collect(toList()); if (!invalidCodes.isEmpty()) { throw new IllegalArgumentException( "Following elements (" + invalidCodes + ") are not valid ISO 3166-1 alpha-2 country codes"); } List<String> uniqueCountries = upperCaseCountries.stream().distinct().collect(toList()); if (uniqueCountries.size() < countryCodes.size()) { logger.warn("Duplicate items were removed from {}", countryCodes); } return uniqueCountries; } private  CountryCodeValidator(); static List<String> validate(List<String> countryCodes); }
CountryCodeValidator { public static List<String> validate(List<String> countryCodes) { List<String> upperCaseCountries = Objects.requireNonNull(countryCodes).stream() .map(String::toUpperCase) .collect(toList()); List<String> invalidCodes = upperCaseCountries.stream() .filter(s -> CountryCode.getByAlpha2Code(s) == null) .collect(toList()); if (!invalidCodes.isEmpty()) { throw new IllegalArgumentException( "Following elements (" + invalidCodes + ") are not valid ISO 3166-1 alpha-2 country codes"); } List<String> uniqueCountries = upperCaseCountries.stream().distinct().collect(toList()); if (uniqueCountries.size() < countryCodes.size()) { logger.warn("Duplicate items were removed from {}", countryCodes); } return uniqueCountries; } private  CountryCodeValidator(); static List<String> validate(List<String> countryCodes);  }