forked from nus-cs2103-AY2122S1/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 nniiggeell/Refactor-Student-Classes
Refactor student classes
- Loading branch information
Showing
17 changed files
with
220 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,22 +126,22 @@ Shows a list of all persons stored in NewAddressBook. | |
|
||
Format: `list` | ||
|
||
### Editing a person : `edit` | ||
### Editing a student : `editStudent` | ||
|
||
Edits an existing person in NewAddressBook. | ||
Edits an existing student in NewAddressBook. | ||
|
||
Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…` | ||
Format: `editStudent INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]…` | ||
|
||
* Edits the person at the specified `INDEX`. The index refers to the index number shown in the displayed person list. The index **must be a positive integer** 1, 2, 3, … | ||
* Edits the student at the specified `INDEX`. The index refers to the index number shown in the displayed person list. The index **must be a positive integer** 1, 2, 3, … | ||
* At least one of the optional fields must be provided. | ||
* Existing values will be updated to the input values. | ||
* When editing tags, the existing tags of the person will be removed i.e adding of tags is not cumulative. | ||
* You can remove all the person’s tags by typing `t/` without | ||
specifying any tags after it. | ||
|
||
Examples: | ||
* `edit 1 p/91234567 e/[email protected]` Edits the phone number and email address of the 1st person to be `91234567` and `[email protected]` respectively. | ||
* `edit 2 n/Betsy Crower t/` Edits the name of the 2nd person to be `Betsy Crower` and clears all existing tags. | ||
* `editStudent 1 p/91234567 e/[email protected]` Edits the phone number and email address of the 1st person to be `91234567` and `[email protected]` respectively. | ||
* `editStudent 2 n/Betsy Crower t/` Edits the name of the 2nd person to be `Betsy Crower` and clears all existing tags. | ||
|
||
### Locating persons by name: `find` | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
package seedu.address.logic.commands; | ||
|
||
import java.util.Set; | ||
|
80 changes: 80 additions & 0 deletions
80
src/main/java/seedu/address/logic/commands/student/AddStudentCommand.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,80 @@ | ||
package seedu.address.logic.commands.student; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMERGENCY_CONTACT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FORM_CLASS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Student; | ||
|
||
/** | ||
* Adds a student to the address book. | ||
*/ | ||
public class AddStudentCommand extends Command { | ||
public static final String COMMAND_WORD = "student"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a student to the address book. " | ||
+ "Parameters: " | ||
+ PREFIX_NAME + "NAME " | ||
+ PREFIX_PHONE + "PHONE " | ||
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_ADDRESS + "ADDRESS " | ||
+ PREFIX_GENDER + "GENDER " | ||
+ PREFIX_FORM_CLASS + "FORM CLASS " | ||
+ PREFIX_INVOLVEMENT + "INVOLVEMENT " | ||
+ "[" + PREFIX_TAG + "TAG]... " | ||
+ PREFIX_EMERGENCY_CONTACT + "EMERGENCY_CONTACT \n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_GENDER + "M " | ||
+ PREFIX_INVOLVEMENT + "Math class " | ||
+ PREFIX_TAG + "naughty " | ||
+ PREFIX_EMERGENCY_CONTACT + "999 " | ||
+ PREFIX_FORM_CLASS + "3E1"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New student added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the address book"; | ||
|
||
private final Student toAdd; | ||
|
||
/** | ||
* Creates an AddStudentCommand to add the specified {@code Student} | ||
*/ | ||
public AddStudentCommand(Student student) { | ||
requireNonNull(student); | ||
toAdd = student; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasPerson(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
} | ||
|
||
model.addPerson(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof seedu.address.logic.commands.student.AddStudentCommand // instanceof handles nulls | ||
&& toAdd.equals(((seedu.address.logic.commands.student.AddStudentCommand) other).toAdd)); | ||
} | ||
} | ||
|
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
76 changes: 76 additions & 0 deletions
76
src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.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,76 @@ | ||
package seedu.address.logic.parser.student; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMERGENCY_CONTACT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FORM_CLASS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.student.AddStudentCommand; | ||
import seedu.address.logic.parser.ArgumentMultimap; | ||
import seedu.address.logic.parser.ArgumentTokenizer; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.Prefix; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.FormClass; | ||
import seedu.address.model.person.Gender; | ||
import seedu.address.model.person.Involvement; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.Student; | ||
import seedu.address.model.tag.Tag; | ||
|
||
public class AddStudentCommandParser implements Parser<AddStudentCommand> { | ||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the StudentCommand | ||
* and returns an StudentCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddStudentCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_GENDER, | ||
PREFIX_INVOLVEMENT, PREFIX_TAG, PREFIX_EMERGENCY_CONTACT, PREFIX_FORM_CLASS); | ||
|
||
// put all the non-optional arguments here | ||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, | ||
PREFIX_EMERGENCY_CONTACT, PREFIX_INVOLVEMENT, PREFIX_FORM_CLASS, PREFIX_GENDER) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddStudentCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); | ||
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); | ||
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); | ||
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); | ||
Involvement involvement = ParserUtil.parseInvolvement(argMultimap.getValue(PREFIX_INVOLVEMENT).get()); | ||
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
Phone emergencyContact = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).get()); | ||
FormClass formClass = ParserUtil.parseFormClass(argMultimap.getValue(PREFIX_FORM_CLASS).get()); | ||
Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()); | ||
|
||
Student student = new Student(name, phone, email, address, involvement, tagList, emergencyContact, formClass, | ||
gender); | ||
|
||
return new AddStudentCommand(student); | ||
} | ||
} |
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
Oops, something went wrong.