|
| 1 | +package org.baeldung.javaxval.enums.demo; |
| 2 | + |
| 3 | +import javax.validation.constraints.NotNull; |
| 4 | + |
| 5 | +import org.baeldung.javaxval.enums.constraints.CustomerTypeSubset; |
| 6 | +import org.baeldung.javaxval.enums.constraints.EnumNamePattern; |
| 7 | +import org.baeldung.javaxval.enums.constraints.ValueOfEnum; |
| 8 | + |
| 9 | +public class Customer { |
| 10 | + @ValueOfEnum(enumClass = CustomerType.class) |
| 11 | + private String customerTypeString; |
| 12 | + |
| 13 | + @NotNull |
| 14 | + @CustomerTypeSubset(anyOf = { CustomerType.NEW, CustomerType.OLD }) |
| 15 | + private CustomerType customerTypeOfSubset; |
| 16 | + |
| 17 | + @EnumNamePattern(regexp = "NEW|DEFAULT") |
| 18 | + private CustomerType customerTypeMatchesPattern; |
| 19 | + |
| 20 | + public Customer() { |
| 21 | + } |
| 22 | + |
| 23 | + public Customer(String customerTypeString, CustomerType customerTypeOfSubset, CustomerType customerTypeMatchesPattern) { |
| 24 | + this.customerTypeString = customerTypeString; |
| 25 | + this.customerTypeOfSubset = customerTypeOfSubset; |
| 26 | + this.customerTypeMatchesPattern = customerTypeMatchesPattern; |
| 27 | + } |
| 28 | + |
| 29 | + public String getCustomerTypeString() { |
| 30 | + return customerTypeString; |
| 31 | + } |
| 32 | + |
| 33 | + public void setCustomerTypeString(String customerTypeString) { |
| 34 | + this.customerTypeString = customerTypeString; |
| 35 | + } |
| 36 | + |
| 37 | + public CustomerType getCustomerTypeOfSubset() { |
| 38 | + return customerTypeOfSubset; |
| 39 | + } |
| 40 | + |
| 41 | + public void setCustomerTypeOfSubset(CustomerType customerTypeOfSubset) { |
| 42 | + this.customerTypeOfSubset = customerTypeOfSubset; |
| 43 | + } |
| 44 | + |
| 45 | + public CustomerType getCustomerTypeMatchesPattern() { |
| 46 | + return customerTypeMatchesPattern; |
| 47 | + } |
| 48 | + |
| 49 | + public void setCustomerTypeMatchesPattern(CustomerType customerTypeMatchesPattern) { |
| 50 | + this.customerTypeMatchesPattern = customerTypeMatchesPattern; |
| 51 | + } |
| 52 | + |
| 53 | + public static class Builder { |
| 54 | + private String customerTypeString; |
| 55 | + private CustomerType customerTypeOfSubset = CustomerType.NEW; |
| 56 | + private CustomerType customerTypeMatchesPattern; |
| 57 | + |
| 58 | + public Builder withCustomerTypeString(String customerTypeString) { |
| 59 | + this.customerTypeString = customerTypeString; |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + public Builder withCustomerTypeOfSubset(CustomerType customerTypeOfSubset) { |
| 64 | + this.customerTypeOfSubset = customerTypeOfSubset; |
| 65 | + return this; |
| 66 | + } |
| 67 | + |
| 68 | + public Builder withCustomerTypeMatchesPattern(CustomerType customerTypeMatchesPattern) { |
| 69 | + this.customerTypeMatchesPattern = customerTypeMatchesPattern; |
| 70 | + return this; |
| 71 | + } |
| 72 | + |
| 73 | + public Customer build() { |
| 74 | + return new Customer(customerTypeString, customerTypeOfSubset, customerTypeMatchesPattern); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments