diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index dd9f9aa65..c47268f34 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -107,7 +107,10 @@ private CommandResult executeCommand(Command command) { try { command.setData(addressBook, lastShownList); CommandResult result = command.execute(); - storage.save(addressBook); + if (command.isMutating()) { + storage.save(addressBook); + } + return result; } catch (Exception e) { ui.showToUser(e.getMessage()); diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index 7ed3cf359..224d648c1 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -58,7 +58,7 @@ public ReadOnlyPerson getPerson() { } @Override - public CommandResult execute() { + public CommandResult execute() throws Exception{ try { addressBook.addPerson(toAdd); return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); @@ -67,4 +67,9 @@ public CommandResult execute() { } } + @Override + public boolean isMutating() { + return true; + } + } diff --git a/src/seedu/addressbook/commands/ClearCommand.java b/src/seedu/addressbook/commands/ClearCommand.java index f1bafb8a2..a8acc9395 100644 --- a/src/seedu/addressbook/commands/ClearCommand.java +++ b/src/seedu/addressbook/commands/ClearCommand.java @@ -22,4 +22,11 @@ public CommandResult execute() { addressBook.clear(); return new CommandResult(MESSAGE_SUCCESS); } + + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return true; + } } diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index 2e4708de9..3464a4e31 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -38,8 +38,9 @@ protected String getMessageForPersonListShownSummary(List relevantPersons; @@ -32,5 +32,9 @@ public CommandResult(String feedbackToUser, List relev public Optional> getRelevantPersons() { return Optional.ofNullable(relevantPersons); } + + public String getFeedbackToUser() { + return feedbackToUser; + } } diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 493d75da6..14ebf10cf 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -39,4 +39,11 @@ public CommandResult execute() { } } + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return true; + } + } diff --git a/src/seedu/addressbook/commands/ExitCommand.java b/src/seedu/addressbook/commands/ExitCommand.java index 2f280395c..06a7a0179 100644 --- a/src/seedu/addressbook/commands/ExitCommand.java +++ b/src/seedu/addressbook/commands/ExitCommand.java @@ -19,4 +19,10 @@ public CommandResult execute() { public static boolean isExit(Command command) { return command instanceof ExitCommand; // instanceof returns false if it is null } + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/seedu/addressbook/commands/FindCommand.java b/src/seedu/addressbook/commands/FindCommand.java index 8937e08da..4a58ce0cc 100644 --- a/src/seedu/addressbook/commands/FindCommand.java +++ b/src/seedu/addressbook/commands/FindCommand.java @@ -53,4 +53,10 @@ private List getPersonsWithNameContainingAnyKeyword(Set return matchedPersons; } + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } + } diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 8a36e8337..1bb956f9a 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -27,4 +27,10 @@ public CommandResult execute() { + "\n" + ExitCommand.MESSAGE_USAGE ); } + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/seedu/addressbook/commands/IncorrectCommand.java b/src/seedu/addressbook/commands/IncorrectCommand.java index 81abba7a1..546ead34a 100644 --- a/src/seedu/addressbook/commands/IncorrectCommand.java +++ b/src/seedu/addressbook/commands/IncorrectCommand.java @@ -17,4 +17,10 @@ public CommandResult execute() { return new CommandResult(feedbackToUser); } + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } + } diff --git a/src/seedu/addressbook/commands/ListCommand.java b/src/seedu/addressbook/commands/ListCommand.java index d76d48297..0e7b8593f 100644 --- a/src/seedu/addressbook/commands/ListCommand.java +++ b/src/seedu/addressbook/commands/ListCommand.java @@ -22,4 +22,11 @@ public CommandResult execute() { List allPersons = addressBook.getAllPersons().immutableListView(); return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons); } + + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/seedu/addressbook/commands/ViewAllCommand.java b/src/seedu/addressbook/commands/ViewAllCommand.java index 0067304bb..10c81463a 100644 --- a/src/seedu/addressbook/commands/ViewAllCommand.java +++ b/src/seedu/addressbook/commands/ViewAllCommand.java @@ -37,4 +37,11 @@ public CommandResult execute() { return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } } + + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } } diff --git a/src/seedu/addressbook/commands/ViewCommand.java b/src/seedu/addressbook/commands/ViewCommand.java index 69335c849..cb67b9402 100644 --- a/src/seedu/addressbook/commands/ViewCommand.java +++ b/src/seedu/addressbook/commands/ViewCommand.java @@ -38,4 +38,11 @@ public CommandResult execute() { } } + + @Override + public boolean isMutating() { + // TODO Auto-generated method stub + return false; + } + } diff --git a/src/seedu/addressbook/data/person/Printable.java b/src/seedu/addressbook/data/person/Printable.java new file mode 100644 index 000000000..43e93d373 --- /dev/null +++ b/src/seedu/addressbook/data/person/Printable.java @@ -0,0 +1,5 @@ +package seedu.addressbook.data.person; + +public interface Printable { + +} diff --git a/src/seedu/addressbook/ui/TextUi.java b/src/seedu/addressbook/ui/TextUi.java index 39a2c6615..8442aa2fe 100644 --- a/src/seedu/addressbook/ui/TextUi.java +++ b/src/seedu/addressbook/ui/TextUi.java @@ -126,7 +126,7 @@ public void showResultToUser(CommandResult result) { if(resultPersons.isPresent()) { showPersonListView(resultPersons.get()); } - showToUser(result.feedbackToUser, DIVIDER); + showToUser(result.getFeedbackToUser(), DIVIDER); } /**