Skip to content

Irish PPSN ID Number#1559

Merged
kingthorin merged 25 commits intodatafaker-net:mainfrom
89snake89:main
Jun 4, 2025
Merged

Irish PPSN ID Number#1559
kingthorin merged 25 commits intodatafaker-net:mainfrom
89snake89:main

Conversation

@89snake89
Copy link
Copy Markdown
Contributor

Irish PPSN ID Number

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented May 26, 2025

PR Summary

  • Introduction of a New Class
    A new class named IrishIdNumber has been added. This class is designed specifically for the creation and verification of Irish Personal Public Service Numbers (PPSN), an important identification code in Ireland.

  • Inclusion of Specific Methods
    Special methods have been incorporated within the class. These enable the generation of both correct and incorrect PPSN codes, in accordance with the official set of rules and specifications.

  • Introduction of Checksum Validation
    An intricate procedure, known as a Modulo 23 algorithm, has been used to implement checksum validation. This procedure ensures that the PPSN codes align with the necessary standard requirements.

  • Extension of Existing IdNumberPatterns
    The existing IdNumberPatterns has been expanded with the addition of a new regex pattern. This pattern is specifically designed for Irish IDs.

  • Development of Unit Tests
    A set of unit tests, named IrishIdNumberTest, has been put in place. These tests serve to confirm and verify the functionality of creating both valid and invalid Irish ID codes.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 26, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 77.50000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 92.45%. Comparing base (3af0054) to head (6ca6258).

Files with missing lines Patch % Lines
...in/java/net/datafaker/idnumbers/IrishIdNumber.java 77.50% 4 Missing and 5 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1559      +/-   ##
============================================
- Coverage     92.58%   92.45%   -0.13%     
- Complexity     3315     3329      +14     
============================================
  Files           329      330       +1     
  Lines          6510     6550      +40     
  Branches        632      643      +11     
============================================
+ Hits           6027     6056      +29     
- Misses          335      339       +4     
- Partials        148      155       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asolntsev asolntsev added this to the 2.4.4 milestone May 26, 2025
@asolntsev asolntsev added the enhancement New feature or request label May 26, 2025
public class IrishIdNumberTest {
private static final Logger LOG = Logger.getLogger(IrishIdNumberTest.class.getName());
private final IrishIdNumber irishIdNumber = new IrishIdNumber();
private final Faker faker = new Faker(new Locale("ie", "IE"));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@89snake89 Wait, isn't "ga" the language code of Ireland (Irish Gaelic)?
While "ie" is the code of international auxiliary language "Interlingue".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ireland has 2 official languages English (mostly used) and Irish Gaelic (very few people can speak it)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini's summary:

The ISO 639-1 language code for Irish (Ireland) is ga. The corresponding locale code, which combines the language and country, is ga-IE. This indicates the Irish language as spoken in Ireland.

Copy link
Copy Markdown
Collaborator

@asolntsev asolntsev May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@89snake89 In this specific test language is not used at all, so it's not critical. :)
BUT
To avoid confusion, let's use

  • either new Locale("en", "IE") (which means English language)
  • or new Locale("ga", "IE") (which means Gaelic language)

But not new Locale("ie", "IE") because "ie" stands for "Interlingue" language, not English.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, my mistake it must be new Locale("en", "IE")

return ppsn.toString();
}

public boolean validateAndCheckModulo23(String ppsn) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this method non-public (so called "package private").
Or wait, why this method is needed at all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to have a separate method to divide and test the validity of the PPSN

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea to split code into smaller methods and test them separately.
But I assume you don't expect your users to call this method, right? @89snake89

But then remove keyword "public" from such methods.

  1. Then it becomes "package-private", and you can still can call this method from tests.
  2. But end-users cannot call this method.

@Override
public String generateInvalid(final BaseProviders faker) {
// Generate 7 digits
Random random = new Random();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we don't use new Random() in DataFaker.
Instead, please use faker methods, e.g.

String digits = faker.number().digits(7);

It's good for reproducible result.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Idea! Thank you


@Override
public String generateValid(final BaseProviders faker) {
Random random = new Random();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of new Random(), please use faker methods, e.g.

String digits = faker.number().digits(7);
boolean addSuffix = faker.bool().bool();
String suffix = addSuffix ? faker.options().option(allowedSuffixes) : "";

etc.

Comment on lines +47 to +49
String digits = faker.number().digits(7);
// Append always invalid character (es: 'Z')
return digits + "Z";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could combine the two and return directly avoiding the intermediate store of digits

Comment on lines +59 to +60
boolean addSuffix = random.nextBoolean(); // 50% chance
String suffix = addSuffix ? allowedSuffixes[random.nextInt(allowedSuffixes.length)] : "";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too, you could inline the random Boolean and skip the intermediate assignment

Comment on lines +84 to +86
for (int d : digits) {
ppsn.append(d);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digits is a string right? Just append it directly.

return ppsn.toString();
}

public boolean validateAndCheckModulo23(String ppsn) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still public

}
sum += (c - '0') * weights[i];
}
// if there is a suffic incude it in the checksum
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suffix

@kingthorin
Copy link
Copy Markdown
Collaborator

Seems to need a spotless apply

@89snake89 89snake89 requested a review from asolntsev June 3, 2025 18:32
Copy link
Copy Markdown
Collaborator

@kingthorin kingthorin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kingthorin kingthorin merged commit d8623b6 into datafaker-net:main Jun 4, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants