forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #53 from saiutkarsh33/branch-SetCourseCommand
Branch set course command
- Loading branch information
Showing
48 changed files
with
1,200 additions
and
73 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
73 changes: 73 additions & 0 deletions
73
src/main/java/seedu/address/logic/commands/SetCourseCommand.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,73 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.model.course.Course.isValidCode; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.logic.commands.util.CommandMessageUsageUtil; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.course.Course; | ||
|
||
|
||
|
||
/** | ||
* Represents a command to set the current course in the application. | ||
* This command updates the application's state to reflect the specified course. | ||
* The command follows a specific format for the course code, which should match "XX1234Y", | ||
* where "Y" is optional. It is designed to handle the action triggered by the user input | ||
* corresponding to setting a new course within the application. | ||
*/ | ||
public class SetCourseCommand extends Command { | ||
public static final String COMMAND_WORD = "setcrs"; | ||
|
||
public static final String MESSAGE_ARGUMENTS = "Course: %1$s"; | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"Course code should follow the format \"XX1234Y\", Y is optional"; | ||
|
||
public static final String MESSAGE_USAGE = CommandMessageUsageUtil.generateMessageUsage(COMMAND_WORD, | ||
"Set Course name ", "course code", COMMAND_WORD + " CS2104"); | ||
|
||
public static final String MESSAGE_SUCCESS = "Successfully updated course name"; | ||
|
||
|
||
private final Course course; | ||
|
||
/** | ||
* Creates a SetCourseCommand with the specified course. | ||
* This constructor initializes a new instance of SetCourseCommand with a given Course object. | ||
* It requires the Course object to be non-null and expects it to adhere to the defined course | ||
* code constraints outlined. | ||
* | ||
* @param course The course to be set by this command. Must not be null and should take the courses | ||
*/ | ||
public SetCourseCommand(Course course) { | ||
requireAllNonNull(course); | ||
this.course = course; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
if (!isValidCode(course.toString())) { | ||
throw new CommandException(MESSAGE_CONSTRAINTS); | ||
} | ||
model.changeCode(course.toString()); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof SetCourseCommand)) { | ||
return false; | ||
} | ||
|
||
SetCourseCommand e = (SetCourseCommand) other; | ||
return course.equalsIgnoreCase(e.course); | ||
|
||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/address/logic/parser/SetCourseCommandParser.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,33 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.SetCourseCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.course.Course; | ||
|
||
/** | ||
* Parses input arguments and creates a new {@code SetCourseCommand} object. | ||
*/ | ||
public class SetCourseCommandParser implements Parser<SetCourseCommand> { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the {@code RemarkCommand} | ||
* and returns a {@code RemarkCommand} object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public SetCourseCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
|
||
Course course; | ||
try { | ||
course = ParserUtil.parseCourse(args); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
SetCourseCommand.MESSAGE_CONSTRAINTS), ive); | ||
} | ||
|
||
return new SetCourseCommand(course); | ||
} | ||
} |
Oops, something went wrong.