Skip to content

Commit

Permalink
Fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Oct 22, 2023
1 parent e951253 commit 3d5a90e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
34 changes: 32 additions & 2 deletions src/main/java/seedu/address/model/AddressBookList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.ArrayList;

/**
* Represents the history of AddressBook to allow undo and redo.
*/
public class AddressBookList extends ArrayList<AddressBook> {
private static final String REDO_ERROR_MESSAGE = "There is no command to redo! "
+ "The command to be redone need to previously modified the employee list.";
Expand All @@ -13,6 +16,9 @@ public class AddressBookList extends ArrayList<AddressBook> {
private ArrayList<String> pastCommands = new ArrayList<String>();
private int index;

/**
* Initializes the AddressBookList.
*/
public AddressBookList() {
super();
index = -1;
Expand All @@ -30,30 +36,54 @@ public boolean add(AddressBook addressBook) {
return super.add(addressBook);
}

/**
* Returns the AddressBook at given index.
* @return
*/
public AddressBook getAddressBook() {
return super.get(index);
}

/**
* Updates the current AddressBook to the previous version.
* @return AddressBook
*/
public AddressBook undo() {
checkArgument(index > 0, UNDO_ERROR_MESSAGE);
index--;
return super.get(index);
return getAddressBook();
}

/**
* Updates the current AddressBook to the latest undone version.
* @return AddressBook
*/
public AddressBook redo() {
checkArgument(index < super.size() - 1, REDO_ERROR_MESSAGE);
index++;
return super.get(index);
return getAddressBook();
}

/**
* Stores the history of command texts.
* @param commandText
*/
public void addCommandText(String commandText) {
this.pastCommands.add(commandText);
}

/**
* Gets the previous command text.
* @return previous command text
*/
public String undoPastCommand() {
return this.pastCommands.get(index);
}

/**
* Gets the latest undone command text.
* @return latest undone command text
*/
public String redoPastCommand() {
return this.pastCommands.get(index - 1);
}
Expand Down
25 changes: 23 additions & 2 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void execute_personAcceptedByModel_addSuccessful() throws Exception {
ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded();
Person validPerson = new PersonBuilder().build();

CommandResult commandResult = new AddCommand(validPerson).execute(modelStub);
CommandResult commandResult = new AddCommand(validPerson).execute(modelStub, "");

assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
commandResult.getFeedbackToUser());
Expand All @@ -50,7 +50,8 @@ public void execute_duplicatePerson_throwsCommandException() {
AddCommand addCommand = new AddCommand(validPerson);
ModelStub modelStub = new ModelStubWithPerson(validPerson);

assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub));
assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PERSON,
() -> addCommand.execute(modelStub, ""));
}

@Test
Expand Down Expand Up @@ -157,6 +158,21 @@ public ObservableList<Person> getFilteredPersonList() {
public void updateFilteredPersonList(Predicate<Person> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public String undo() {
throw new AssertionError("This method should not be called.");
}

@Override
public String redo() {
throw new AssertionError("This method should not be called.");
}

@Override
public void addCommandText(String commandText) {
throw new AssertionError("This method should not be called.");
}
}

/**
Expand Down Expand Up @@ -199,6 +215,11 @@ public void addPerson(Person person) {
public ReadOnlyAddressBook getAddressBook() {
return new AddressBook();
}

@Override
public void addCommandText(String commandText) {
return;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void execute_birthday_success() {

@Test
public void execute_birthdayNoResults() {
CommandResult result = new BirthdayCommand(FILTER_TEST_PREDICATE_FAILURE).execute(model);
CommandResult result = new BirthdayCommand(FILTER_TEST_PREDICATE_FAILURE).execute(model, "");
assertEquals(result.toString(), new CommandResult(MESSAGE_FAILURE).toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class CommandTestUtil {
public static void assertCommandSuccess(Command command, Model actualModel, CommandResult expectedCommandResult,
Model expectedModel) {
try {
CommandResult result = command.execute(actualModel);
CommandResult result = command.execute(actualModel, "");
assertEquals(expectedCommandResult, result);
assertEquals(expectedModel, actualModel);
} catch (CommandException ce) {
Expand Down Expand Up @@ -134,7 +134,7 @@ public static void assertCommandFailure(Command command, Model actualModel, Stri
AddressBook expectedAddressBook = new AddressBook(actualModel.getAddressBook());
List<Person> expectedFilteredList = new ArrayList<>(actualModel.getFilteredPersonList());

assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel));
assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel, ""));
assertEquals(expectedAddressBook, actualModel.getAddressBook());
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void execute_validMultiplePhone_failure() throws CommandException {
+ "1. %s's Department is %s.\n\n", firstPersonToView.getName(), firstPersonToView.getDepartment())
+ String.format("You are viewing Claim Budget:\n"
+ "1. %s's Claim Budget is %s.\n\n", secondPersonToView.getName(), secondPersonToView.getClaimBudget());
assertNotEquals(newViewCommand.execute(model).toString(), wrongReponse);
assertNotEquals(newViewCommand.execute(model, "").toString(), wrongReponse);
}

@Test
Expand Down

0 comments on commit 3d5a90e

Please sign in to comment.