From d44d5667741aec4c1b8e5ab04e2a45fae0ef3df3 Mon Sep 17 00:00:00 2001 From: nixonwidjaja Date: Tue, 3 Oct 2023 23:42:48 +0800 Subject: [PATCH] Create leave entity --- .../seedu/address/model/person/Leave.java | 75 +++++++++++++++++++ .../seedu/address/model/person/Person.java | 23 +++++- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/java/seedu/address/model/person/Leave.java diff --git a/src/main/java/seedu/address/model/person/Leave.java b/src/main/java/seedu/address/model/person/Leave.java new file mode 100644 index 00000000000..6e4b5291087 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Leave.java @@ -0,0 +1,75 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Person's leave. + */ +public class Leave { + public static final int LEAVE_LENGTH = 12; + public static final String MESSAGE_CONSTRAINTS = "Invalid leave format"; + + public final String leave; + + /** + * Constructs an empty {@code Leave}. + */ + public Leave() { + this.leave = "000000000000"; + } + + /** + * Constructs a {@code Leave}. + * + * @param leave A valid leave. + */ + public Leave(String leave) { + requireNonNull(leave); + leave = leave.trim(); + checkArgument(isValidLeave(leave), MESSAGE_CONSTRAINTS); + this.leave = leave; + } + + /** + * Returns true if a given string is a valid leave. + */ + public static boolean isValidLeave(String test) { + test = test.trim(); + if (test.length() != LEAVE_LENGTH) { + return false; + } + for (int i = 0; i < LEAVE_LENGTH; i++) { + if (test.charAt(i) != '0' || test.charAt(i) != '1') { + return false; + } + } + return true; + } + + @Override + public String toString() { + return leave; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Leave)) { + return false; + } + + Leave otherLeave = (Leave) other; + return leave.equals(otherLeave.leave); + } + + @Override + public int hashCode() { + return leave.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 790dd97b657..70a3f368444 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -27,6 +27,7 @@ public class Person { private final Money claimBudget; private final Department department; private final Birthday dob; + private final Leave leave; private final Set tags = new HashSet<>(); /** @@ -43,6 +44,21 @@ public Person(Name name, Phone phone, Email email, Address address, this.claimBudget = claimBudget; this.department = dep; this.dob = dob; + this.leave = new Leave(); + } + + public Person(Name name, Phone phone, Email email, Address address, + Money salary, Money claimBudget, Department dep, Birthday dob, Leave leave) { + requireAllNonNull(name, phone, email, address, salary, claimBudget, dep, dob); + this.name = name; + this.phone = phone; + this.email = email; + this.address = address; + this.salary = salary; + this.claimBudget = claimBudget; + this.department = dep; + this.dob = dob; + this.leave = leave; } public Name getName() { @@ -77,6 +93,10 @@ public Birthday getDob() { return dob; } + public Leave getLeave() { + return leave; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -123,7 +143,7 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, salary, claimBudget, department, dob); + return Objects.hash(name, phone, email, address, salary, claimBudget, department, dob, leave); } @Override @@ -137,6 +157,7 @@ public String toString() { .add("claimBudget", claimBudget) .add("department", department) .add("dob", dob) + .add("leave", leave) .toString(); }