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

net.datafaker.idnumbers.MoldovanIdNumber Maven / Gradle / Ivy

package net.datafaker.idnumbers;

import net.datafaker.providers.base.BaseProviders;

import java.time.LocalDate;

/**
 * The Moldovan Individual Tax ID Number is 13 digits.
 * 

* For Individuals, Example: 4234567891236 * Specification * Overview * Online generator */ public class MoldovanIdNumber implements IdNumberGenerator { private static final int[] CHECKSUM_MASK = new int[]{7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1}; @Override public String countryCode() { return "MD"; } @Override public String generateValid(BaseProviders faker) { String basePart = basePart(faker); return basePart + checksum(basePart); } @Override public String generateInvalid(BaseProviders faker) { String basePart = basePart(faker); return basePart + (checksum(basePart) + 1) % 10; } private String basePart(BaseProviders faker) { var birthday = faker.timeAndDate().birthday(0, 120); // IDNP: 2ГГГXXXYYYYYK return firstDigit() + ГГГ(birthday) + XXX(faker) + YYYYY(faker); } /** * 2 - the identification index of the natural person in the multitude of state identifiers (?) */ private char firstDigit() { return '2'; } /** * ГГГ- the last three digits of the IDNP award year */ private String ГГГ(LocalDate birthday) { return "%03d".formatted(birthday.getYear() % 1000); } /** * XXX - code of the registrar's office */ private String XXX(BaseProviders faker) { return faker.number().digits(3); } /** * YYYYY- the order number of the registration in the respective year in the respective office */ private String YYYYY(BaseProviders faker) { return faker.number().digits(5); } char checksum(String text) { int checksum = 0; for (int i = 0; i < text.length(); i++) { checksum += digitAt(text, i) * CHECKSUM_MASK[i]; } return (char) ('0' + checksum % 10); } private int digitAt(String text, int index) { return text.charAt(index) - '0'; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy