diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 71656d7c5c8..3b5398a1eb6 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -4,9 +4,12 @@ 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_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PERFORMANCE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHOTO; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; + import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Person; @@ -23,13 +26,17 @@ public class AddCommand extends Command { + PREFIX_NAME + "NAME " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + + PREFIX_PHOTO + "PHOTO " + PREFIX_ADDRESS + "ADDRESS " + + PREFIX_PERFORMANCE + "PERFORMANCE " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + + PREFIX_PHOTO + "(link to image) " + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + + PREFIX_PERFORMANCE + "40 " + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; diff --git a/src/main/java/seedu/address/logic/commands/PerformanceCommand.java b/src/main/java/seedu/address/logic/commands/PerformanceCommand.java index 09b88f8122f..1c209b5672f 100644 --- a/src/main/java/seedu/address/logic/commands/PerformanceCommand.java +++ b/src/main/java/seedu/address/logic/commands/PerformanceCommand.java @@ -75,7 +75,8 @@ public CommandResult execute(Model model) throws CommandException { * {@code personToEdit}. */ private String generateSuccessMessage(Person personToEdit) { - String message = !performance.value.isEmpty() ? MESSAGE_ADD_PERFORMANCE_SUCCESS + String message = !performance.value.isEmpty() + ? MESSAGE_ADD_PERFORMANCE_SUCCESS : MESSAGE_DELETE_PERFORMANCE_SUCCESS; return String.format(message, personToEdit); } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index b8888d38fab..749753dbc2e 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -4,6 +4,7 @@ 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_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PERFORMANCE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHOTO; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -36,9 +37,9 @@ public class AddCommandParser implements Parser { public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_PHOTO, - PREFIX_ADDRESS, PREFIX_TAG); + PREFIX_ADDRESS, PREFIX_PERFORMANCE, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_PHOTO) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_PHOTO, PREFIX_PERFORMANCE) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } @@ -48,8 +49,10 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Photo photo = ParserUtil.parsePhoto(argMultimap.getValue(PREFIX_PHOTO).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); + Remark remark = new Remark(); // add command does not allow adding remarks straight away - Performance performance = new Performance(); // add command does not allow adding performances straight away + Performance performance = ParserUtil.parsePerformance(argMultimap.getValue(PREFIX_PERFORMANCE).get()); + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); Person person = new Person(name, phone, email, photo, address, remark, performance, tagList); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 08a28371ff3..4a1ac97031d 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -12,6 +12,7 @@ import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.Performance; import seedu.address.model.person.Phone; import seedu.address.model.person.Photo; import seedu.address.model.tag.Tag; @@ -137,4 +138,13 @@ public static Set parseTags(Collection tags) throws ParseException } return tagSet; } + + public static Performance parsePerformance(String performance) throws ParseException { + requireNonNull(performance); + String trimmedPerformance = performance.trim(); + if (!Performance.isValidPerformance(trimmedPerformance)) { + throw new ParseException(Performance.MESSAGE_CONSTRAINTS); + } + return new Performance(trimmedPerformance); + } } diff --git a/src/main/java/seedu/address/logic/parser/PerformanceCommandParser.java b/src/main/java/seedu/address/logic/parser/PerformanceCommandParser.java index 5c7e946af97..a7ee75f23ec 100644 --- a/src/main/java/seedu/address/logic/parser/PerformanceCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/PerformanceCommandParser.java @@ -31,7 +31,7 @@ public PerformanceCommand parse(String args) throws ParseException { PerformanceCommand.MESSAGE_USAGE), ive); } - String performance = argMultimap.getValue(PREFIX_PERFORMANCE).orElse(""); + String performance = argMultimap.getValue(PREFIX_PERFORMANCE).orElse("1"); return new PerformanceCommand(index, new Performance(performance)); } diff --git a/src/main/java/seedu/address/model/person/Performance.java b/src/main/java/seedu/address/model/person/Performance.java index e486e6f621e..168ea36e32f 100644 --- a/src/main/java/seedu/address/model/person/Performance.java +++ b/src/main/java/seedu/address/model/person/Performance.java @@ -1,13 +1,17 @@ package seedu.address.model.person; import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; /** - * Represents a Person's remark in the address book. + * Represents a Person's performance in the address book. * Guarantees: immutable; is always valid */ public class Performance { + public static final String NULL_PERFORMANCE = "None yet!"; + public static final String MESSAGE_CONSTRAINTS = "Must be an integer between 0 to 100"; + public final String value; @@ -17,20 +21,34 @@ public class Performance { */ public Performance(String performance) { requireNonNull(performance); - //Add check to make sure it is not a gibberish number + checkArgument(isValidPerformance(performance), Performance.MESSAGE_CONSTRAINTS); value = performance; } - /** - * Initiates null performance object without causing error. - */ - public Performance() { - value = NULL_PERFORMANCE; + public static boolean isValidPerformance(String performance) { + boolean validInteger = true; + for (int i = 0; i < performance.length(); i++) { + if (!Character.isDigit(performance.charAt(i))) { + validInteger = false; + } + } + int convertedNumber = 0; + try { + convertedNumber = Integer.parseInt(performance); + } catch (NumberFormatException nfe) { + return false; + } + if (validInteger) { + if (convertedNumber < 0 || convertedNumber > 100) { + validInteger = false; + } + } + return validInteger; } @Override public String toString() { - return value; + return String.valueOf(value); } @Override diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index b46a7666175..48b7f2204d4 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -112,6 +112,7 @@ public boolean equals(Object other) { && otherPerson.getEmail().equals(getEmail()) && otherPerson.getPhoto().equals(getPhoto()) && otherPerson.getAddress().equals(getAddress()) + && otherPerson.getPerformance().equals(getPerformance()) && otherPerson.getTags().equals(getTags()); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 58f77b18da6..404269d55d5 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -126,8 +126,10 @@ public Person toModelType() throws IllegalValueException { final Remark modelRemark = new Remark(remark); if (performance == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, - Performance.class.getSimpleName())); + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Performance.class.getSimpleName())); + } + if (!Performance.isValidPerformance(performance)) { + throw new IllegalValueException(String.format(Performance.MESSAGE_CONSTRAINTS)); } final Performance modelPerformance = new Performance(performance); diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 46f640d3365..4c7e6a00597 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -94,7 +94,7 @@ public PersonCard(Person person, int displayedIndex) { email.setText(person.getEmail().value); photo.setText(person.getPhoto().photoFilePath); remark.setText(person.getRemark().value); - performance.setText(person.getPerformance().value); + performance.setText(String.valueOf(person.getPerformance().value)); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));