fi.kapsi.killnine.iban.spi.CountryCodeValidation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iban-validator Show documentation
Show all versions of iban-validator Show documentation
A Java library for IBAN validation
The newest version!
package fi.kapsi.killnine.iban.spi;
import java.util.Locale;
import java.util.SortedSet;
import java.util.TreeSet;
import fi.kapsi.killnine.iban.Iban;
/**
* An {@link IbanValidation} which checks that the IBAN contains a valid country code. Here "valid" simply
* means, that {@link Locale#getISOCountries()} includes the country code.
*/
public class CountryCodeValidation implements IbanValidation {
private final SortedSet isoCountries;
public CountryCodeValidation() {
this.isoCountries = new TreeSet();
for (String countryCode : Locale.getISOCountries()) {
isoCountries.add(countryCode);
}
}
@Override
public boolean canValidate(Iban iban) {
return true;
}
@Override
public boolean isValid(Iban iban) {
return isoCountries.contains(iban.countryCode);
}
}