Skip to content

Commit

Permalink
Add line breakes, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
viepovsky committed Dec 18, 2023
1 parent f979139 commit ad8c19c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
* </ul>
*/
public class InvalidPeselException extends RuntimeException {

/**
* Constructs a {@code InvalidPeselException} with the specified
* detail message.
*
* @param message the detail message.
* @param message the detail message.
*/
InvalidPeselException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* <blockquote><pre>
* Pesel pesel = new Pesel("92082683499");
* </pre></blockquote>
* and then you can access the PESEL values:
* and then you can access the PESEL values:
* <blockquote><pre>
* String gender = pesel.getGender();
* LocalDate birthDate = pesel.getBirthDate();
Expand All @@ -31,10 +31,12 @@
* @author Oskar Rajzner
*/
public class Pesel extends PeselDigits {

/**
* The date of birth decoded from the given PESEL.
*/
private final LocalDate birthDate;

/**
* The gender decoded from the given PESEL.
*/
Expand All @@ -56,7 +58,7 @@ public Pesel(String pesel) {
* Validates given PESEL, decodes and stores date of birth, gender and sets PESEL digits.
*
* @param peselDecoder an instance of the {@code PeselDecoder} class
* @param pesel the PESEL number
* @param pesel the PESEL number
* @throws InvalidPeselException if the given PESEL is invalid
*/
private Pesel(PeselDecoder peselDecoder, String pesel) {
Expand All @@ -81,6 +83,7 @@ private Pesel(PeselDecoder peselDecoder, String pesel) {
public String getGender() {
return String.valueOf(gender);
}

/**
* Returns decoded date of birth of given PESEL number.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
* @author Oskar Rajzner
*/
final class PeselDecoder {

/**
* Decodes the date of birth from given PESEL.
*
* @param pesel the PESEL number
* @return the date of birth as a LocalDate object
*/
Expand Down Expand Up @@ -46,6 +48,7 @@ LocalDate decodeBirthDate(String pesel) {

/**
* Decodes the gender from given PESEL.
*
* @param pesel the PESEL number
* @return the gender as a Pesel.Gender enum
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
* @author Oskar Rajzner
*/
abstract class PeselDigits {

/**
* Year, month, and day digits of the PESEL number in form of YYMMDD (digits 1-6).
*/
private int birthDateDigits;

/**
* Unique serial digits of the PESEL in form of ZZZ (digits 7-9).
*/
private int serialDigits;

/**
* Gender digit of the PESEL in form of X (digit 10).
*/
private int genderDigit;

/**
* Control sum digit of the PESEL in form of Q (digit 11).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,27 @@
* @see PeselGeneratorParams
*/
public class PeselGenerator {

/**
* Digits weights for calculating the control digit of the PESEL.
*/
private static final int[] CONTROL_WEIGHTS = new int[]{1, 3, 7, 9, 1, 3, 7, 9, 1, 3};

/**
* A random number generator used for generating PESEL numbers.
*/
private static final Random RANDOM = new Random();

/**
* The gender that will be included in the generated PESEL numbers.
*/
private static PeselGeneratorParams.Gender gender;

/**
* The minimum date range from which a PESEL number will be generated.
*/
private final LocalDate minDate;

/**
* The maximum date range to which a PESEL number will be generated.
*/
Expand Down Expand Up @@ -181,7 +186,6 @@ private static String getRandomSerialDigits() {
return String.valueOf(RANDOM.nextInt(10)) + RANDOM.nextInt(10) + RANDOM.nextInt(10);
}


/**
* Generates a random digit to represent the gender in the PESEL number. If a gender is specified,
* the PESEL will be generated with that gender. If no gender is specified, the generated gender will be random.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,43 @@
* @see PeselGenerator
*/
public class PeselGeneratorParams {

/**
* The earliest possible date from which a PESEL number can be generated.
*/
private static final LocalDate MIN_DATE_POSSIBLE = LocalDate.of(1800, 1, 1);

/**
* The latest possible date to which a PESEL number can be generated.
*/
private static final LocalDate MAX_DATE_POSSIBLE = LocalDate.of(2299, 12, 31);

/**
* The default earliest date from which a PESEL number can be generated,
* which is 100 years before the current date.
*/
private static final LocalDate DEFAULT_MIN_DATE = LocalDate.now().minusYears(100);

/**
* The default latest date to which a PESEL number can be generated, which is the current date.
*/
private static final LocalDate DEFAULT_MAX_DATE = LocalDate.now();

/**
* The gender that will be included in the generated PESEL numbers.
*/
private final Gender gender;

/**
* The earliest date from which a PESEL number will be generated.
*/
private LocalDate minDate;

/**
* The latest date to which a PESEL number will be generated.
*/
private LocalDate maxDate;


/**
* Constructs a new PeselGeneratorParams object using the Builder pattern.
* It validates input dates values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
* @author Oskar Rajzner
*/
public abstract class PeselValidator {

/**
* Digits weight for checking the validity of the PESEL
*/
private static final int[] CONTROL_WEIGHTS = new int[]{1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1};

/**
* An instance of the {@code PeselDecoder} class.
*/
Expand Down

0 comments on commit ad8c19c

Please sign in to comment.