Skip to content

Commit

Permalink
Create leave entity
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Oct 3, 2023
1 parent c6fd530 commit d44d566
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
75 changes: 75 additions & 0 deletions src/main/java/seedu/address/model/person/Leave.java
Original file line number Diff line number Diff line change
@@ -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();
}

}
23 changes: 22 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tag> tags = new HashSet<>();

/**
Expand All @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -137,6 +157,7 @@ public String toString() {
.add("claimBudget", claimBudget)
.add("department", department)
.add("dob", dob)
.add("leave", leave)
.toString();
}

Expand Down

0 comments on commit d44d566

Please sign in to comment.