diff --git a/src/main/java/seedu/address/commons/util/DateUtil.java b/src/main/java/seedu/address/commons/util/DateUtil.java index 686ba223806..3de2e28110f 100644 --- a/src/main/java/seedu/address/commons/util/DateUtil.java +++ b/src/main/java/seedu/address/commons/util/DateUtil.java @@ -11,7 +11,8 @@ public class DateUtil { public static final String MESSAGE_CONSTRAINTS_FORMAT = "%1$s takes in a date of format dd/MM/yyyy"; public static final String MESSAGE_CONSTRAINTS_FUTURE_OCCURRENCE = "%1$s should not be later than current date"; - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy"); /** * Returns true if a given string is a valid date. @@ -20,7 +21,7 @@ public class DateUtil { */ public static boolean isValidDate(String value) { try { - LocalDate date = LocalDate.parse(value, formatter); + LocalDate date = LocalDate.parse(value, FORMATTER); return true; } catch (DateTimeParseException e) { return false; @@ -33,7 +34,7 @@ public static boolean isValidDate(String value) { */ public static boolean isFutureDate(String value) { if (isValidDate(value)) { - LocalDate date = LocalDate.parse(value, formatter); + LocalDate date = LocalDate.parse(value, FORMATTER); return date.isAfter(LocalDate.now()); } return false; @@ -43,6 +44,6 @@ public static boolean isFutureDate(String value) { * Returns the formatter for the date. */ public static DateTimeFormatter getFormatter() { - return formatter; + return FORMATTER; } } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 15ea1cd2713..cfb1d939bea 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -20,6 +20,7 @@ * Adds a person to the address book. */ public class AddCommand extends Command { + public static final String COMMAND_WORD = "add"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. \n" + "Parameters: " @@ -39,7 +40,6 @@ public class AddCommand extends Command { + PREFIX_REMARK + "Prevent bed sores. " + PREFIX_TAG + "FallRisk"; public static final String MESSAGE_SUCCESS = "New patient added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "A patient with this IC already exists in the address book"; private final Person toAdd; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 50e8efce215..d35b1922a91 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -207,36 +207,47 @@ public void setTags(Set tags) { public Optional> getTags() { return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); } + public void setIc(Ic ic) { this.ic = ic; } + public Optional getIc() { return Optional.ofNullable(ic); } + public void setDob(Dob dob) { this.dob = dob; } + public Optional getDob() { return Optional.ofNullable(dob); } + public void setAdmissionDate(AdmissionDate admissionDate) { this.admissionDate = admissionDate; } + public Optional getAdmissionDate() { return Optional.ofNullable(admissionDate); } + public void setWard(Ward ward) { this.ward = ward; } + public Optional getWard() { return Optional.ofNullable(ward); } + public void setRemark(Remark remark) { this.remark = remark; } + public Optional getRemark() { return Optional.ofNullable(remark); } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/ExitCommand.java b/src/main/java/seedu/address/logic/commands/ExitCommand.java index 3dd85a8ba90..4f52a0c5f8a 100644 --- a/src/main/java/seedu/address/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/address/logic/commands/ExitCommand.java @@ -13,6 +13,7 @@ public class ExitCommand extends Command { @Override public CommandResult execute(Model model) { + return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true); } diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index b0cf87265e7..d485a5f3f11 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -26,6 +26,7 @@ public class ListCommand extends Command { public static final String MESSAGE_SUCCESS = "Listed all persons"; public static final String MESSAGE_SUCCESS_LIST = "Listed all persons with: %1$s"; + private final ListKeywordsPredicate predicate; /** @@ -74,7 +75,7 @@ public boolean equals(Object other) { @Override public String toString() { return new ToStringBuilder(this) - .add("predicate", predicate == null ? "null" : predicate) + .add("predicate", (predicate == null) ? "null" : predicate) .toString(); } } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index db08ec6a57c..5c2eecf620b 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -31,6 +31,7 @@ public class AddCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the AddCommand * and returns an AddCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public AddCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 3527fe76a3e..4e29d82d253 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -14,6 +14,7 @@ public class DeleteCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the DeleteCommand * and returns a DeleteCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public DeleteCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 1e6c727f895..a50cc27fa3e 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -29,6 +29,7 @@ public class EditCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the EditCommand * and returns an EditCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public EditCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 8bb6a82ca12..b46ea16c092 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -20,6 +20,7 @@ public class FindCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the FindCommand * and returns a FindCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public FindCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/ListCommandParser.java b/src/main/java/seedu/address/logic/parser/ListCommandParser.java index 96464fe5320..daba20edaee 100644 --- a/src/main/java/seedu/address/logic/parser/ListCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ListCommandParser.java @@ -19,18 +19,21 @@ public class ListCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the ListCommand * and returns a ListCommand object for execution. + * + * @param args the arguments to parse. + * @return a ListCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ public ListCommand parse(String args) throws ParseException { String trimmedArgs = args.trim(); - // If there are no arguments, return a ListCommand object with no predicate + + // If there are no arguments, list all patients if (trimmedArgs.isEmpty()) { - return new ListCommand(); // return a ListCommand object with no predicate + return new ListCommand(); } - // If there are arguments, parse the arguments and return a ListCommand object with the parsed predicate - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_TAG, PREFIX_WARD); + // If there are arguments, filter patients based on the arguments + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_TAG, PREFIX_WARD); if (!argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE)); } @@ -39,20 +42,20 @@ public ListCommand parse(String args) throws ParseException { List tagList = List.of(); if (arePrefixesPresent(argMultimap, PREFIX_TAG)) { tagList = ParserUtil.parseTagsKeywords(argMultimap.getAllValues(PREFIX_TAG)); - assert !tagList.isEmpty(); + assert !tagList.isEmpty() : "tagList should not be empty"; } String ward = ""; if (arePrefixesPresent(argMultimap, PREFIX_WARD)) { ward = ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).orElse(null)).toString(); - assert !ward.isEmpty(); + assert !ward.isEmpty() : "ward should not be empty"; } - if (ward.isEmpty() && tagList.isEmpty()) { // If there are no valid arguments, throw an exception + if (ward.isEmpty() && tagList.isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE)); } - assert !tagList.isEmpty() || !ward.isEmpty(); + assert !tagList.isEmpty() || !ward.isEmpty() : "at least either tagList or ward must be supplied"; return new ListCommand(new ListKeywordsPredicate(tagList, ward)); } @@ -60,6 +63,9 @@ public ListCommand parse(String args) throws ParseException { /** * Returns true if none of the prefixes contains empty {@code Optional} values in the given * {@code ArgumentMultimap}. + * + * @param argumentMultimap the {@code ArgumentMultimap} to check for the presence of prefixes. + * @param prefixes the prefixes to check for. */ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 11f15588683..7e1d702191a 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -128,7 +128,7 @@ public static Ic parseIc(String ic) throws ParseException { } /** - * Parses a {@code String admissionDate, Dob dob} into a {@code AdmissionDate}. + * Parses a {@code String admissionDate} into a {@code AdmissionDate}. * Leading and trailing whitespaces will be trimmed. * * @throws ParseException if the given {@code admissionDate} is invalid. @@ -163,7 +163,7 @@ public static Ward parseWard(String ward) throws ParseException { * Parses a {@code String remark} into a {@code Remark}. * Leading and trailing whitespaces will be trimmed. */ - public static Remark parseRemark(String remark) throws ParseException { + public static Remark parseRemark(String remark) { if (remark == null) { return new Remark(""); } else { diff --git a/src/main/java/seedu/address/logic/parser/Prefix.java b/src/main/java/seedu/address/logic/parser/Prefix.java index 348b7686c8a..8c0a829988f 100644 --- a/src/main/java/seedu/address/logic/parser/Prefix.java +++ b/src/main/java/seedu/address/logic/parser/Prefix.java @@ -7,10 +7,20 @@ public class Prefix { private final String prefix; + /** + * Constructs a Prefix object. + * + * @param prefix A valid prefix. + */ public Prefix(String prefix) { this.prefix = prefix; } + /** + * Returns the prefix string. + * + * @return Prefix string. + */ public String getPrefix() { return prefix; } diff --git a/src/main/java/seedu/address/model/person/AdmissionDate.java b/src/main/java/seedu/address/model/person/AdmissionDate.java index b3f112accec..fcc18a1ae5f 100644 --- a/src/main/java/seedu/address/model/person/AdmissionDate.java +++ b/src/main/java/seedu/address/model/person/AdmissionDate.java @@ -12,10 +12,10 @@ */ public class AdmissionDate extends DateUtil { public static final String DATE_TYPE = "Admission date"; - public static final String MESSAGE_CONSTRAINTS_FORMAT = - String.format(DateUtil.MESSAGE_CONSTRAINTS_FORMAT, DATE_TYPE); - public static final String MESSAGE_CONSTRAINTS_OCCURRENCE = - "Admission date should not be earlier than date of birth or later than current date"; + public static final String MESSAGE_CONSTRAINTS_FORMAT = String + .format(DateUtil.MESSAGE_CONSTRAINTS_FORMAT, DATE_TYPE); + public static final String MESSAGE_CONSTRAINTS_OCCURRENCE = String + .format("%1$s should not be earlier than date of birth or later than current date", DATE_TYPE); private final LocalDate admissionDate; private final String value; @@ -51,6 +51,7 @@ public boolean equals(Object other) { return true; } + // instanceof handles nulls if (!(other instanceof AdmissionDate)) { return false; } diff --git a/src/main/java/seedu/address/model/person/Dob.java b/src/main/java/seedu/address/model/person/Dob.java index 00ef26e98ad..08837710c1a 100644 --- a/src/main/java/seedu/address/model/person/Dob.java +++ b/src/main/java/seedu/address/model/person/Dob.java @@ -17,11 +17,11 @@ public class Dob extends DateUtil { String.format(DateUtil.MESSAGE_CONSTRAINTS_FORMAT, DATE_TYPE); public static final String MESSAGE_CONSTRAINTS_FUTURE_OCCURRENCE = String.format(DateUtil.MESSAGE_CONSTRAINTS_FUTURE_OCCURRENCE, DATE_TYPE); - public static final String MESSAGE_DOB_AFTER_ADMISSION = "Date of birth should not be later than date of admission."; - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + private final LocalDate dob; private final String value; @@ -34,7 +34,7 @@ public Dob(String value) { requireNonNull(value); checkArgument(isValidDate(value), MESSAGE_CONSTRAINTS_FORMAT); checkArgument(!isFutureDate(value), MESSAGE_CONSTRAINTS_FUTURE_OCCURRENCE); - this.dob = LocalDate.parse(value, formatter); + this.dob = LocalDate.parse(value, FORMATTER); this.value = value; } @@ -63,6 +63,7 @@ public boolean equals(Object other) { return true; } + // instanceof handles nulls if (!(other instanceof Dob)) { return false; } diff --git a/src/main/java/seedu/address/model/person/Ic.java b/src/main/java/seedu/address/model/person/Ic.java index e91b2ce790b..7150981e627 100644 --- a/src/main/java/seedu/address/model/person/Ic.java +++ b/src/main/java/seedu/address/model/person/Ic.java @@ -45,6 +45,7 @@ public boolean equals(Object other) { return true; } + // instanceof handles nulls if (!(other instanceof Ic)) { return false; } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 99db8560eec..16ef97974ac 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -20,6 +20,10 @@ * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { + + /** + * Returns an array of sample persons. + */ public static Person[] getSamplePersons() { return new Person[]{ @@ -40,6 +44,9 @@ public static Person[] getSamplePersons() { }; } + /** + * Returns an address book containing sample persons. + */ public static ReadOnlyAddressBook getSampleAddressBook() { AddressBook sampleAb = new AddressBook(); for (Person samplePerson : getSamplePersons()) {