All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.jakaarl.iban.spi.CountryCodeValidation Maven / Gradle / Ivy

The newest version!
package io.github.jakaarl.iban.spi;

import java.util.Locale;
import java.util.SortedSet;
import java.util.TreeSet;

import io.github.jakaarl.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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy