sombraglez / ahv-validator

Simple Java validator for AHV (Swiss Social Security) Numbers
GNU General Public License v2.0
3 stars 0 forks source link

Is this maintained? Can this be published to Maven repo? #1

Open igorpupkinable opened 3 years ago

igorpupkinable commented 3 years ago

Great work! It would be handy to publish this to Maven Central if possible, so we could add this to our project as a dependency.

igorpupkinable commented 3 years ago

Please find a code to generate AHV nummer in case you need this (e.g. automation tests)

public static String generateAhv() {
    List<Integer> ssn = new ArrayList<>();
    ssn.add(7);
    ssn.add(5);
    ssn.add(6);
    for (int i = 0; i < 9; i++) {
        int r = new Random().nextInt(10);
        ssn.add(r);
    }
    int sum = 0;
    for (int i = 0; i < ssn.size(); i++) {
        sum += ssn.get(i) * (i % 2 == 0 ? 1 : 3);
    }
    int lastDigit = 10 - (sum % 10);
    lastDigit = lastDigit == 10 ? 0 : lastDigit;
    ssn.add(lastDigit);
    StringBuilder sb = new StringBuilder();
    ssn.forEach(sb::append);
    return sb.toString();
}