forked from nus-cs2103-AY2122S1/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.
Merge pull request nus-cs2103-AY2122S1#79 from itzblim/add-list-commands
Add list commands
- Loading branch information
Showing
15 changed files
with
357 additions
and
41 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
src/main/java/seedu/address/logic/commands/ListCommand.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/main/java/seedu/address/logic/commands/list/ListCommand.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,16 @@ | ||
package seedu.address.logic.commands.list; | ||
|
||
import seedu.address.logic.commands.Command; | ||
|
||
/** | ||
* Lists all modules / lessons / exams in the address book to the user. | ||
*/ | ||
public abstract class ListCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "list"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all modules / lessons / exams.\n" | ||
+ "Parameters: [mod / lesson / exam]\n" | ||
+ "Example: " + COMMAND_WORD + " mod"; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/commands/list/ListExamCommand.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,30 @@ | ||
package seedu.address.logic.commands.list; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES; | ||
|
||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.GuiState; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists all exams in the ModBook to the user. | ||
*/ | ||
public class ListExamCommand extends ListCommand { | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all exams."; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
model.updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES); | ||
return new CommandResult(MESSAGE_SUCCESS, false, GuiState.EXAMS); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ListExamCommand); // state check | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/commands/list/ListLessonCommand.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,30 @@ | ||
package seedu.address.logic.commands.list; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES; | ||
|
||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.GuiState; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists all lessons in the ModBook to the user. | ||
*/ | ||
public class ListLessonCommand extends ListCommand { | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all lessons."; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
model.updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES); | ||
return new CommandResult(MESSAGE_SUCCESS, false, GuiState.LESSONS); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ListLessonCommand); // state check | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/commands/list/ListModCommand.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,30 @@ | ||
package seedu.address.logic.commands.list; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES; | ||
|
||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.GuiState; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists all modules in the ModBook to the user. | ||
*/ | ||
public class ListModCommand extends ListCommand { | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all modules."; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
model.updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES); | ||
return new CommandResult(MESSAGE_SUCCESS, false, GuiState.SUMMARY); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ListModCommand); // state check | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/main/java/seedu/address/logic/parser/ListCommandParser.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,52 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.logic.commands.GuiState; | ||
import seedu.address.logic.commands.list.ListCommand; | ||
import seedu.address.logic.commands.list.ListExamCommand; | ||
import seedu.address.logic.commands.list.ListLessonCommand; | ||
import seedu.address.logic.commands.list.ListModCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new ListCommand object | ||
*/ | ||
public class ListCommandParser implements Parser<ListCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ListCommand | ||
* and returns a ListCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ListCommand parse(String args, GuiState guiState) throws ParseException { | ||
|
||
if (hasMultipleArguments(args)) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
try { | ||
Type type = ParserUtil.parseFirstArg(args, ListCommand.MESSAGE_USAGE); | ||
switch (type) { | ||
case LESSON: | ||
return new ListLessonCommand(); | ||
case EXAM: | ||
return new ListExamCommand(); | ||
default: | ||
return new ListModCommand(); | ||
} | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if an argument string has multiple arguments | ||
*/ | ||
private static boolean hasMultipleArguments(String args) { | ||
return args.trim().split(" ", 2).length != 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
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
46 changes: 46 additions & 0 deletions
46
src/test/java/seedu/address/logic/commands/list/ListExamCommandTest.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,46 @@ | ||
package seedu.address.logic.commands.list; | ||
|
||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.logic.commands.CommandTestUtil.showModuleAtIndex; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_MODULE; | ||
import static seedu.address.testutil.TypicalModules.getTypicalModBook; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.GuiState; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for ListExamCommand. | ||
*/ | ||
public class ListExamCommandTest { | ||
|
||
private Model model; | ||
private Model expectedModel; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
model = new ModelManager(getTypicalAddressBook(), getTypicalModBook(), new UserPrefs()); | ||
expectedModel = new ModelManager(getTypicalAddressBook(), getTypicalModBook(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void execute_listIsNotFiltered_showsSameList() { | ||
assertCommandSuccess(new ListExamCommand(), model, | ||
new CommandResult(ListExamCommand.MESSAGE_SUCCESS, false, GuiState.EXAMS), | ||
expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_listIsFiltered_showsEverything() { | ||
showModuleAtIndex(model, INDEX_FIRST_MODULE); | ||
assertCommandSuccess(new ListExamCommand(), model, | ||
new CommandResult(ListExamCommand.MESSAGE_SUCCESS, false, GuiState.EXAMS), | ||
expectedModel); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/seedu/address/logic/commands/list/ListLessonCommandTest.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,46 @@ | ||
package seedu.address.logic.commands.list; | ||
|
||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.logic.commands.CommandTestUtil.showModuleAtIndex; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_MODULE; | ||
import static seedu.address.testutil.TypicalModules.getTypicalModBook; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.GuiState; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for ListLessonCommand. | ||
*/ | ||
public class ListLessonCommandTest { | ||
|
||
private Model model; | ||
private Model expectedModel; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
model = new ModelManager(getTypicalAddressBook(), getTypicalModBook(), new UserPrefs()); | ||
expectedModel = new ModelManager(getTypicalAddressBook(), getTypicalModBook(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void execute_listIsNotFiltered_showsSameList() { | ||
assertCommandSuccess(new ListLessonCommand(), model, | ||
new CommandResult(ListLessonCommand.MESSAGE_SUCCESS, false, GuiState.LESSONS), | ||
expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_listIsFiltered_showsEverything() { | ||
showModuleAtIndex(model, INDEX_FIRST_MODULE); | ||
assertCommandSuccess(new ListLessonCommand(), model, | ||
new CommandResult(ListLessonCommand.MESSAGE_SUCCESS, false, GuiState.LESSONS), | ||
expectedModel); | ||
} | ||
} |
Oops, something went wrong.