Skip to content

Commit

Permalink
fix: update BloodType.java
Browse files Browse the repository at this point in the history
Update BloodType.java to match JsonAdaptedPerson expected output
  • Loading branch information
jovantanyk committed Mar 20, 2024
1 parent fa47bdc commit de86e72
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/seedu/address/model/person/BloodType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
* Guarantees: immutable;
*/
public class BloodType {
public static final String MESSAGE_CONSTRAINTS =
"BloodType should be A, B, AB, O. Rh should be either + or -";
private enum Type { A, B, AB, O };
private enum Rh { POSITIVE, NEGATIVE };
public static final String MESSAGE_CONSTRAINTS = "BloodType should be A, B, AB, O. Rh should be either + or -";
private final Type type;

private final Rh rh;

/**
* Constructs a {@code BloodType}.
*
* @param type A valid blood type.
* @param rh A valid Rh factor.
* @param rh A valid Rh factor.
*/
public BloodType(String type, String rh) {
requireNonNull(type, rh);
Expand All @@ -33,32 +31,31 @@ public BloodType(String type, String rh) {

/**
* A method for testing if two strings form a valid BloodType
*
* @param testType String for storing testing type
* @param testRh String for storing testing rh
* @param testRh String for storing testing rh
* @return Boolean whether test passes or fails
*/
public static boolean isValidBloodType(String testType, String testRh) {
try {
Type type = Type.valueOf(testType);
if (testRh == "+" || testRh == "-") {
return true;
}
return false;
return testRh == "+" || testRh == "-";
} catch (IllegalArgumentException e) {
return false;
}
}

public String getType() {
return type.toString();
return this.type.toString();
}

public String getRh() {
return rh.toString();
return this.rh == Rh.POSITIVE ? "+" : "-";
}

@Override
public String toString() {
return this.type.toString() + this.rh.toString();
return this.type.toString() + this.getRh();
}

@Override
Expand All @@ -77,4 +74,8 @@ public boolean equals(Object other) {
BloodType otherBloodType = (BloodType) other;
return type.equals(otherBloodType.type) && rh.equals(otherBloodType.rh);
}

private enum Type { A, B, AB, O }

private enum Rh { POSITIVE, NEGATIVE }
}

0 comments on commit de86e72

Please sign in to comment.