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

[T5A1][T01-T3] Teo Shu Qi #23

Open
wants to merge 2 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
8 changes: 7 additions & 1 deletion src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;

Expand Down Expand Up @@ -58,7 +59,7 @@ public ReadOnlyPerson getPerson() {
}

@Override
public CommandResult execute() {
public CommandResult execute() throws DuplicatePersonException{
try {
addressBook.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand All @@ -67,4 +68,9 @@ public CommandResult execute() {
}
}

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

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean isMutating() {
return true;
}
}
6 changes: 5 additions & 1 deletion src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import seedu.addressbook.common.Messages;
import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.person.ReadOnlyPerson;
import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException;

import java.util.List;

Expand Down Expand Up @@ -38,8 +39,11 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly

/**
* Executes the command and returns the result.
* @throws DuplicatePersonException
*/
public abstract CommandResult execute();
public abstract CommandResult execute() throws DuplicatePersonException;

public abstract boolean isMutating();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to mention it returns true if the Command potentially mutates the data (header comments specify a contract, so try to be as precise as possible). E.g. Adding a duplicate person will not mutate data but the corresponding AddCommand object will still return true for this method.


/**
* Supplies the data the command will operate on.
Expand Down
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public CommandResult execute() {
}
}


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

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public CommandResult execute() {
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
}

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

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String>
return matchedPersons;
}

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

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public class HelpCommand extends Command {
public CommandResult execute() {
return new CommandResult(MESSAGE_ALL_USAGES);
}

@Override
public boolean isMutating() {
return false;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public CommandResult execute() {
return new CommandResult(feedbackToUser);
}

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

}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons);
}


@Override
public boolean isMutating() {
return false;
}
}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
}


@Override
public boolean isMutating() {
return false;
}
}
7 changes: 7 additions & 0 deletions src/seedu/addressbook/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public CommandResult execute() {
}
}


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


}
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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior of the code has been changed. Ensure the header comment and the tests have been updated.

return result;
}

Expand Down