-
-
Save Freeongoo/305aeb5469a04472ebd6bf670d3efd14 to your computer and use it in GitHub Desktop.
Person Entity Using Builder Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.jmethods.catatumbo.Entity; | |
| import com.jmethods.catatumbo.Identifier; | |
| import com.jmethods.catatumbo.Property; | |
| @Entity | |
| public class Person { | |
| @Identifier | |
| private final long id; | |
| @Property(name = "fname") | |
| private final String firstName; | |
| @Property(name = "lname") | |
| private final String lastName; | |
| @Property(indexed = false) | |
| private final int birthYear; | |
| private final boolean citizen; | |
| private Person(PersonBuilder builder) { | |
| this.id = builder.id; | |
| this.firstName = builder.firstName; | |
| this.lastName = builder.lastName; | |
| this.birthYear = builder.birthYear; | |
| this.citizen = builder.citizen; | |
| } | |
| public long getId() { | |
| return id; | |
| } | |
| public String getFirstName() { | |
| return firstName; | |
| } | |
| public String getLastName() { | |
| return lastName; | |
| } | |
| public int getBirthYear() { | |
| return birthYear; | |
| } | |
| public boolean isCitizen() { | |
| return citizen; | |
| } | |
| public static PersonBuilder newBuilder() { | |
| return new PersonBuilder(); | |
| } | |
| public static class PersonBuilder { | |
| private long id; | |
| private String firstName; | |
| private String lastName; | |
| private int birthYear; | |
| private boolean citizen; | |
| public void setId(long id) { | |
| this.id = id; | |
| } | |
| public void setFirstName(String firstName) { | |
| this.firstName = firstName; | |
| } | |
| public void setLastName(String lastName) { | |
| this.lastName = lastName; | |
| } | |
| public void setBirthYear(int birthYear) { | |
| this.birthYear = birthYear; | |
| } | |
| public void setCitizen(boolean citizen) { | |
| this.citizen = citizen; | |
| } | |
| public Person build() { | |
| return new Person(this); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment