-
-
Save Redrield/646704f520d8e238b077c8344125d91a to your computer and use it in GitHub Desktop.
User Classes
This file contains 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 java.util.Objects; | |
public final class JUser { | |
private static final int DEFAULT_AGE = 1; | |
private static final String DEFAULT_MIDDLE = ""; | |
// start fields | |
private int age; | |
@Nonnull | |
private String firstName, middleName, lastName; | |
// start constructors (many permutations more due to parameter labels) | |
public JUser(@Nonnull String firstName, @Nonnull String middleName, @Nonnull String lastName, int age) { | |
assert firstName != null; | |
assert middleName != null; | |
assert lastName != null; | |
this.age = age; | |
this.firstName = firstName; | |
this.middleName = middleName; | |
this.lastName = lastName; | |
} | |
public JUser(@Nonnull String firstName,@Nonnull String middleName, @Nonnull String lastName) { | |
this(firstName, middleName, lastName, DEFAULT_AGE); | |
} | |
public JUser(@Nonnull String firstName, @Nonnull String lastName, int age) { | |
this(firstName, DEFAULT_MIDDLE, lastName, age); | |
} | |
public JUser(@Nonnull String firstName, @Nonnull String lastName) { | |
this(firstName, lastName, DEFAULT_AGE); | |
} | |
// start getters/setters | |
@Nonnull | |
public String getFirstName() { | |
return firstName; | |
} | |
public void setFirstName(@Nonnull String firstName) { | |
assert firstName != null; | |
this.firstName = firstName; | |
} | |
@Nonnull | |
public String getMiddleName() { | |
return middleName; | |
} | |
public void setMiddleName(@Nonnull String middleName) { | |
assert middleName != null; | |
this.middleName = middleName; | |
} | |
@Nonnull | |
public String getLastName() { | |
return lastName; | |
} | |
public void setLastName(@Nonnull String lastName) { | |
assert lastName != null; | |
this.lastName = lastName; | |
} | |
public int getAge() { | |
return age; | |
} | |
public void setAge(int age) { | |
this.age = age; | |
} | |
// start components | |
@Nonnull | |
public String component1() { | |
return firstName; | |
} | |
@Nonnull | |
public String component2() { | |
return middleName; | |
} | |
@Nonnull | |
public String component3() { | |
return lastName; | |
} | |
public int component4() { | |
return age; | |
} | |
// start copy (many permutations more due to parameter labels) | |
@Nonnull | |
public JUser copy(@Nonnull String firstName, @Nonnull String middleName, @Nonnull String lastName, int age) { | |
assert firstName != null; | |
assert middleName != null; | |
assert lastName != null; | |
return new JUser(firstName, middleName, lastName, age); | |
} | |
@Nonnull | |
public JUser copy(@Nonnull String firstName, @Nonnull String middleName, @Nonnull String lastName) { | |
return copy(firstName, middleName, lastName, this.age); | |
} | |
@Nonnull | |
public JUser copy(@Nonnull String firstName, @Nonnull String middleName) { | |
return copy(firstName, middleName, this.lastName, this.age); | |
} | |
@Nonnull | |
public JUser copy(@Nonnull String firstName) { | |
return copy(firstName, this.middleName, this.lastName, this.age); | |
} | |
@Nonnull | |
public JUser copy() { | |
return copy(this.firstName, this.middleName, this.lastName, this.age); | |
} | |
// start object overrides | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (!(o instanceof JUser)) return false; | |
JUser jUser = (JUser) o; | |
return getAge() == jUser.getAge() && | |
Objects.equals(getFirstName(), jUser.getFirstName()) && | |
Objects.equals(getMiddleName(), jUser.getMiddleName()) && | |
Objects.equals(getLastName(), jUser.getLastName()); | |
} | |
@Override | |
public int hashCode() { | |
return Objects.hash(getAge(), getFirstName(), getMiddleName(), getLastName()); | |
} | |
@Override | |
public String toString() { | |
final StringBuilder sb = new StringBuilder("JUser{"); | |
sb.append("age=").append(age); | |
sb.append(", firstName='").append(firstName).append('\''); | |
sb.append(", middleName='").append(middleName).append('\''); | |
sb.append(", lastName='").append(lastName).append('\''); | |
sb.append('}'); | |
return sb.toString(); | |
} | |
} |
This file contains 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
data class KUser(var firstName : String, var middleName : String = "", var lastName : String, var age : Int = 1) |
This file contains 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
#[derive(Copy, Clone, Debug)] | |
struct RUser { | |
pub firstName: String, | |
pub middleName: String, | |
pub lastName: String, | |
pub age: u32 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment