From adaba602695f7b8fb2badb1bfb0c5b55a97d2096 Mon Sep 17 00:00:00 2001 From: "Wei Yin, Joanne Wong" Date: Thu, 28 Oct 2021 14:56:24 +0800 Subject: [PATCH] Edit add function User can now add more than one word on the front of the card --- .gitignore | 5 ++++- .../cardli/commands/deck/AddCardCommand.java | 18 +++++++++++------- .../cardli/parser/deck/AddCardParser.java | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 73dd13fb99..52691dd88d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,7 @@ text-ui-test/EXPECTED-UNIX.TXT *.log # data files -/data/ \ No newline at end of file +/data/ + +# manifest files +*.MF \ No newline at end of file diff --git a/src/main/java/seedu/cardli/commands/deck/AddCardCommand.java b/src/main/java/seedu/cardli/commands/deck/AddCardCommand.java index 52579ce919..a77d3d9f2e 100644 --- a/src/main/java/seedu/cardli/commands/deck/AddCardCommand.java +++ b/src/main/java/seedu/cardli/commands/deck/AddCardCommand.java @@ -32,16 +32,20 @@ public CommandResult execute() { } String[] rawParameters = parser.parseArguments(super.arguments); - if (rawParameters.length < 4) { + if (rawParameters.length < 3) { throw new FieldEmptyException(FIELD_EMPTY_ERROR_MESSAGE); } - - if (!rawParameters[0].equalsIgnoreCase("/f") || !rawParameters[2].equalsIgnoreCase("/b")) { - throw new InvalidCommandFormatException(WRONG_ORDER_ERROR_MESSAGE); + + String front = ""; + String back = ""; + if (arguments.indexOf("/f") < arguments.indexOf("/b")) { + front = rawParameters[1].trim(); + back = rawParameters[2].trim(); + } else if (arguments.indexOf("/b") < arguments.indexOf("/f")) { + back = rawParameters[1].trim(); + front = rawParameters[2].trim(); } - String front = rawParameters[1]; - String back = rawParameters[3]; if (front.isEmpty() || back.isEmpty()) { throw new FieldEmptyException(FIELD_EMPTY_ERROR_MESSAGE); @@ -49,7 +53,7 @@ public CommandResult execute() { String[] parameters = {front, back}; result = new CommandResult(deck.prepareToAddFlashCard(parameters)); - } catch (FieldEmptyException | InvalidCommandFormatException e) { + } catch (FieldEmptyException e) { result = new CommandResult(e.getMessage()); } return result; diff --git a/src/main/java/seedu/cardli/parser/deck/AddCardParser.java b/src/main/java/seedu/cardli/parser/deck/AddCardParser.java index 51cb0bf646..ce02f58228 100644 --- a/src/main/java/seedu/cardli/parser/deck/AddCardParser.java +++ b/src/main/java/seedu/cardli/parser/deck/AddCardParser.java @@ -17,7 +17,7 @@ public AddCardParser() { @Override public String[] parseArguments(String arguments) { //add /f /b - String[] parameters = arguments.trim().split(" ", 4); + String[] parameters = arguments.trim().split("/f|/b", 3); return parameters; } }