diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index 72b9eddd3a7..db641b202d9 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -6,6 +6,8 @@ import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.Status; +import seedu.address.model.person.StatusContainsKeywordsPredicate; /** * Finds and lists all persons in address book whose name contains any of the argument keywords. @@ -13,23 +15,34 @@ */ public class FindCommand extends Command { - public static final String COMMAND_WORD = "find"; + public static final String COMMAND_WORD = "search"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of " - + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + + "the name keywords (case-insensitive) and (if specified) whose status contain any of the status" + + "keywords (case-insensitive) and displays them as a list with index numbers.\n" + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " alice bob charlie"; + + "Example: " + COMMAND_WORD + " n/alex bernice s/interviewed"; - private final NameContainsKeywordsPredicate predicate; + private final NameContainsKeywordsPredicate namePredicate; + private final StatusContainsKeywordsPredicate statusPredicate; - public FindCommand(NameContainsKeywordsPredicate predicate) { - this.predicate = predicate; + /** + * Creates an FindCommand to find the specified {@code Person} + */ + public FindCommand(NameContainsKeywordsPredicate namePredicate, StatusContainsKeywordsPredicate statusPredicate) { + this.namePredicate = namePredicate; + this.statusPredicate = statusPredicate; } + @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredPersonList(predicate); + if (!Status.isValidStatus(statusPredicate.toString())) { + model.updateFilteredPersonList(namePredicate); + } else { + model.updateFilteredPersonList(namePredicate, statusPredicate); + } return new CommandResult( String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); } @@ -46,13 +59,19 @@ public boolean equals(Object other) { } FindCommand otherFindCommand = (FindCommand) other; - return predicate.equals(otherFindCommand.predicate); + if (Status.isValidStatus(statusPredicate.toString())) { + return namePredicate.equals(otherFindCommand.namePredicate) + && statusPredicate.equals(otherFindCommand.statusPredicate); + } + return namePredicate.equals(otherFindCommand.namePredicate); + } @Override public String toString() { return new ToStringBuilder(this) - .add("predicate", predicate) + .add("name predicate", namePredicate) + .add("status predicate", statusPredicate) .toString(); } } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 389ea233c97..5ad7ce2d8b6 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -13,5 +13,7 @@ public class CliSyntax { public static final Prefix PREFIX_REMARK = new Prefix("r/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_STATUS = new Prefix("s/"); + } diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 2867bde857b..cb125ae4568 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -1,12 +1,20 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS; import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; import seedu.address.logic.commands.FindCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.StatusContainsKeywordsPredicate; + + + /** * Parses input arguments and creates a new FindCommand object @@ -19,15 +27,45 @@ public class FindCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public FindCommand parse(String args) throws ParseException { - String trimmedArgs = args.trim(); - if (trimmedArgs.isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STATUS); + + if (!arePrefixesPresent(argMultimap, PREFIX_NAME) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } - String[] nameKeywords = trimmedArgs.split("\\s+"); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_STATUS); + + String[] nameKeywords = parseKeywordsList(argMultimap.getAllValues(PREFIX_NAME)); + String[] statusKeywords = parseKeywordsList(argMultimap.getAllValues(PREFIX_STATUS)); - return new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + return new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords)), + new StatusContainsKeywordsPredicate(Arrays.asList(statusKeywords))); } + /** + * Parses a list of keywords into an array of strings. + * + * @param keywordsList A list of keywords, where each element may contain multiple words. + * @return An array of strings where each element represents an individual keyword. + * + * The method first converts the list of keywords into a string representation, + * e.g., [Alex, Yeoh] (including square brackets). It then removes the square brackets + * from the string representation, resulting in a cleaned string, e.g., Alex, Yeoh (no square brackets). + * Finally, the cleaned string is split into an array of strings, where each word separated + * by a whitespace or comma is considered a single element. + * + * Example: + * If keywordsList is ["John Doe"], the returned array will be ["John", "Doe"]. + */ + private String[] parseKeywordsList(List keywordsList) { + String list = keywordsList.toString(); + String cleanedList = list.replaceAll("[\\[\\]]", ""); + return cleanedList.split("\\s+"); + } + + 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 b117acb9c55..ae1d6733476 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -13,6 +13,7 @@ import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; +import seedu.address.model.person.Status; import seedu.address.model.tag.Tag; /** @@ -121,4 +122,21 @@ public static Set parseTags(Collection tags) throws ParseException } return tagSet; } + + /** + * Parses {@code Collection status} into a {@code Set of status}. + */ + public static Set parseStatus(Collection statusList) throws ParseException { + requireNonNull(statusList); + final Set statusSet = new HashSet<>(); + for (String status : statusList) { + status = status.trim(); + if (!Status.isValidStatus(status)) { + throw new ParseException(Status.MESSAGE_CONSTRAINTS); + } + statusSet.add(status); + } + return statusSet; + } + } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index d54df471c1f..d21ff794e11 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -84,4 +84,10 @@ public interface Model { * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredPersonList(Predicate predicate); + + /** + * Updates the filter of the filtered person list to filter by the given {@code predicates}. + * @throws NullPointerException if any of the {@code predicates} is null. + */ + void updateFilteredPersonList(Predicate predicate1, Predicate predicate2); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 57bc563fde6..6d67167c159 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -128,6 +128,13 @@ public void updateFilteredPersonList(Predicate predicate) { filteredPersons.setPredicate(predicate); } + @Override + public void updateFilteredPersonList(Predicate predicate1, Predicate predicate2) { + requireNonNull(predicate1); + requireNonNull(predicate2);; + filteredPersons.setPredicate(person -> predicate1.test(person) && predicate2.test(person)); + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/model/person/Status.java b/src/main/java/seedu/address/model/person/Status.java index 6fa9e1e74ad..ae9b62b1bca 100644 --- a/src/main/java/seedu/address/model/person/Status.java +++ b/src/main/java/seedu/address/model/person/Status.java @@ -1,9 +1,16 @@ package seedu.address.model.person; +import java.util.Arrays; +import java.util.List; + +import seedu.address.commons.util.StringUtil; + /** * Represents a Status in the Person class */ public class Status { + public static final String MESSAGE_CONSTRAINTS = "Status should be either one of the following: 'Preliminary'," + + "'Interviewed', 'Offered', 'Rejected'"; private StatusTypes statusType; @@ -19,6 +26,18 @@ public void setStatusType(StatusTypes newStatus) { this.statusType = newStatus; } + /** + * Checks if the provided status is a valid status. + * + * @param status The status to be checked for validity. + * @return {@code true} if the status is valid, {@code false} otherwise. + */ + public static boolean isValidStatus(String status) { + List validStatus = Arrays.asList("Preliminary", "Interviewed", "Rejected", "Offered"); + return validStatus.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(status, keyword)); + } + @Override public String toString() { return statusType.toString(); diff --git a/src/main/java/seedu/address/model/person/StatusContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/StatusContainsKeywordsPredicate.java new file mode 100644 index 00000000000..ad6eb8a26be --- /dev/null +++ b/src/main/java/seedu/address/model/person/StatusContainsKeywordsPredicate.java @@ -0,0 +1,43 @@ +package seedu.address.model.person; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.address.commons.util.StringUtil; + +/** + * Tests that a {@code Person}'s {@code Name} matches any of the keywords given. + */ +public class StatusContainsKeywordsPredicate implements Predicate { + private final List keywords; + + public StatusContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Person person) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getStatus().toString(), keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof StatusContainsKeywordsPredicate)) { + return false; + } + + StatusContainsKeywordsPredicate otherStatusContainsKeywordsPredicate = (StatusContainsKeywordsPredicate) other; + return keywords.equals(otherStatusContainsKeywordsPredicate.keywords); + } + + @Override + public String toString() { + return keywords.toString().replaceAll("[\\[\\]]", ""); + } +} diff --git a/src/main/java/seedu/address/model/person/StatusTypes.java b/src/main/java/seedu/address/model/person/StatusTypes.java index 772e30cef32..955a6fac1e7 100644 --- a/src/main/java/seedu/address/model/person/StatusTypes.java +++ b/src/main/java/seedu/address/model/person/StatusTypes.java @@ -14,6 +14,7 @@ public enum StatusTypes { this.statusName = statusName; } + @Override public String toString() { return this.statusName; diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 90e8253f48e..39d18e31fef 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -157,6 +157,11 @@ public ObservableList getFilteredPersonList() { public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + + @Override + public void updateFilteredPersonList(Predicate predicate1, Predicate predicate2) { + throw new AssertionError("This method should not be called."); + } } /** diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index b8b7dbba91a..89b76d87c33 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -19,6 +19,7 @@ import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.StatusContainsKeywordsPredicate; /** * Contains integration tests (interaction with the Model) for {@code FindCommand}. @@ -29,19 +30,23 @@ public class FindCommandTest { @Test public void equals() { - NameContainsKeywordsPredicate firstPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("first")); - NameContainsKeywordsPredicate secondPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("second")); - - FindCommand findFirstCommand = new FindCommand(firstPredicate); - FindCommand findSecondCommand = new FindCommand(secondPredicate); + NameContainsKeywordsPredicate firstNamePredicate = + new NameContainsKeywordsPredicate(Collections.singletonList("firstName")); + StatusContainsKeywordsPredicate firstStatusPredicate = + new StatusContainsKeywordsPredicate(Collections.singletonList("firstStatus")); + NameContainsKeywordsPredicate secondNamePredicate = + new NameContainsKeywordsPredicate(Collections.singletonList("secondName")); + StatusContainsKeywordsPredicate secondStatusPredicate = + new StatusContainsKeywordsPredicate(Collections.singletonList("secondStatus")); + + FindCommand findFirstCommand = new FindCommand(firstNamePredicate, firstStatusPredicate); + FindCommand findSecondCommand = new FindCommand(secondNamePredicate, secondStatusPredicate); // same object -> returns true assertTrue(findFirstCommand.equals(findFirstCommand)); // same values -> returns true - FindCommand findFirstCommandCopy = new FindCommand(firstPredicate); + FindCommand findFirstCommandCopy = new FindCommand(firstNamePredicate, firstStatusPredicate); assertTrue(findFirstCommand.equals(findFirstCommandCopy)); // different types -> returns false @@ -57,9 +62,10 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); - NameContainsKeywordsPredicate predicate = preparePredicate(" "); - FindCommand command = new FindCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); + NameContainsKeywordsPredicate namePredicate = prepareNamePredicate(" "); + StatusContainsKeywordsPredicate statusPredicate = prepareStatusPredicate(""); + FindCommand command = new FindCommand(namePredicate, statusPredicate); + expectedModel.updateFilteredPersonList(namePredicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Collections.emptyList(), model.getFilteredPersonList()); } @@ -67,25 +73,37 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_multipleKeywords_multiplePersonsFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); - FindCommand command = new FindCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); + NameContainsKeywordsPredicate namePredicate = prepareNamePredicate("Kurz Elle Kunz"); + StatusContainsKeywordsPredicate statusPredicate = prepareStatusPredicate("Preliminary"); + FindCommand command = new FindCommand(namePredicate, statusPredicate); + expectedModel.updateFilteredPersonList(namePredicate, statusPredicate); + System.out.println(expectedModel.getAddressBook()); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList()); } + @Test public void toStringMethod() { - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); - FindCommand findCommand = new FindCommand(predicate); - String expected = FindCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; + NameContainsKeywordsPredicate namePredicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); + StatusContainsKeywordsPredicate statusPredicate = new StatusContainsKeywordsPredicate(Arrays.asList("keyword")); + FindCommand findCommand = new FindCommand(namePredicate, statusPredicate); + String expected = FindCommand.class.getCanonicalName() + "{name predicate=" + namePredicate + + ", status predicate=" + statusPredicate + "}"; assertEquals(expected, findCommand.toString()); } /** * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. */ - private NameContainsKeywordsPredicate preparePredicate(String userInput) { + private NameContainsKeywordsPredicate prepareNamePredicate(String userInput) { return new NameContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); } + + /** + * Parses {@code userInput} into a {@code StatusContainsKeywordsPredicate}. + */ + private StatusContainsKeywordsPredicate prepareStatusPredicate(String userInput) { + return new StatusContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); + } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 8f90c8d8218..4a7d55e6039 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -28,6 +28,7 @@ import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; import seedu.address.model.person.Remark; +import seedu.address.model.person.StatusContainsKeywordsPredicate; import seedu.address.testutil.EditPersonDescriptorBuilder; import seedu.address.testutil.PersonBuilder; import seedu.address.testutil.PersonUtil; @@ -75,8 +76,9 @@ public void parseCommand_exit() throws Exception { public void parseCommand_find() throws Exception { List keywords = Arrays.asList("foo", "bar", "baz"); FindCommand command = (FindCommand) parser.parseCommand( - FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindCommand(new NameContainsKeywordsPredicate(keywords)), command); + FindCommand.COMMAND_WORD + " " + "n/" + keywords.stream().collect(Collectors.joining(" "))); + assertEquals(new FindCommand(new NameContainsKeywordsPredicate(keywords), + new StatusContainsKeywordsPredicate(Arrays.asList(""))), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index d92e64d12f9..34605f205ab 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -10,6 +10,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.StatusContainsKeywordsPredicate; public class FindCommandParserTest { @@ -24,11 +25,24 @@ public void parse_emptyArg_throwsParseException() { public void parse_validArgs_returnsFindCommand() { // no leading and trailing whitespaces FindCommand expectedFindCommand = - new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); - assertParseSuccess(parser, "Alice Bob", expectedFindCommand); + new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")), + new StatusContainsKeywordsPredicate(Arrays.asList("Interviewed"))); + assertParseSuccess(parser, " n/Alice Bob s/Interviewed", expectedFindCommand); // multiple whitespaces between keywords - assertParseSuccess(parser, " \n Alice \n \t Bob \t", expectedFindCommand); + assertParseSuccess(parser, " n/ \n Alice \n \t Bob \t s/Interviewed", expectedFindCommand); + } + + @Test + public void parse_validArgsWithNoStatus_returnsFindCommand() { + // no leading and trailing whitespaces + FindCommand expectedFindCommand = + new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")), + new StatusContainsKeywordsPredicate(Arrays.asList(""))); + assertParseSuccess(parser, " n/Alice Bob", expectedFindCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " n/ \n Alice \n \t Bob \t ", expectedFindCommand); } } diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 4256788b1a7..dff9bfd626d 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -26,6 +26,8 @@ public class ParserUtilTest { private static final String INVALID_ADDRESS = " "; private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_TAG = "#friend"; + private static final String INVALID_STATUS = "Accepted"; + private static final String VALID_NAME = "Rachel Walker"; private static final String VALID_PHONE = "123456"; @@ -33,7 +35,7 @@ public class ParserUtilTest { private static final String VALID_EMAIL = "rachel@example.com"; private static final String VALID_TAG_1 = "friend"; private static final String VALID_TAG_2 = "neighbour"; - + private static final String VALID_STATUS = "Interviewed"; private static final String WHITESPACE = " \t\r\n"; @Test @@ -193,4 +195,9 @@ public void parseTags_collectionWithValidTags_returnsTagSet() throws Exception { assertEquals(expectedTagSet, actualTagSet); } + + @Test + public void parseStatus_collectionWithInvalidStatus_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseStatus(Arrays.asList(VALID_STATUS, INVALID_STATUS))); + } } diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index ec73df0576e..f65abd1a6f4 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -9,6 +9,8 @@ import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.person.Remark; +import seedu.address.model.person.Status; +import seedu.address.model.person.StatusTypes; import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; @@ -31,6 +33,7 @@ public class PersonBuilder { private Remark remark; private Set tags; + private Status status; /** * Creates a {@code PersonBuilder} with the default details. @@ -42,6 +45,7 @@ public PersonBuilder() { address = new Address(DEFAULT_ADDRESS); remark = new Remark(DEFAULT_REMARK); tags = new HashSet<>(); + status = new Status(); // default status is preliminary } /** @@ -104,6 +108,30 @@ public PersonBuilder withRemark(String remark) { } + /** + * Sets the {@code Status} of the {@code Person} that we are building. + */ + public PersonBuilder withStatus(String status) { + switch (status) { + case "Preliminary": + this.status.setStatusType(StatusTypes.PRELIMINARY); + break; + case "Interviewed": + this.status.setStatusType(StatusTypes.INTERVIEWED); + break; + case "Rejected": + this.status.setStatusType(StatusTypes.REJECTED); + break; + case "Offered": + this.status.setStatusType(StatusTypes.OFFERED); + break; + default: + this.status.setStatusType(StatusTypes.PRELIMINARY); + } + System.out.println(this.status); + return this; + } + public Person build() { return new Person(name, phone, email, address, remark, tags); }