forked from AY2324S1-CS2103-F13-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c0305e
commit a176b70
Showing
21 changed files
with
190 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/seedu/address/logic/commands/RedoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Redo the most recent command that was undone. | ||
*/ | ||
public class RedoCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "redo"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Redo the most recent command that was undone."; | ||
|
||
private static final String MESSAGE_SUCCESS = | ||
"The last command that modified the employee list has been redone!\n" | ||
+ "Successfully redone the following command: %1$s"; | ||
|
||
@Override | ||
public CommandResult execute(Model model, String cmd) throws CommandException { | ||
requireNonNull(model); | ||
try { | ||
String commandText = model.redo(); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, commandText)); | ||
} catch (IllegalArgumentException e) { | ||
throw new CommandException(e.getMessage()); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/seedu/address/logic/commands/UndoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Undo the most recent command that modified the employee list. | ||
*/ | ||
public class UndoCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "undo"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Undo the most recent command that modified the employee list."; | ||
|
||
private static final String MESSAGE_SUCCESS = | ||
"The last command that modified the employee list has been undone!\n" | ||
+ "Successfully undone the following command: %1$s"; | ||
|
||
@Override | ||
public CommandResult execute(Model model, String cmd) throws CommandException { | ||
requireNonNull(model); | ||
try { | ||
String commandText = model.undo(); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, commandText)); | ||
} catch (IllegalArgumentException e) { | ||
throw new CommandException(e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package seedu.address.model; | ||
|
||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
import java.util.ArrayList; | ||
|
||
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."; | ||
private static final String UNDO_ERROR_MESSAGE = "There is no command to undo! " | ||
+ "The command to be undone need to previously modified the employee list."; | ||
|
||
private ArrayList<String> pastCommands = new ArrayList<String>(); | ||
private int index; | ||
|
||
public AddressBookList() { | ||
super(); | ||
index = -1; | ||
} | ||
|
||
@Override | ||
public boolean add(AddressBook addressBook) { | ||
index++; | ||
if (index < this.size()) { | ||
this.removeRange(index, this.size()); | ||
while (this.pastCommands.size() >= index) { | ||
this.pastCommands.remove(pastCommands.size() - 1); | ||
} | ||
} | ||
return super.add(addressBook); | ||
} | ||
|
||
public AddressBook getAddressBook() { | ||
return super.get(index); | ||
} | ||
|
||
public AddressBook undo() { | ||
checkArgument(index > 0, UNDO_ERROR_MESSAGE); | ||
index--; | ||
return super.get(index); | ||
} | ||
|
||
public AddressBook redo() { | ||
checkArgument(index < super.size() - 1, REDO_ERROR_MESSAGE); | ||
index++; | ||
return super.get(index); | ||
} | ||
|
||
public void addCommandText(String commandText) { | ||
this.pastCommands.add(commandText); | ||
} | ||
|
||
public String undoPastCommand() { | ||
return this.pastCommands.get(index); | ||
} | ||
|
||
public String redoPastCommand() { | ||
return this.pastCommands.get(index - 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.