feat: add builder pattern for Firearm, Modification, User, UserCredential, and UserCredentialId classes
This commit is contained in:
@@ -140,5 +140,88 @@ public class Firearm {
|
||||
this.modifications.remove(modification);
|
||||
modification.setFirearm(null);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private FirearmType type;
|
||||
private String level;
|
||||
private String review;
|
||||
private String calibre;
|
||||
private Integer fireRate;
|
||||
private Integer armourDamage;
|
||||
private Integer bodyDamage;
|
||||
private List<Modification> modifications;
|
||||
|
||||
public Builder id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(FirearmType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder level(String level) {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder review(String review) {
|
||||
this.review = review;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder calibre(String calibre) {
|
||||
this.calibre = calibre;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder fireRate(Integer fireRate) {
|
||||
this.fireRate = fireRate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder armourDamage(Integer armourDamage) {
|
||||
this.armourDamage = armourDamage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bodyDamage(Integer bodyDamage) {
|
||||
this.bodyDamage = bodyDamage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder modifications(List<Modification> modifications) {
|
||||
this.modifications = modifications;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Firearm build() {
|
||||
Firearm firearm = new Firearm();
|
||||
firearm.id = this.id;
|
||||
firearm.name = this.name;
|
||||
firearm.type = this.type;
|
||||
firearm.level = this.level;
|
||||
firearm.review = this.review;
|
||||
firearm.calibre = this.calibre;
|
||||
firearm.fireRate = this.fireRate;
|
||||
firearm.armourDamage = this.armourDamage;
|
||||
firearm.bodyDamage = this.bodyDamage;
|
||||
firearm.modifications = this.modifications == null ? new ArrayList<>() : this.modifications;
|
||||
return firearm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,5 +116,74 @@ public class Modification {
|
||||
public void setVideoUrl(String videoUrl) {
|
||||
this.videoUrl = videoUrl;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Long id;
|
||||
private Firearm firearm;
|
||||
private String name;
|
||||
private String code;
|
||||
private List<String> tags;
|
||||
private String note;
|
||||
private String author;
|
||||
private String videoUrl;
|
||||
|
||||
public Builder id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder firearm(Firearm firearm) {
|
||||
this.firearm = firearm;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder code(String code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder note(String note) {
|
||||
this.note = note;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder author(String author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder videoUrl(String videoUrl) {
|
||||
this.videoUrl = videoUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Modification build() {
|
||||
Modification modification = new Modification();
|
||||
modification.id = this.id;
|
||||
modification.firearm = this.firearm;
|
||||
modification.name = this.name;
|
||||
modification.code = this.code;
|
||||
modification.tags = this.tags == null ? new ArrayList<>() : this.tags;
|
||||
modification.note = this.note;
|
||||
modification.author = this.author;
|
||||
modification.videoUrl = this.videoUrl;
|
||||
return modification;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +70,45 @@ public class User {
|
||||
this.credentials.remove(credential);
|
||||
credential.setUser(null);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Long id;
|
||||
private String username;
|
||||
private String email;
|
||||
private List<UserCredential> credentials;
|
||||
|
||||
public Builder id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder username(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder email(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder credentials(List<UserCredential> credentials) {
|
||||
this.credentials = credentials;
|
||||
return this;
|
||||
}
|
||||
|
||||
public User build() {
|
||||
User user = new User();
|
||||
user.id = this.id;
|
||||
user.username = this.username;
|
||||
user.email = this.email;
|
||||
user.credentials = this.credentials == null ? new ArrayList<>() : this.credentials;
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,4 +80,59 @@ public class UserCredential {
|
||||
public void setCredential(String credential) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private UserCredentialId id;
|
||||
private User user;
|
||||
private Long userId;
|
||||
private String provider;
|
||||
private String credential;
|
||||
|
||||
public Builder id(UserCredentialId id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder user(User user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder userId(Long userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder provider(String provider) {
|
||||
this.provider = provider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder credential(String credential) {
|
||||
this.credential = credential;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserCredential build() {
|
||||
UserCredential userCredential = new UserCredential();
|
||||
userCredential.id = this.id == null ? new UserCredentialId() : this.id;
|
||||
userCredential.user = this.user;
|
||||
if (this.user != null) {
|
||||
userCredential.id.setUserId(this.user.getId());
|
||||
}
|
||||
if (this.userId != null) {
|
||||
userCredential.id.setUserId(this.userId);
|
||||
}
|
||||
if (this.provider != null) {
|
||||
userCredential.id.setProvider(this.provider);
|
||||
}
|
||||
userCredential.credential = this.credential;
|
||||
return userCredential;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,33 @@ public class UserCredentialId implements Serializable {
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, provider);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Long userId;
|
||||
private String provider;
|
||||
|
||||
public Builder userId(Long userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder provider(String provider) {
|
||||
this.provider = provider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserCredentialId build() {
|
||||
UserCredentialId id = new UserCredentialId();
|
||||
id.userId = this.userId;
|
||||
id.provider = this.provider;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user