Skip to content

Commit

Permalink
#1214 [refactoring] rename "IdNumbers" to "IdNumberGenerator"
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed May 29, 2024
1 parent 7b45d89 commit 3a57f20
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* The Albanian Identity Number is a unique personal identification number of 10 characters in the format YYMMDDSSSC
*/
public class AlbanianIdNumber implements IdNumbers {
public class AlbanianIdNumber implements IdNumberGenerator {
private static final String FIRST_CHAR = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String CHECKSUM_CHAR = "WABCDEFGHIJKLMNOPQRSTUV";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.regex.Pattern;

public class AmericanIdNumber implements IdNumbers {
public class AmericanIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "US";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* <a href="https://en.wikipedia.org/wiki/Unique_citizenship_number">Specification</a>
*/
public class BulgarianIdNumber implements IdNumbers {
public class BulgarianIdNumber implements IdNumberGenerator {
private static final int[] CHECKSUM_WEIGHTS = {2, 4, 8, 5, 10, 9, 7, 3, 6};
private static final int[] EVEN_DIGITS = {0, 2, 4, 6, 8};
private static final int[] ODD_DIGITS = {1, 3, 5, 7, 9};
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/datafaker/idnumbers/ChineseIdNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author irakatz
*/
public class ChineseIdNumber implements IdNumbers {
public class ChineseIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "CN";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* <p>
* and <a href="https://en.wikipedia.org/wiki/National_identification_number#Estonia">Estonian identification number</a>
*/
public class EstonianIdNumber implements IdNumbers {
public class EstonianIdNumber implements IdNumberGenerator {
private static final DateTimeFormatter BIRTHDAY_FORMAT = DateTimeFormatter.ofPattern("yyMMdd");
private static final int[] CHECKSUM_COEFFICIENTS = {1, 2, 3, 4, 5, 6, 7, 8, 9, 1};
private static final int[] CHECKSUM_COEFFICIENTS2 = {3, 4, 5, 6, 7, 8, 9, 1, 2, 3};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Generates ID numbers for Georgian citizens and Residents
*/
public class GeorgianIdNumber implements IdNumbers {
public class GeorgianIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "GE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.time.format.DateTimeFormatter;

public interface IdNumbers {
public interface IdNumberGenerator {
DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMdd");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* <a href="https://en.wikipedia.org/wiki/National_identification_number#North_Macedonia">Intro</a>
* <a href="https://en.wikipedia.org/wiki/Unique_Master_Citizen_Number">Specification</a>
*/
public class MacedonianIdNumber implements IdNumbers {
public class MacedonianIdNumber implements IdNumberGenerator {
private static final List<String> REGIONS = List.of("41", "42", "43", "44", "45", "46", "47", "48", "49");

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/datafaker/idnumbers/MexicanIdNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Implementation based on the definition at
* <a href="https://en.wikipedia.org/wiki/Unique_Population_Registry_Code">https://en.wikipedia.org/wiki/Unique_Population_Registry_Code</a>
*/
public class MexicanIdNumber implements IdNumbers {
public class MexicanIdNumber implements IdNumberGenerator {

@Override
public String countryCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* <a href="https://taxid.pro/docs/countries/moldova">Overview</a>
* <a href="https://taxid.pro/?example=moldova-tin-for-individuals">Online generator</a>
*/
public class MoldovanIdNumber implements IdNumbers {
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};

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/datafaker/idnumbers/PolishIdNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* <a href="https://isap.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU20210000510">https://isap.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU20210000510</a> and the
* description at <a href="https://en.wikipedia.org/wiki/PESEL">https://en.wikipedia.org/wiki/PESEL</a>
*/
public class PolishIdNumber implements IdNumbers {
public class PolishIdNumber implements IdNumberGenerator {

public static final int PESEL_LENGTH = 11;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* See <a href="https://pt.wikipedia.org/wiki/N%C3%BAmero_de_identifica%C3%A7%C3%A3o_fiscal">Número de identificação fiscal</a>
* and <a href="https://en.wikipedia.org/wiki/VAT_identification_number">VAT identification number</a>
*/
public class PortugueseIdNumber implements IdNumbers {
public class PortugueseIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "PT";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/datafaker/idnumbers/SingaporeIdNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Generate number of UIN/FIN for Singapore.
* Algorithm is given from <a href="http://www.ngiam.net/NRIC/">http://www.ngiam.net/NRIC/</a>
*/
public class SingaporeIdNumber implements IdNumbers {
public class SingaporeIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "SG";
}

public enum Type {SINGAPOREAN_TWENTIETH_CENTURY, FOREIGNER_TWENTIETH_CENTURY, SINGAPOREAN_TWENTY_FIRST_CENTURY, FOREIGNER_TWENTY_FIRST_CENTURY;}
public enum Type {SINGAPOREAN_TWENTIETH_CENTURY, FOREIGNER_TWENTIETH_CENTURY, SINGAPOREAN_TWENTY_FIRST_CENTURY, FOREIGNER_TWENTY_FIRST_CENTURY}

private record NricType(char firstLetter, String matchLetters, int[] code, int initialValue) {
private String format(int[] digits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Implementation based on the definition at
* <a href="https://en.wikipedia.org/wiki/South_African_identity_card">https://en.wikipedia.org/wiki/South_African_identity_card</a>
*/
public class SouthAfricanIdNumber implements IdNumbers {
public class SouthAfricanIdNumber implements IdNumberGenerator {

@Override
public String countryCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Implementation based on the description at
* <a href="https://en.wikipedia.org/wiki/Resident_registration_number">Wikipedia - Resident registration number</a>
*/
public class SouthKoreanIdNumber implements IdNumbers {
public class SouthKoreanIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "KR";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/datafaker/idnumbers/SwedenIdNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* and the description at
* <a href="https://en.wikipedia.org/wiki/Personal_identity_number_">https://en.wikipedia.org/wiki/Personal_identity_number_</a>(Sweden)
*/
public class SwedenIdNumber implements IdNumbers {
public class SwedenIdNumber implements IdNumberGenerator {
@Override
public String countryCode() {
return "SE";
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/datafaker/providers/base/IdNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.datafaker.idnumbers.AmericanIdNumber;
import net.datafaker.idnumbers.MexicanIdNumber;
import net.datafaker.idnumbers.IdNumbers;
import net.datafaker.idnumbers.IdNumberGenerator;
import net.datafaker.idnumbers.SouthKoreanIdNumber;
import net.datafaker.idnumbers.SingaporeIdNumber;
import net.datafaker.idnumbers.SingaporeIdNumber.Type;
Expand All @@ -25,13 +25,13 @@
*/
public class IdNumber extends AbstractProvider<BaseProviders> {

private final Map<Class<? extends IdNumbers>, IdNumbers> providers = new ConcurrentHashMap<>();
private final Map<String, IdNumbers> countryProviders = new ConcurrentHashMap<>();
private final Map<Class<? extends IdNumberGenerator>, IdNumberGenerator> providers = new ConcurrentHashMap<>();
private final Map<String, IdNumberGenerator> countryProviders = new ConcurrentHashMap<>();

protected IdNumber(BaseProviders faker) {
super(faker);
List<IdNumbers> idNumbers = loadGenerators(IdNumbers.class);
for (IdNumbers idNumber : idNumbers) {
List<IdNumberGenerator> idNumbers = loadGenerators(IdNumberGenerator.class);
for (IdNumberGenerator idNumber : idNumbers) {
countryProviders.put(idNumber.countryCode(), idNumber);
}
}
Expand All @@ -48,7 +48,7 @@ public String invalid() {
.orElseGet(() -> faker.numerify(faker.resolve("id_number.invalid")));
}

private Optional<IdNumbers> countryProvider() {
private Optional<IdNumberGenerator> countryProvider() {
String country = faker.getContext().getLocale().getCountry();
return Optional.ofNullable(countryProviders.get(country));
}
Expand Down Expand Up @@ -236,11 +236,11 @@ public String validGeIDNumber() {
}

@SuppressWarnings("unchecked")
private <T extends IdNumbers> T provider(Class<T> clazz) {
private <T extends IdNumberGenerator> T provider(Class<T> clazz) {
return (T) providers.computeIfAbsent(clazz, aClass -> create(clazz));
}

private <T extends IdNumbers> T create(Class<T> clazz) {
private <T extends IdNumberGenerator> T create(Class<T> clazz) {
try {
return clazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
Expand Down

0 comments on commit 3a57f20

Please sign in to comment.