forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from jiahui0309/fix-find-command-bugs
Fix UI bugs for FindCommand
- Loading branch information
Showing
14 changed files
with
426 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/main/java/seedu/address/logic/commands/ShowCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.IdentityCardNumberMatchesPredicate; | ||
import seedu.address.model.person.Person; | ||
|
||
|
||
|
||
/** | ||
* Shows the user a note of a person in the address book. | ||
* If no IC is given, the displayed note panel will be cleared. | ||
*/ | ||
public class ShowCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "show"; | ||
public static final String MESSAGE_SHOW_NOTE_SUCCESS = "Displayed note of person: %1$s"; | ||
|
||
public static final String MESSAGE_CLEAR_NOTE_SUCCESS = "Note cleared."; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows the note of the person whose IC matches the " | ||
+ "specified valid IC (case-insensitive) and displays it.\n" | ||
+ "If no IC is given, the displayed note panel will be cleared.\n" | ||
+ "Parameters: IC (optional)\n" | ||
+ "Example (to display note): " + COMMAND_WORD + " t1234567A\n" | ||
+ "Example (to clear display): " + COMMAND_WORD; | ||
private final IdentityCardNumberMatchesPredicate icPredicate; | ||
|
||
private final boolean isClear; | ||
|
||
/** | ||
* Creates a ShowCommand to show the note of the person whose profile matches the specified {@code icPredicate}. | ||
* @param icPredicate of the person in the filtered person list to show the note | ||
*/ | ||
private ShowCommand(IdentityCardNumberMatchesPredicate icPredicate, boolean isClear) { | ||
this.icPredicate = icPredicate; | ||
this.isClear = isClear; | ||
} | ||
|
||
/** | ||
* Factory method to create a ShowCommand to show the note of the person whose profile matches | ||
* the specified {@code icPredicate}. | ||
* @param icPredicate of the person in the filtered person list to show the note | ||
*/ | ||
public static ShowCommand createShowCommand(IdentityCardNumberMatchesPredicate icPredicate) { | ||
return new ShowCommand(icPredicate, false); | ||
} | ||
|
||
/** | ||
* Factory method to create a ShowCommand to clear the displayed note panel. | ||
*/ | ||
public static ShowCommand createClearCommand() { | ||
return new ShowCommand(null, true); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
if (isClear) { | ||
model.clearDisplayNote(); | ||
return new CommandResult(MESSAGE_CLEAR_NOTE_SUCCESS); | ||
} | ||
|
||
List<Person> allPatients = model.getAddressBook().getPersonList(); | ||
|
||
Person person = allPatients.stream() | ||
.filter(icPredicate::test) | ||
.findFirst() | ||
.orElseThrow(() -> new CommandException(Messages.MESSAGE_NO_MATCHING_IC)); | ||
|
||
model.setDisplayNote(person); | ||
|
||
return new CommandResult( | ||
String.format(MESSAGE_SHOW_NOTE_SUCCESS, person.getIdentityCardNumber()) | ||
); | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof ShowCommand)) { | ||
return false; | ||
} | ||
|
||
ShowCommand e = (ShowCommand) other; | ||
// icPredicate is not important if isClear is true | ||
if (isClear && e.isClear) { | ||
return true; | ||
} | ||
if (isClear != e.isClear) { | ||
return false; | ||
} | ||
if (icPredicate == null || e.icPredicate == null) { | ||
return icPredicate == e.icPredicate; | ||
} | ||
return icPredicate.equals(e.icPredicate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("predicate", icPredicate) | ||
.add("isClear", isClear) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/seedu/address/logic/parser/ShowCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.logic.commands.ShowCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.IdentityCardNumber; | ||
import seedu.address.model.person.IdentityCardNumberMatchesPredicate; | ||
|
||
/** | ||
* Parses input arguments and creates a new ShowCommand object | ||
*/ | ||
public class ShowCommandParser implements Parser<ShowCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ShowCommand | ||
* and returns a ShowCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ShowCommand parse(String args) throws ParseException { | ||
String trimmedArgs = args.trim(); | ||
if (trimmedArgs.isEmpty()) { | ||
return ShowCommand.createClearCommand(); | ||
} | ||
|
||
try { | ||
IdentityCardNumber ic = ParserUtil.parseIC(trimmedArgs); | ||
return ShowCommand.createShowCommand(new IdentityCardNumberMatchesPredicate(ic)); | ||
} catch (IllegalArgumentException e) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ShowCommand.MESSAGE_USAGE), e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.