forked from AY2324S1-CS2103T-T13-0/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
Showing
2 changed files
with
55 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package seedu.address.testutil; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_SEMESTER; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR; | ||
|
||
import seedu.address.logic.commands.AddCommand; | ||
import seedu.address.logic.commands.EditCommand.EditModuleDescriptor; | ||
import seedu.address.model.module.Module; | ||
|
||
|
||
/** | ||
* A utility class for Module. | ||
*/ | ||
public class ModuleUtil { | ||
/** | ||
* Returns an add command string for adding the {@code person}. | ||
*/ | ||
public static String getAddCommand(Module module) { | ||
return AddCommand.COMMAND_WORD + " " + getModuleDetails(module); | ||
} | ||
|
||
/** | ||
* Returns the part of command string for the given {@code person}'s details. | ||
*/ | ||
public static String getModuleDetails(Module module) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(PREFIX_CODE + module.getModuleCode().toString() + " "); | ||
sb.append(PREFIX_YEAR + module.getYearTaken().year.toString() + " "); | ||
sb.append(PREFIX_SEMESTER + module.getSemesterTaken().semester.toString() + " "); | ||
sb.append(PREFIX_GRADE + module.getGrade().toString() + " "); | ||
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Returns the part of command string for the given {@code EditModuleDescriptor}'s details. | ||
*/ | ||
public static String getEditModuleDescriptorDetails(EditModuleDescriptor descriptor) { | ||
StringBuilder sb = new StringBuilder(); | ||
descriptor.getYear().ifPresent(year -> sb.append(PREFIX_YEAR).append(year.toString()).append(" ")); | ||
descriptor.getSemester().ifPresent(semester -> sb.append(PREFIX_SEMESTER).append(semester.toString()).append(" ")); | ||
descriptor.getGrade().ifPresent(grade -> sb.append(PREFIX_GRADE).append(grade.toString()).append(" ")); | ||
|
||
return sb.toString(); | ||
} | ||
} |