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.4d][F14-A3] Quentin Khoo #543

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
2 changes: 2 additions & 0 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public AddCommand(String name,
String email, boolean isEmailPrivate,
String address, boolean isAddressPrivate,
Set<String> tags) throws IllegalValueException {
super(true);
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
Expand All @@ -50,6 +51,7 @@ public AddCommand(String name,
}

public AddCommand(Person toAdd) {
super(true);
this.toAdd = toAdd;
}

Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class ClearCommand extends Command {

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

public ClearCommand() {
super(true);
}

@Override
public CommandResult execute() {
addressBook.clear();
Expand Down
9 changes: 7 additions & 2 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ public abstract class Command {
protected AddressBook addressBook;
protected List<? extends ReadOnlyPerson> relevantPersons;
private int targetIndex = -1;
private boolean isMutating;

/**
* @param targetIndex last visible listing index of the target person
*/
public Command(int targetIndex) {
public Command(int targetIndex, boolean isMutating) {
this.setTargetIndex(targetIndex);
this.isMutating = isMutating;
}

protected Command() {
protected Command(boolean isMutating) {
this.isMutating = isMutating;
}

/**
Expand Down Expand Up @@ -70,4 +73,6 @@ public int getTargetIndex() {
public void setTargetIndex(int targetIndex) {
this.targetIndex = targetIndex;
}

public boolean isMutating() { return isMutating; }
}
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DeleteCommand extends Command {


public DeleteCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
super(targetVisibleIndex, true);
}


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

public ExitCommand() {
super(false);
}
@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
Expand Down
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class FindCommand extends Command {
private final Set<String> keywords;

public FindCommand(Set<String> keywords) {
super(false);
this.keywords = keywords;
}

Expand Down
3 changes: 3 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class HelpCommand extends Command {
+ "\n" + HelpCommand.MESSAGE_USAGE
+ "\n" + ExitCommand.MESSAGE_USAGE;

public HelpCommand() {
super(false);
}
@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_ALL_USAGES);
Expand Down
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class IncorrectCommand extends Command{
public final String feedbackToUser;

public IncorrectCommand(String feedbackToUser){
super(false);
this.feedbackToUser = feedbackToUser;
}

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

public ListCommand() {
super(false);
}

@Override
public CommandResult execute() {
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ViewAllCommand extends Command {


public ViewAllCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
super(targetVisibleIndex, false);
}


Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ViewCommand extends Command {


public ViewCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
super(targetVisibleIndex, false);
}


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
7 changes: 6 additions & 1 deletion test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.parser.Parser;
import seedu.addressbook.storage.StorageFile;

import java.util.*;
Expand Down Expand Up @@ -77,6 +78,8 @@ private void assertCommandBehavior(String inputCommand,
boolean isRelevantPersonsExpected,
List<? extends ReadOnlyPerson> lastShownList) throws Exception {

//Parse command to determine if command is mutating
Command command = new Parser().parseCommand(inputCommand);
//Execute the command
CommandResult r = logic.execute(inputCommand);

Expand All @@ -90,7 +93,9 @@ private void assertCommandBehavior(String inputCommand,
//Confirm the state of data is as expected
assertEquals(expectedAddressBook, addressBook);
assertEquals(lastShownList, logic.getLastShownList());
assertEquals(addressBook, saveFile.load());
if (command.isMutating()) {
assertEquals(addressBook, saveFile.load());
}
}


Expand Down