Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W6.1d][W09-B1] Fan Yuting #866

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public ReadOnlyPerson getPerson() {
return toAdd;
}

@Override
public boolean isMutating() {
return true;
}

@Override
public CommandResult execute() {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class ClearCommand extends Command {

public static final String MESSAGE_SUCCESS = "Address book has been cleared!";

@Override
public boolean isMutating() {
return true;
}

@Override
public CommandResult execute() {
addressBook.clear();
Expand Down
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public Command(int targetIndex) {
protected Command() {
}

/**
* Checks whether the command type mutates the data
* @return true if the data is mutated, false otherwise
*/
public abstract boolean isMutating();

/**
* Constructs a feedback message to summarise an operation that displayed a listing of persons.
*
Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public DeleteCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}

@Override
public boolean isMutating() {
return true;
}

@Override
public CommandResult execute() {
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class ExitCommand extends Command {
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_EXIT_ACKNOWEDGEMENT = "Exiting Address Book as requested ...";

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public Set<String> getKeywords() {
return new HashSet<>(keywords);
}

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
final List<ReadOnlyPerson> personsFound = getPersonsWithNameContainingAnyKeyword(keywords);
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class HelpCommand extends Command {
+ "\n" + HelpCommand.MESSAGE_USAGE
+ "\n" + ExitCommand.MESSAGE_USAGE;

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_ALL_USAGES);
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public IncorrectCommand(String feedbackToUser){
this.feedbackToUser = feedbackToUser;
}

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
return new CommandResult(feedbackToUser);
Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class ListCommand extends Command {
+ "Displays all persons in the address book as a list with index numbers.\n\t"
+ "Example: " + COMMAND_WORD;

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public ViewAllCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public ViewCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}

@Override
public boolean isMutating() {
return false;
}

@Override
public CommandResult execute() {
Expand Down
4 changes: 3 additions & 1 deletion src/seedu/addressbook/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public CommandResult execute(String userCommandText) throws Exception {
private CommandResult execute(Command command) throws Exception {
command.setData(addressBook, lastShownList);
CommandResult result = command.execute();
storage.save(addressBook);
if (command.isMutating()) {
storage.save(addressBook);
}
return result;
}

Expand Down