From 2465aa19abed70983999625fc2c747a602d3cc43 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:32:30 +0800 Subject: [PATCH 01/10] Create Blank class --- .../logic/parser/AddCommandParser.java | 25 ++++++++++++++++--- .../address/logic/parser/ParserUtil.java | 10 ++++++++ .../seedu/address/model/person/Address.java | 9 +++++++ .../seedu/address/model/person/Blank.java | 8 ++++++ .../seedu/address/model/person/Email.java | 9 +++++++ .../seedu/address/model/person/Phone.java | 9 +++++++ .../java/seedu/address/ui/PersonCard.java | 11 ++++++++ 7 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/main/java/seedu/address/model/person/Blank.java diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 00b78379874..184237f7088 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -17,6 +17,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.game.Game; import seedu.address.model.person.Address; +import seedu.address.model.person.Blank; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -39,16 +40,32 @@ public AddCommand parse(String args) throws ParseException { ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, PREFIX_GAME, PREFIX_PREFERREDTIME); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); - Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); - Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); - Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); + Phone phone; + if (arePrefixesPresent(argMultimap, PREFIX_PHONE)) { + phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); + } else { + phone = new Phone(new Blank()); + } + Email email; + if (arePrefixesPresent(argMultimap, PREFIX_EMAIL)) { + email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); + } else { + email = new Email(new Blank()); + } + Address address; + if (arePrefixesPresent(argMultimap, PREFIX_ADDRESS)) { + address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); + } else { + address = new Address(new Blank()); + } + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); Map gameList = ParserUtil.parseGames(argMultimap.getAllValues(PREFIX_GAME)); Set preferredTimeList = diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 89674b1502d..aabb861b953 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -16,6 +16,7 @@ import seedu.address.model.game.SkillLevel; import seedu.address.model.game.Username; import seedu.address.model.person.Address; +import seedu.address.model.person.Blank; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; @@ -64,6 +65,9 @@ public static Name parseName(String name) throws ParseException { * @throws ParseException if the given {@code phone} is invalid. */ public static Phone parsePhone(String phone) throws ParseException { + if (phone.equals("")) { + return new Phone(new Blank()); + } requireNonNull(phone); String trimmedPhone = phone.trim(); if (!Phone.isValidPhone(trimmedPhone)) { @@ -79,6 +83,9 @@ public static Phone parsePhone(String phone) throws ParseException { * @throws ParseException if the given {@code address} is invalid. */ public static Address parseAddress(String address) throws ParseException { + if (address.equals("")) { + return new Address(new Blank()); + } requireNonNull(address); String trimmedAddress = address.trim(); if (!Address.isValidAddress(trimmedAddress)) { @@ -94,6 +101,9 @@ public static Address parseAddress(String address) throws ParseException { * @throws ParseException if the given {@code email} is invalid. */ public static Email parseEmail(String email) throws ParseException { + if (email.equals("")) { + return new Email(new Blank()); + } requireNonNull(email); String trimmedEmail = email.trim(); if (!Email.isValidEmail(trimmedEmail)) { diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/person/Address.java index 469a2cc9a1e..299dd7d659b 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/person/Address.java @@ -30,6 +30,15 @@ public Address(String address) { value = address; } + /** + * Constructs an {@code Address}. + * + * @param blank A blank address. + */ + public Address(Blank blank) { + value = ""; + } + /** * Returns true if a given string is a valid email. */ diff --git a/src/main/java/seedu/address/model/person/Blank.java b/src/main/java/seedu/address/model/person/Blank.java new file mode 100644 index 00000000000..00a60f9db03 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Blank.java @@ -0,0 +1,8 @@ +package seedu.address.model.person; + + +/** + * Used to create blank version of {@code Person} fields + */ +public class Blank { +} diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java index c62e512bc29..795a38bb68d 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/person/Email.java @@ -44,6 +44,15 @@ public Email(String email) { value = email; } + /** + * Constructs an {@code Email}. + * + * @param blank A blank email. + */ + public Email(Blank blank) { + value = ""; + } + /** * Returns if a given string is a valid email. */ diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index d733f63d739..1b573c10034 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -26,6 +26,15 @@ public Phone(String phone) { value = phone; } + /** + * Constructs an {@code Phone}. + * + * @param blank A blank phone. + */ + public Phone(Blank blank) { + value = ""; + } + /** * Returns true if a given string is a valid phone number. */ diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 941d85c3332..d4a44b46c86 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -67,8 +67,19 @@ public PersonCard(Person person, int displayedIndex) { id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); phone.setText(person.getPhone().value); + if (phone.getText().isEmpty()) { + phone.setMaxHeight(0); + } address.setText(person.getAddress().value); + if (address.getText().isEmpty()) { + System.out.println("this is working"); + address.setMaxHeight(0); + address.setVisible(false); + } email.setText(person.getEmail().value); + if (email.getText().isEmpty()) { + email.setMaxHeight(0); + } person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); From 63d59dc2a62a7ca164487f599059e99a607f9b65 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 02:55:17 +0800 Subject: [PATCH 02/10] Fix personCard --- src/main/java/seedu/address/ui/PersonCard.java | 8 ++++++-- src/main/resources/view/PersonListCard.fxml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index d4a44b46c86..f8b4f7f2c55 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -69,16 +69,20 @@ public PersonCard(Person person, int displayedIndex) { phone.setText(person.getPhone().value); if (phone.getText().isEmpty()) { phone.setMaxHeight(0); + phone.setMinHeight(0); + phone.setPrefHeight(0); } address.setText(person.getAddress().value); if (address.getText().isEmpty()) { - System.out.println("this is working"); address.setMaxHeight(0); - address.setVisible(false); + address.setMinHeight(0); + address.setPrefHeight(0); } email.setText(person.getEmail().value); if (email.getText().isEmpty()) { email.setMaxHeight(0); + email.setMinHeight(0); + email.setPrefHeight(0); } person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index e1344d57411..99ae2ef9972 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -9,7 +9,7 @@ - + From 6da9eb2b0de1cfc95eb487704f74de37dc8fb49b Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:27:11 +0800 Subject: [PATCH 03/10] Fix CommandHistory bugs --- src/main/java/seedu/address/ui/CommandHistory.java | 3 +++ .../ui/commandpopup/AutoSuggestionTextField.java | 3 +-- .../java/seedu/address/model/person/AddressTest.java | 2 +- .../java/seedu/address/model/person/EmailTest.java | 2 +- .../java/seedu/address/model/person/PhoneTest.java | 2 +- .../java/seedu/address/ui/CommandHistoryTest.java | 11 +++++++++++ 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/ui/CommandHistory.java b/src/main/java/seedu/address/ui/CommandHistory.java index 16df4c710c3..211f0c02c57 100644 --- a/src/main/java/seedu/address/ui/CommandHistory.java +++ b/src/main/java/seedu/address/ui/CommandHistory.java @@ -35,6 +35,9 @@ public String getNextCommand() { currentHistoryIndex++; return commandHistory.get(currentHistoryIndex); } + if (currentHistoryIndex == commandHistory.size() - 1) { + currentHistoryIndex++; + } return ""; // No next command } } diff --git a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java index 6d31f745a87..ab6287f5746 100644 --- a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java +++ b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java @@ -66,7 +66,7 @@ public AutoSuggestionTextField() { // Listen for text changes textProperty().addListener((obs, oldText, newText) -> { - if (!newText.isEmpty()) { + if (!newText.trim().isEmpty()) { String[] text = newText.split("\\s+"); String command = text[0]; boolean hasParams = false; @@ -106,7 +106,6 @@ public AutoSuggestionTextField() { CommandTextFlow commandFlow = (CommandTextFlow) selectedTextFlow; setText(commandFlow.getCommandText()); this.positionCaret(commandFlow.getCommandText().length()); - suggestionPopup.hide(); } }); diff --git a/src/test/java/seedu/address/model/person/AddressTest.java b/src/test/java/seedu/address/model/person/AddressTest.java index 314885eca26..388334236ab 100644 --- a/src/test/java/seedu/address/model/person/AddressTest.java +++ b/src/test/java/seedu/address/model/person/AddressTest.java @@ -10,7 +10,7 @@ public class AddressTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Address(null)); + assertThrows(NullPointerException.class, () -> new Address((String) null)); } @Test diff --git a/src/test/java/seedu/address/model/person/EmailTest.java b/src/test/java/seedu/address/model/person/EmailTest.java index f08cdff0a64..ee0fdd5276d 100644 --- a/src/test/java/seedu/address/model/person/EmailTest.java +++ b/src/test/java/seedu/address/model/person/EmailTest.java @@ -10,7 +10,7 @@ public class EmailTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Email(null)); + assertThrows(NullPointerException.class, () -> new Email((String) null)); } @Test diff --git a/src/test/java/seedu/address/model/person/PhoneTest.java b/src/test/java/seedu/address/model/person/PhoneTest.java index deaaa5ba190..9dd6e7b4390 100644 --- a/src/test/java/seedu/address/model/person/PhoneTest.java +++ b/src/test/java/seedu/address/model/person/PhoneTest.java @@ -10,7 +10,7 @@ public class PhoneTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Phone(null)); + assertThrows(NullPointerException.class, () -> new Phone((String) null)); } @Test diff --git a/src/test/java/seedu/address/ui/CommandHistoryTest.java b/src/test/java/seedu/address/ui/CommandHistoryTest.java index 7d22ed2a32c..d1e8c1e9755 100644 --- a/src/test/java/seedu/address/ui/CommandHistoryTest.java +++ b/src/test/java/seedu/address/ui/CommandHistoryTest.java @@ -40,6 +40,16 @@ public void testPrevCommand() { assertNull(commandHistory.getPreviousCommand()); } + @Test + public void testOneCommand() { + commandHistory.addCommand("first command"); + + commandHistory.getPreviousCommand(); + commandHistory.getNextCommand(); + + assertEquals("first command", commandHistory.getPreviousCommand()); + assertEquals("", commandHistory.getNextCommand()); // No further next command after latest + } @Test public void testNextCommand() { commandHistory.addCommand("first command"); @@ -76,5 +86,6 @@ public void testMixedNavigation() { // After the latest command, there should be no more next command and change the textfield back to a blank assertEquals("", commandHistory.getNextCommand()); + assertEquals("third command", commandHistory.getPreviousCommand()); } } From a14d82c77e5a5319de890fe1cfebaae501fdc2a3 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:52:24 +0800 Subject: [PATCH 04/10] Fix commandHistory --- .../java/seedu/address/ui/CommandBox.java | 52 ++++++++++++------- .../java/seedu/address/ui/CommandHistory.java | 3 ++ .../commandpopup/AutoSuggestionTextField.java | 14 ++--- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/main/java/seedu/address/ui/CommandBox.java b/src/main/java/seedu/address/ui/CommandBox.java index 6c694135f4b..6cc9620c989 100644 --- a/src/main/java/seedu/address/ui/CommandBox.java +++ b/src/main/java/seedu/address/ui/CommandBox.java @@ -48,27 +48,41 @@ public CommandBox(CommandExecutor commandExecutor) { */ @FXML public void initialize() { - commandTextField.setOnKeyPressed(event -> { - if (event.getCode() == KeyCode.UP && !event.isShiftDown()) { - String previousCommand = commandHistory.getPreviousCommand(); - if (previousCommand != null) { - commandTextField.setText(previousCommand); - commandTextField.positionCaret(previousCommand.length()); // Move cursor to end - } - } - if (event.getCode() == KeyCode.DOWN && !event.isShiftDown()) { - String nextCommand = commandHistory.getNextCommand(); - if (nextCommand != null) { - commandTextField.setText(nextCommand); - commandTextField.positionCaret(nextCommand.length()); // Move cursor to end - } - } - if (event.getCode() == KeyCode.ENTER) { - handleCommandEntered(); - } - }); +// commandTextField.setOnKeyPressed(event -> { +// if (event.getCode() == KeyCode.UP && !event.isShiftDown()) { +// handleUpEntered(); +// } +// if (event.getCode() == KeyCode.DOWN && !event.isShiftDown()) { +// handleDownEntered(); +// } +// if (event.getCode() == KeyCode.ENTER) { +// handleCommandEntered(); +// } +// }); } + /** + * Handles the Up button pressed event. + */ + @FXML + public void handleUpEntered() { + String previousCommand = commandHistory.getPreviousCommand(); + if (previousCommand != null) { + commandTextField.setText(previousCommand); + commandTextField.positionCaret(previousCommand.length()); // Move cursor to end + } + } + /** + * Handles the Down button pressed event. + */ + @FXML + public void handleDownEntered() { + String nextCommand = commandHistory.getNextCommand(); + if (nextCommand != null) { + commandTextField.setText(nextCommand); + commandTextField.positionCaret(nextCommand.length()); // Move cursor to end + } + } /** * Handles the Enter button pressed event. diff --git a/src/main/java/seedu/address/ui/CommandHistory.java b/src/main/java/seedu/address/ui/CommandHistory.java index 211f0c02c57..d9c04b3e1fc 100644 --- a/src/main/java/seedu/address/ui/CommandHistory.java +++ b/src/main/java/seedu/address/ui/CommandHistory.java @@ -12,6 +12,7 @@ public class CommandHistory { * Adds a command to the ArrayList */ public void addCommand(String command) { + System.out.println("add cmd"); commandHistory.add(command); currentHistoryIndex = commandHistory.size(); // Reset index to point after the latest command } @@ -20,6 +21,7 @@ public void addCommand(String command) { * Retrieves the previous command from the ArrayList, outputs null if already at the front of the arraylist */ public String getPreviousCommand() { + System.out.println("prev cmd"); if (currentHistoryIndex > 0) { currentHistoryIndex--; return commandHistory.get(currentHistoryIndex); @@ -31,6 +33,7 @@ public String getPreviousCommand() { * Retrieves the next command from the ArrayList, outputs null if already at the end of the arraylist */ public String getNextCommand() { + System.out.println("next cmd"); if (currentHistoryIndex < commandHistory.size() - 1) { currentHistoryIndex++; return commandHistory.get(currentHistoryIndex); diff --git a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java index ab6287f5746..2cb69ba5211 100644 --- a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java +++ b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java @@ -43,7 +43,6 @@ public class AutoSuggestionTextField extends TextField { private PopupControl suggestionPopup; private ListView suggestionList; private CommandBox commandBox; - private ObservableList textFlowItems; /** @@ -81,6 +80,12 @@ public AutoSuggestionTextField() { // Add key event handler to both the TextField and ListView EventHandler keyEventHandler = event -> { + if (event.getCode() == KeyCode.UP && !event.isShiftDown()) { + commandBox.handleUpEntered(); + } + if (event.getCode() == KeyCode.DOWN && !event.isShiftDown()) { + commandBox.handleDownEntered(); + } if (event.isShiftDown()) { switch (event.getCode()) { case UP: @@ -97,6 +102,8 @@ public AutoSuggestionTextField() { } else if (event.getCode() == KeyCode.TAB) { handleTab(); event.consume(); + } else if (event.getCode() == KeyCode.ENTER) { + handleCommandEntered(); } }; @@ -113,11 +120,6 @@ public AutoSuggestionTextField() { this.addEventHandler(KeyEvent.KEY_PRESSED, keyEventHandler); suggestionList.addEventHandler(KeyEvent.KEY_PRESSED, keyEventHandler); - // Ensure the TextField keeps focus when showing popup - suggestionPopup.setOnShowing(event -> { - Platform.runLater(() -> this.requestFocus()); - }); - // Prevent ListView from handling its default key events suggestionList.addEventFilter(KeyEvent.ANY, event -> { if (event.isControlDown() || (event.isShiftDown() && event.getCode() == KeyCode.ENTER)) { From eaf02338858883dd16fec904d37ab83c3a6a5d56 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 04:01:51 +0800 Subject: [PATCH 05/10] Fix CommandHistory --- src/main/java/seedu/address/ui/CommandBox.java | 18 ------------------ .../commandpopup/AutoSuggestionTextField.java | 1 - 2 files changed, 19 deletions(-) diff --git a/src/main/java/seedu/address/ui/CommandBox.java b/src/main/java/seedu/address/ui/CommandBox.java index 6cc9620c989..ecc99d4b2be 100644 --- a/src/main/java/seedu/address/ui/CommandBox.java +++ b/src/main/java/seedu/address/ui/CommandBox.java @@ -5,7 +5,6 @@ import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.scene.input.KeyCode; import javafx.scene.layout.Region; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -43,23 +42,6 @@ public CommandBox(CommandExecutor commandExecutor) { commandTextField.textProperty().addListener((unused1, unused2, unused3) -> setStyleToDefault()); } - /** - * initialize() method from javaFx, used to check for arrow inputs inside the commandTextField - */ - @FXML - public void initialize() { -// commandTextField.setOnKeyPressed(event -> { -// if (event.getCode() == KeyCode.UP && !event.isShiftDown()) { -// handleUpEntered(); -// } -// if (event.getCode() == KeyCode.DOWN && !event.isShiftDown()) { -// handleDownEntered(); -// } -// if (event.getCode() == KeyCode.ENTER) { -// handleCommandEntered(); -// } -// }); - } /** * Handles the Up button pressed event. diff --git a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java index 2cb69ba5211..541119777f0 100644 --- a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java +++ b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java @@ -5,7 +5,6 @@ import java.util.SortedSet; import java.util.stream.Collectors; -import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; From bf22429a891ece8e0609fb327f34ac1a4b863c17 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 04:04:29 +0800 Subject: [PATCH 06/10] Update CommandHistory.java --- src/main/java/seedu/address/ui/CommandHistory.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/seedu/address/ui/CommandHistory.java b/src/main/java/seedu/address/ui/CommandHistory.java index d9c04b3e1fc..211f0c02c57 100644 --- a/src/main/java/seedu/address/ui/CommandHistory.java +++ b/src/main/java/seedu/address/ui/CommandHistory.java @@ -12,7 +12,6 @@ public class CommandHistory { * Adds a command to the ArrayList */ public void addCommand(String command) { - System.out.println("add cmd"); commandHistory.add(command); currentHistoryIndex = commandHistory.size(); // Reset index to point after the latest command } @@ -21,7 +20,6 @@ public void addCommand(String command) { * Retrieves the previous command from the ArrayList, outputs null if already at the front of the arraylist */ public String getPreviousCommand() { - System.out.println("prev cmd"); if (currentHistoryIndex > 0) { currentHistoryIndex--; return commandHistory.get(currentHistoryIndex); @@ -33,7 +31,6 @@ public String getPreviousCommand() { * Retrieves the next command from the ArrayList, outputs null if already at the end of the arraylist */ public String getNextCommand() { - System.out.println("next cmd"); if (currentHistoryIndex < commandHistory.size() - 1) { currentHistoryIndex++; return commandHistory.get(currentHistoryIndex); From 8fc3447ef79bc5291a57f6400abc0e273e10b40f Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:42:23 +0800 Subject: [PATCH 07/10] Fix json reading --- .../address/storage/JsonAdaptedPerson.java | 56 +++++++++++-------- .../commandpopup/AutoSuggestionTextField.java | 3 +- .../logic/parser/AddCommandParserTest.java | 16 ------ .../logic/parser/EditCommandParserTest.java | 2 - .../storage/JsonAdaptedPersonTest.java | 16 ++++-- 5 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index cab409290dd..4d9978cfccb 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -14,6 +14,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.game.Game; import seedu.address.model.person.Address; +import seedu.address.model.person.Blank; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -42,10 +43,10 @@ class JsonAdaptedPerson { */ @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags, - @JsonProperty("games") List games, - @JsonProperty("preferred times") List preferredTimes) { + @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("tags") List tags, + @JsonProperty("games") List games, + @JsonProperty("preferred times") List preferredTimes) { this.name = name; this.phone = phone; this.email = email; @@ -95,7 +96,7 @@ public Person toModelType() throws IllegalValueException { personGames.put(game.getGameName(), game.toModelType()); } final List personPreferredTimes = new ArrayList<>(); - for (JsonAdaptedPreferredTime preferredTime: preferredTimes) { + for (JsonAdaptedPreferredTime preferredTime : preferredTimes) { personPreferredTimes.add(preferredTime.toModelType()); } @@ -107,29 +108,38 @@ public Person toModelType() throws IllegalValueException { } final Name modelName = new Name(name); - if (phone == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); - } - if (!Phone.isValidPhone(phone)) { - throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); - } - final Phone modelPhone = new Phone(phone); - if (email == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); + final Phone modelPhone; + if (phone.isEmpty()) { + modelPhone = new Phone(new Blank()); + } else { + if (!Phone.isValidPhone(phone)) { + throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); + } + modelPhone = new Phone(phone); } - if (!Email.isValidEmail(email)) { - throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); - } - final Email modelEmail = new Email(email); - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); + final Email modelEmail; + if (email.isEmpty()) { + System.out.println("help"); + modelEmail = new Email(new Blank()); + } else { + if (!Email.isValidEmail(email)) { + throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); + } + System.out.println("uh oh"); + modelEmail = new Email(email); } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); + + final Address modelAddress; + if (address.isEmpty()) { + modelAddress = new Address(new Blank()); + } else { + if (!Address.isValidAddress(address)) { + throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); + } + modelAddress = new Address(address); } - final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(personTags); final Map modelGames = new HashMap<>(personGames); diff --git a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java index 541119777f0..f501660d44c 100644 --- a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java +++ b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java @@ -232,7 +232,7 @@ public void hidePopup() { } /** - * Sets the CommandBox object that processes commands entered in the TextField. + * Sets the CommandBox object that processes commands entered into the TextField. * * @param commandBox The CommandBox object to be set. */ @@ -353,6 +353,7 @@ public void populatePopup(List filteredList, String searchRequest) { } } + /** * Build TextFlow with selected text. Return "case" dependent. * diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 8d910548bf0..3b617d847db 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -37,7 +37,6 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.AddCommand; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -146,17 +145,6 @@ public void parse_compulsoryFieldMissing_failure() { assertParseFailure(parser, VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB, expectedMessage); - // missing phone prefix - assertParseFailure(parser, NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB, - expectedMessage); - - // missing email prefix - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + ADDRESS_DESC_BOB, - expectedMessage); - - // missing address prefix - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_ADDRESS_BOB, - expectedMessage); // all prefixes missing assertParseFailure(parser, VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_ADDRESS_BOB, @@ -177,10 +165,6 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ADDRESS_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS); - // invalid address - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Address.MESSAGE_CONSTRAINTS); - // invalid tag assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + INVALID_TAG_DESC + VALID_TAG_FRIEND, Tag.MESSAGE_CONSTRAINTS); diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index cc7175172d4..f0f7eaf3e0a 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -38,7 +38,6 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; @@ -86,7 +85,6 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email - assertParseFailure(parser, "1" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag // invalid phone followed by valid email diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index 330256f69a4..ab5ad857ac8 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -1,5 +1,6 @@ package seedu.address.storage; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.storage.JsonAdaptedPerson.MISSING_FIELD_MESSAGE_FORMAT; import static seedu.address.testutil.Assert.assertThrows; @@ -86,27 +87,30 @@ public void toModelType_invalidEmail_throwsIllegalValueException() { } @Test - public void toModelType_nullEmail_throwsIllegalValueException() { + public void toModelType_nullEmail_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test - public void toModelType_invalidAddress_throwsIllegalValueException() { + public void toModelType_invalidAddress_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = Address.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test - public void toModelType_nullAddress_throwsIllegalValueException() { + public void toModelType_nullAddress_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test From 595d0362803f2ac4dadd855720414f6df6e1ef7d Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:49:10 +0800 Subject: [PATCH 08/10] Update Test Cases --- .../java/seedu/address/storage/JsonAdaptedPersonTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index ab5ad857ac8..30ffe02e878 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -71,11 +71,12 @@ public void toModelType_invalidPhone_throwsIllegalValueException() { } @Test - public void toModelType_nullPhone_throwsIllegalValueException() { + public void toModelType_nullPhone_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test From c061bd49afb23ad68c05db8b729610fc75817bd0 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Wed, 6 Nov 2024 00:18:11 +0800 Subject: [PATCH 09/10] Update AddCommandParser.java --- .../logic/parser/AddCommandParser.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 184237f7088..4e96734ae23 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -47,24 +47,10 @@ public AddCommand parse(String args) throws ParseException { argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); - Phone phone; - if (arePrefixesPresent(argMultimap, PREFIX_PHONE)) { - phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); - } else { - phone = new Phone(new Blank()); - } - Email email; - if (arePrefixesPresent(argMultimap, PREFIX_EMAIL)) { - email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); - } else { - email = new Email(new Blank()); - } - Address address; - if (arePrefixesPresent(argMultimap, PREFIX_ADDRESS)) { - address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); - } else { - address = new Address(new Blank()); - } + + Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).orElse("")); + Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).orElse("")); + Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).orElse("")); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); Map gameList = ParserUtil.parseGames(argMultimap.getAllValues(PREFIX_GAME)); @@ -72,7 +58,6 @@ public AddCommand parse(String args) throws ParseException { ParserUtil.parsePreferredTimes(argMultimap.getAllValues(PREFIX_PREFERREDTIME)); Person person = new Person(name, phone, email, address, tagList, gameList, preferredTimeList); - return new AddCommand(person); } From 0ef27d39f2994909252dc058e86d5ea964b1b2a2 Mon Sep 17 00:00:00 2001 From: flyingsalsa <107453007+flyingsalsa@users.noreply.github.com> Date: Wed, 6 Nov 2024 00:19:59 +0800 Subject: [PATCH 10/10] Fix Checkstyle --- src/main/java/seedu/address/logic/parser/AddCommandParser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4e96734ae23..5e36d8b1052 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -17,7 +17,6 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.game.Game; import seedu.address.model.person.Address; -import seedu.address.model.person.Blank; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person;