https://github.com/vladislavgoltjajev/java-isikukood
Library for working with Estonian personal identification codes (isikukood).
https://github.com/vladislavgoltjajev/java-isikukood
isikukood java java-isikukood java8 parser personal-code
Last synced: 30 days ago
JSON representation
Library for working with Estonian personal identification codes (isikukood).
- Host: GitHub
- URL: https://github.com/vladislavgoltjajev/java-isikukood
- Owner: vladislavgoltjajev
- License: mit
- Created: 2018-06-20T20:38:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-04T22:01:41.000Z (over 4 years ago)
- Last Synced: 2023-07-02T07:37:24.276Z (over 2 years ago)
- Topics: isikukood, java, java-isikukood, java8, parser, personal-code
- Language: Java
- Homepage:
- Size: 95.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :exclamation::exclamation::exclamation: Library is no longer supported :exclamation::exclamation::exclamation:
Development moved to [this](https://github.com/vladislavgoltjajev/java-personal-code) repo.
# java-isikukood
[](https://github.com/vladislavgoltjajev/java-isikukood/blob/master/LICENSE)
Extract personal data from and generate Estonian personal identification codes (isikukood) with this lightweight library.
## Import
The library is available on Maven Central and JCenter.
JDK 8 or higher is required for the library to work.
### Gradle
```groovy
dependencies {
implementation 'com.github.vladislavgoltjajev:java-isikukood:2.1'
}
```
### Maven
```xml
com.github.vladislavgoltjajev
java-isikukood
2.1
```
## Usage
```java
public class Test {
public static void main(String[] args) {
EstonianId estonianId = new EstonianId("47508030046");
boolean isValid = estonianId.isValid(); // true
String gender = estonianId.getGender(); // F
LocalDate dateOfBirth = estonianId.getDateOfBirth(); // 1975-08-03
Integer age = estonianId.getAge(); // 43
EstonianId invalidEstonianId = new EstonianId("123");
isValid = invalidEstonianId.isValid(); // false
gender = invalidEstonianId.getGender(); // null
dateOfBirth = invalidEstonianId.getDateOfBirth(); // null
age = invalidEstonianId.getAge(); // null
String personalCode = EstonianId.generateRandomPersonalCode(); // 35207049817
try {
gender = EstonianId.MALE;
dateOfBirth = LocalDate.of(1984, 3, 15);
personalCode = EstonianId.generatePersonalCode(gender, dateOfBirth); // 38403153949
personalCode = EstonianId.generatePersonalCode(gender, dateOfBirth, 7); // 38403150076
personalCode = EstonianId.generatePersonalCode("A", LocalDate.of(1799, 1, 1)); // Throws exception.
} catch (EstonianIdException e) {
// Handle exception.
}
}
}
```
## API
### Field summary
Modifier and type
Field
Description
static String
FEMALE
Female gender classifier "F".
static String
MALE
Male gender classifier "M".
### Constructor summary
Constructor
Description
EstonianId(String personalCode)
Constructs a new EstonianId object using the specified personal code.
### Method summary
Modifier and type
Method
Description
static String
generatePersonalCode(String gender, LocalDate dateOfBirth)
Generates a personal code using the specified gender and date of birth. Throws an exception if the gender is not "M" or "F" or the birth year is before 1800 or after 2099.
static String
generatePersonalCode(String gender, LocalDate dateOfBirth, int birthOrderNumber)
Generates a personal code using the specified gender, date of birth and birth order number. Throws an exception if the gender is not "M" or "F", the birth year is before 1800 or after 2099 or the birth order number is less than 0 or more than 999.
static String
generateRandomPersonalCode()
Generates a random personal code.
Integer
getAge()
Calculates the person's age in years. Returns null if the personal code is invalid or the date of birth is in the future.
LocalDate
getDateOfBirth()
Returns the person's date of birth. Returns null if the personal code is invalid.
String
getGender()
Returns the person's gender ("M" or "F"). Returns null if the personal code is invalid.
boolean
isValid()
Returns whether or not the personal code is valid.
## Buy me a beer? :beer:
Please [donate](https://www.paypal.me/VladislavGoltjajev) if you like my work.