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

[T5A2][F11-B3] Praveer Tewari #1698

Open
wants to merge 5 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: 4 additions & 1 deletion src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 6 additions & 1 deletion src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -67,4 +67,9 @@ public CommandResult execute() {
}
}

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

}
7 changes: 7 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 4 additions & 1 deletion src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ protected String getMessageForPersonListShownSummary(List<? extends ReadOnlyPers

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

/**
* Supplies the data the command will operate on.
Expand All @@ -65,4 +66,6 @@ public int getTargetIndex() {
public void setTargetIndex(int targetIndex) {
this.targetIndex = targetIndex;
}

public abstract boolean isMutating();
}
6 changes: 5 additions & 1 deletion src/seedu/addressbook/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class CommandResult {

/** The feedback message to be shown to the user. Contains a description of the execution result */
public final String feedbackToUser;
private final String feedbackToUser;

/** The list of persons that was produced by the command */
private final List<? extends ReadOnlyPerson> relevantPersons;
Expand All @@ -32,5 +32,9 @@ public CommandResult(String feedbackToUser, List<? extends ReadOnlyPerson> relev
public Optional<List<? extends ReadOnlyPerson>> getRelevantPersons() {
return Optional.ofNullable(relevantPersons);
}

public String getFeedbackToUser() {
return feedbackToUser;
}

}
7 changes: 7 additions & 0 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ public CommandResult execute() {
}
}


@Override
public boolean isMutating() {
// TODO Auto-generated method stub
return true;
}

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

@Override
public boolean isMutating() {
// TODO Auto-generated method stub
return false;
}

}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public CommandResult execute() {
+ "\n" + ExitCommand.MESSAGE_USAGE
);
}

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

@Override
public boolean isMutating() {
// TODO Auto-generated method stub
return false;
}

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


@Override
public boolean isMutating() {
// TODO Auto-generated method stub
return false;
}
}
7 changes: 7 additions & 0 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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() {
// TODO Auto-generated method stub
return false;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/data/person/Printable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package seedu.addressbook.data.person;

public interface Printable {

}
2 changes: 1 addition & 1 deletion src/seedu/addressbook/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void showResultToUser(CommandResult result) {
if(resultPersons.isPresent()) {
showPersonListView(resultPersons.get());
}
showToUser(result.feedbackToUser, DIVIDER);
showToUser(result.getFeedbackToUser(), DIVIDER);
}

/**
Expand Down