Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Data
- @Embeddable // spłaszczenie struktury na poziomie bazy danych, nie zostanie stworzona nowa tabelka dla tej klasy
- public class CreditCardNumber {
- private static final String regex = "[0-9]{16}";
- @Column(unique = true) // zapewnienie unikalności na poziomie bazy danych
- private final String number;
- public CreditCardNumber(String number) {
- if (!isValid(number)) { // walidacja numeru karty kredytowej w momencie tworzenia
- throw new IllegalArgumentException(String.format("Invalid credit card NUMBER %s!", number));
- }
- this.number = number;
- }
- private boolean isValid(String number) {
- return number == null ? false : number.matches(regex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement