Skip to content

Commit

Permalink
Merge pull request #99 from JWweiyin/master
Browse files Browse the repository at this point in the history
Edit add function
  • Loading branch information
JWweiyin authored Oct 28, 2021
2 parents 3aa9a5e + adaba60 commit f4f0cf2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ text-ui-test/EXPECTED-UNIX.TXT
*.log

# data files
/data/
/data/

# manifest files
*.MF
18 changes: 11 additions & 7 deletions src/main/java/seedu/cardli/commands/deck/AddCardCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@ 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);
}

String[] parameters = {front, back};
result = new CommandResult(deck.prepareToAddFlashCard(parameters));
} catch (FieldEmptyException | InvalidCommandFormatException e) {
} catch (FieldEmptyException e) {
result = new CommandResult(e.getMessage());
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/cardli/parser/deck/AddCardParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AddCardParser() {

@Override
public String[] parseArguments(String arguments) { //add /f <front> /b <back>
String[] parameters = arguments.trim().split(" ", 4);
String[] parameters = arguments.trim().split("/f|/b", 3);
return parameters;
}
}

0 comments on commit f4f0cf2

Please sign in to comment.