From 7657246f2c843edd19f2626042bbb201bd1a3e79 Mon Sep 17 00:00:00 2001 From: DarylTew Date: Mon, 17 Sep 2018 20:38:28 +0800 Subject: [PATCH 001/881] Change Prefixes and descriptions of Message response messages Add [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] into Prefixes Change descriptions of MESSAGE_EDIT_PERSON_SUCCESS and MESSAGE_DUPLICATE_PERSON from "person" to "workout" --- .../address/logic/commands/EditCommand.java | 40 +++++++++++++------ .../seedu/address/logic/parser/CliSyntax.java | 13 ++++-- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index dc782d8e230f..73b19a8c397c 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,10 +1,17 @@ package seedu.address.logic.commands; 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_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +//import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +//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_TYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DURATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EQUIPMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INSTRUCTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; @@ -28,28 +35,35 @@ import seedu.address.model.tag.Tag; /** - * Edits the details of an existing person in the address book. + * Edits the details of an existing workout in the address book. */ public class EditCommand extends Command { public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " - + "by the index number used in the displayed person list. " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the workout identified " + + "by the index number used in the displayed workout list. " + "Existing values will be overwritten by the input values.\n" + "Parameters: INDEX (must be a positive integer) " + "[" + PREFIX_NAME + "NAME] " - + "[" + PREFIX_PHONE + "PHONE] " - + "[" + PREFIX_EMAIL + "EMAIL] " - + "[" + PREFIX_ADDRESS + "ADDRESS] " +// + "[" + PREFIX_PHONE + "PHONE] " +// + "[" + PREFIX_EMAIL + "EMAIL] " +// + "[" + PREFIX_ADDRESS + "ADDRESS] " + + "[" + PREFIX_TYPE + "TYPE] " + + "[" + PREFIX_DURATION + "DURATION] " + + "[" + PREFIX_DIFFICULTY + "DIFFICULTY] " + + "[" + PREFIX_EQUIPMENT + "EQUIPMENT] " + + "[" + PREFIX_MUSCLE + "MUSCLE] " + + "[" + PREFIX_CALORIES + "CALORIES] " + + "[" + PREFIX_INSTRUCTION + "INSTRUCTION] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " - + PREFIX_PHONE + "91234567 " - + PREFIX_EMAIL + "johndoe@example.com"; + + PREFIX_TYPE + "Anaerobic " + + PREFIX_DIFFICULTY + "Beginner"; - public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; + public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Workout: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; + public static final String MESSAGE_DUPLICATE_PERSON = "This workout already exists in the address book."; private final Index index; private final EditPersonDescriptor editPersonDescriptor; diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf1190..445b743e1f0a 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -7,9 +7,16 @@ public class CliSyntax { /* Prefix definitions */ public static final Prefix PREFIX_NAME = new Prefix("n/"); - public static final Prefix PREFIX_PHONE = new Prefix("p/"); - public static final Prefix PREFIX_EMAIL = new Prefix("e/"); - public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); +// public static final Prefix PREFIX_PHONE = new Prefix("p/"); +// public static final Prefix PREFIX_EMAIL = new Prefix("e/"); +// public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); + public static final Prefix PREFIX_TYPE = new Prefix("t/"); + public static final Prefix PREFIX_DURATION = new Prefix("du/"); + public static final Prefix PREFIX_DIFFICULTY = new Prefix("di/"); + public static final Prefix PREFIX_EQUIPMENT = new Prefix("e/"); + public static final Prefix PREFIX_MUSCLE = new Prefix("m/"); + public static final Prefix PREFIX_CALORIES = new Prefix("c/"); + public static final Prefix PREFIX_INSTRUCTION = new Prefix("i/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); } From 9f3584189922f9be29bcc22f736fab20bf8c38cd Mon Sep 17 00:00:00 2001 From: DarylTew Date: Mon, 17 Sep 2018 21:28:12 +0800 Subject: [PATCH 002/881] Change Person class Change Person class to include [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] fields --- .../seedu/address/model/person/Person.java | 107 ++++++++++++++---- 1 file changed, 82 insertions(+), 25 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 557a7a60cd51..289275d39d6a 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -17,22 +17,37 @@ public class Person { // Identity fields private final Name name; - private final Phone phone; - private final Email email; +// private final Phone phone; +// private final Email email; + private final Type type; + private final Duration duration; + private final Difficulty difficulty; // Data fields - private final Address address; +// private final Address address; + private final Equipment equipment; + private final Muscle muscle; + private final Calories calories; + private final Instruction instruction; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { - requireAllNonNull(name, phone, email, address, tags); + public Person(Name name, Type type, Duration duration, Difficulty difficulty, Equipment equipment, + Muscle muscle, Calories calories, Instruction instruction, Set tags) { + requireAllNonNull(name, type, duration, difficulty, equipment, muscle, calories, instruction, tags); this.name = name; - this.phone = phone; - this.email = email; - this.address = address; +// this.phone = phone; +// this.email = email; +// this.address = address; + this.type = type; + this.duration = duration; + this.difficulty = difficulty; + this.equipment = equipment; + this.muscle = muscle; + this.calories = calories; + this.instruction = instruction; this.tags.addAll(tags); } @@ -40,18 +55,38 @@ public Name getName() { return name; } - public Phone getPhone() { - return phone; + public Type getType() { return type; } + + public Duration getDuration() { + return duration; + } + + public Difficulty getDifficulty() { + return difficulty; + } + + public Equipment getEquipment() { + return equipment; + } + + public Muscle getMuscle() { + return muscle; } - public Email getEmail() { - return email; + public Calories getCalories() { + return calories; } - public Address getAddress() { - return address; + public Instruction getInstruction() { + return instruction; } +// public Phone getPhone() { return phone; } +// +// public Email getEmail() { return email; } +// +// public Address getAddress() { return address; } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -71,7 +106,8 @@ public boolean isSamePerson(Person otherPerson) { return otherPerson != null && otherPerson.getName().equals(getName()) - && (otherPerson.getPhone().equals(getPhone()) || otherPerson.getEmail().equals(getEmail())); + && (otherPerson.getType().equals(getType()) || otherPerson.getDuration().equals(getDuration()) + || otherPerson.getDifficulty().equals(getDifficulty())); } /** @@ -90,28 +126,49 @@ public boolean equals(Object other) { Person otherPerson = (Person) other; return otherPerson.getName().equals(getName()) - && otherPerson.getPhone().equals(getPhone()) - && otherPerson.getEmail().equals(getEmail()) - && otherPerson.getAddress().equals(getAddress()) +// && otherPerson.getPhone().equals(getPhone()) +// && otherPerson.getEmail().equals(getEmail()) +// && otherPerson.getAddress().equals(getAddress()) + && otherPerson.getType().equals(getType()) + && otherPerson.getDuration().equals(getDuration()) + && otherPerson.getDifficulty().equals(getDifficulty()) + && otherPerson.getEquipment().equals(getEquipment()) + && otherPerson.getMuscle().equals(getMuscle()) + && otherPerson.getCalories().equals(getCalories()) + && otherPerson.getInstruction().equals(getInstruction()) && otherPerson.getTags().equals(getTags()); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags); + return Objects.hash(name, type, duration, difficulty, equipment, muscle, calories, instruction, tags); } @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append(getName()) - .append(" Phone: ") - .append(getPhone()) - .append(" Email: ") - .append(getEmail()) - .append(" Address: ") - .append(getAddress()) +// .append(" Phone: ") +// .append(getPhone()) +// .append(" Email: ") +// .append(getEmail()) +// .append(" Address: ") +// .append(getAddress()) + .append(" Type: ") + .append(getType()) + .append(" Duration: ") + .append(getDuration()) + .append(" Difficulty: ") + .append(getDifficulty()) + .append(" Equipment: ") + .append(getEquipment()) + .append(" Muscle: ") + .append(getMuscle()) + .append(" Calories: ") + .append(getCalories()) + .append(" Instruction: ") + .append(getInstruction()) .append(" Tags: "); getTags().forEach(builder::append); return builder.toString(); From 269d4c16277b87920075d0584ab13e3845ac9300 Mon Sep 17 00:00:00 2001 From: DarylTew Date: Mon, 17 Sep 2018 21:45:29 +0800 Subject: [PATCH 003/881] Change EditPersonDescriptor class and Add the classes Add [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] into methods --- .../address/logic/commands/EditCommand.java | 153 ++++++++++++++---- .../seedu/address/model/person/Calories.java | 57 +++++++ .../address/model/person/Difficulty.java | 59 +++++++ .../seedu/address/model/person/Duration.java | 59 +++++++ .../seedu/address/model/person/Equipment.java | 59 +++++++ .../address/model/person/Instruction.java | 57 +++++++ .../seedu/address/model/person/Muscle.java | 59 +++++++ .../java/seedu/address/model/person/Type.java | 59 +++++++ 8 files changed, 532 insertions(+), 30 deletions(-) create mode 100644 src/main/java/seedu/address/model/person/Calories.java create mode 100644 src/main/java/seedu/address/model/person/Difficulty.java create mode 100644 src/main/java/seedu/address/model/person/Duration.java create mode 100644 src/main/java/seedu/address/model/person/Equipment.java create mode 100644 src/main/java/seedu/address/model/person/Instruction.java create mode 100644 src/main/java/seedu/address/model/person/Muscle.java create mode 100644 src/main/java/seedu/address/model/person/Type.java diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 73b19a8c397c..0c139a0649a0 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -27,11 +27,18 @@ import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.Name; +//import seedu.address.model.person.Address; +//import seedu.address.model.person.Email; +//import seedu.address.model.person.Phone; +import seedu.address.model.person.Type; +import seedu.address.model.person.Duration; +import seedu.address.model.person.Difficulty; +import seedu.address.model.person.Equipment; +import seedu.address.model.person.Muscle; +import seedu.address.model.person.Calories; +import seedu.address.model.person.Instruction; import seedu.address.model.tag.Tag; /** @@ -110,12 +117,20 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript assert personToEdit != null; Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); - Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); - Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); - Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); +// Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); +// Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); +// Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); + Type updatedType = editPersonDescriptor.getType().orElse(personToEdit.getType()); + Duration updatedDuration = editPersonDescriptor.getDuration().orElse(personToEdit.getDuration()); + Difficulty updatedDifficulty = editPersonDescriptor.getDifficulty().orElse(personToEdit.getDifficulty()); + Equipment updatedEquipment = editPersonDescriptor.getEquipment().orElse(personToEdit.getEquipment()); + Muscle updatedMuscle = editPersonDescriptor.getMuscle().orElse(personToEdit.getMuscle()); + Calories updatedCalories = editPersonDescriptor.getCalories().orElse(personToEdit.getCalories()); + Instruction updatedInstruction = editPersonDescriptor.getInstruction().orElse(personToEdit.getInstruction()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Person(updatedName, updatedType, updatedDuration, updatedDifficulty, updatedEquipment, + updatedMuscle, updatedCalories, updatedInstruction, updatedTags); } @Override @@ -142,9 +157,16 @@ public boolean equals(Object other) { */ public static class EditPersonDescriptor { private Name name; - private Phone phone; - private Email email; - private Address address; +// private Phone phone; +// private Email email; +// private Address address; + private Type type; + private Duration duration; + private Difficulty difficulty; + private Equipment equipment; + private Muscle muscle; + private Calories calories; + private Instruction instruction; private Set tags; public EditPersonDescriptor() {} @@ -155,9 +177,16 @@ public EditPersonDescriptor() {} */ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setName(toCopy.name); - setPhone(toCopy.phone); - setEmail(toCopy.email); - setAddress(toCopy.address); +// setPhone(toCopy.phone); +// setEmail(toCopy.email); +// setAddress(toCopy.address); + setType(toCopy.type); + setDuration(toCopy.duration); + setDifficulty(toCopy.difficulty); + setEquipment(toCopy.equipment); + setMuscle(toCopy.muscle); + setCalories(toCopy.calories); + setInstruction(toCopy.instruction); setTags(toCopy.tags); } @@ -165,7 +194,8 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); + return CollectionUtil.isAnyNonNull(name, type, duration, difficulty, equipment, muscle, calories, + instruction, tags); } public void setName(Name name) { @@ -176,30 +206,86 @@ public Optional getName() { return Optional.ofNullable(name); } - public void setPhone(Phone phone) { - this.phone = phone; + public void setType(Type type) { + this.type = type; + } + + public Optional getType() { + return Optional.ofNullable(type); + } + + public void setDuration(Duration duration) { + this.duration = duration; + } + + public Optional getDuration() { + return Optional.ofNullable(duration); + } + + public void setDifficulty(Difficulty difficulty) { + this.difficulty = difficulty; } - public Optional getPhone() { - return Optional.ofNullable(phone); + public Optional getDifficulty() { + return Optional.ofNullable(difficulty); } - public void setEmail(Email email) { - this.email = email; + public void setEquipment(Equipment equipment) { + this.equipment = equipment; } - public Optional getEmail() { - return Optional.ofNullable(email); + public Optional getEquipment() { + return Optional.ofNullable(equipment); } - public void setAddress(Address address) { - this.address = address; + public void setMuscle(Muscle muscle) { + this.muscle = muscle; } - public Optional
getAddress() { - return Optional.ofNullable(address); + public Optional getMuscle() { + return Optional.ofNullable(muscle); } + public void setCalories(Calories calories) { + this.calories = calories; + } + + public Optional getCalories() { + return Optional.ofNullable(calories); + } + + public void setInstruction(Instruction instruction) { + this.instruction = instruction; + } + + public Optional getInstruction() { + return Optional.ofNullable(instruction); + } + +// public void setPhone(Phone phone) { +// this.phone = phone; +// } +// +// public Optional getPhone() { +// return Optional.ofNullable(phone); +// } +// +// public void setEmail(Email email) { +// this.email = email; +// } +// +// public Optional getEmail() { +// return Optional.ofNullable(email); +// } +// +// public void setAddress(Address address) { +// this.address = address; +// } +// +// public Optional
getAddress() { +// return Optional.ofNullable(address); +// } + /** * Sets {@code tags} to this object's {@code tags}. * A defensive copy of {@code tags} is used internally. @@ -233,9 +319,16 @@ public boolean equals(Object other) { EditPersonDescriptor e = (EditPersonDescriptor) other; return getName().equals(e.getName()) - && getPhone().equals(e.getPhone()) - && getEmail().equals(e.getEmail()) - && getAddress().equals(e.getAddress()) +// && getPhone().equals(e.getPhone()) +// && getEmail().equals(e.getEmail()) +// && getAddress().equals(e.getAddress()) + && getType().equals(e.getType()) + && getDuration().equals(e.getDuration()) + && getDifficulty().equals(e.getDifficulty()) + && getEquipment().equals(e.getEquipment()) + && getMuscle().equals(e.getMuscle()) + && getCalories().equals(e.getCalories()) + && getInstruction().equals(e.getInstruction()) && getTags().equals(e.getTags()); } } diff --git a/src/main/java/seedu/address/model/person/Calories.java b/src/main/java/seedu/address/model/person/Calories.java new file mode 100644 index 000000000000..5c3e75203d96 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Calories.java @@ -0,0 +1,57 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Calories in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidCalories(String)} + */ +public class Calories { + + public static final String MESSAGE_CALORIES_CONSTRAINTS = + "Calories should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String CALORIES_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullCalories; + + /** + * Constructs a {@code Calories}. + * + * @param calories A valid calories. + */ + public Calories(String calories) { + requireNonNull(calories); + checkArgument(isValidCalories(calories), MESSAGE_CALORIES_CONSTRAINTS); + fullCalories = calories; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidCalories(String test) { return test.matches(CALORIES_VALIDATION_REGEX); } + + + @Override + public String toString() { + return fullCalories; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Calories // instanceof handles nulls + && fullCalories.equals(((Calories) other).fullCalories)); // state check + } + + @Override + public int hashCode() { + return fullCalories.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Difficulty.java b/src/main/java/seedu/address/model/person/Difficulty.java new file mode 100644 index 000000000000..cdabf7911346 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Difficulty.java @@ -0,0 +1,59 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Difficulty in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidDifficulty(String)} + */ +public class Difficulty { + + public static final String MESSAGE_DIFFICULTY_CONSTRAINTS = + "Difficulty should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String DIFFICULTY_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullDifficulty; + + /** + * Constructs a {@code Difficulty}. + * + * @param difficulty A valid difficulty. + */ + public Difficulty(String difficulty) { + requireNonNull(difficulty); + checkArgument(isValidDifficulty(difficulty), MESSAGE_DIFFICULTY_CONSTRAINTS); + fullDifficulty = difficulty; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidDifficulty(String test) { + return test.matches(DIFFICULTY_VALIDATION_REGEX); + } + + + @Override + public String toString() { + return fullDifficulty; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Difficulty // instanceof handles nulls + && fullDifficulty.equals(((Difficulty) other).fullDifficulty)); // state check + } + + @Override + public int hashCode() { + return fullDifficulty.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Duration.java b/src/main/java/seedu/address/model/person/Duration.java new file mode 100644 index 000000000000..48717a6dcf21 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Duration.java @@ -0,0 +1,59 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Duration in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidDuration(String)} + */ +public class Duration { + + public static final String MESSAGE_DURATION_CONSTRAINTS = + "Duration should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String DURATION_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullDuration; + + /** + * Constructs a {@code Duration}. + * + * @param duration A valid duration. + */ + public Duration(String duration) { + requireNonNull(duration); + checkArgument(isValidDuration(duration), MESSAGE_DURATION_CONSTRAINTS); + fullDuration = duration; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidDuration(String test) { + return test.matches(DURATION_VALIDATION_REGEX); + } + + + @Override + public String toString() { + return fullDuration; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Duration // instanceof handles nulls + && fullDuration.equals(((Duration) other).fullDuration)); // state check + } + + @Override + public int hashCode() { + return fullDuration.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Equipment.java b/src/main/java/seedu/address/model/person/Equipment.java new file mode 100644 index 000000000000..712784b08136 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Equipment.java @@ -0,0 +1,59 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Equipment in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidEquipment(String)} + */ +public class Equipment { + + public static final String MESSAGE_EQUIPMENT_CONSTRAINTS = + "Equipment should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String EQUIPMENT_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullEquipment; + + /** + * Constructs a {@code Equipment}. + * + * @param equipment A valid equipment. + */ + public Equipment(String equipment) { + requireNonNull(equipment); + checkArgument(isValidEquipment(equipment), MESSAGE_EQUIPMENT_CONSTRAINTS); + fullEquipment = equipment; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidEquipment(String test) { + return test.matches(EQUIPMENT_VALIDATION_REGEX); + } + + + @Override + public String toString() { + return fullEquipment; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Equipment // instanceof handles nulls + && fullEquipment.equals(((Equipment) other).fullEquipment)); // state check + } + + @Override + public int hashCode() { + return fullEquipment.hashCode(); + } + +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/person/Instruction.java b/src/main/java/seedu/address/model/person/Instruction.java new file mode 100644 index 000000000000..88e93ae51ade --- /dev/null +++ b/src/main/java/seedu/address/model/person/Instruction.java @@ -0,0 +1,57 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Instruction in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidInstruction(String)} + */ +public class Instruction { + + public static final String MESSAGE_INSTRUCTION_CONSTRAINTS = + "Instruction should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String INSTRUCTION_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullInstruction; + + /** + * Constructs a {@code Instruction}. + * + * @param instruction A valid instruction. + */ + public Instruction(String instruction) { + requireNonNull(instruction); + checkArgument(isValidInstruction(instruction), MESSAGE_INSTRUCTION_CONSTRAINTS); + fullInstruction = instruction; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidInstruction(String test) { return test.matches(INSTRUCTION_VALIDATION_REGEX); } + + + @Override + public String toString() { + return fullInstruction; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Instruction // instanceof handles nulls + && fullInstruction.equals(((Instruction) other).fullInstruction)); // state check + } + + @Override + public int hashCode() { + return fullInstruction.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Muscle.java b/src/main/java/seedu/address/model/person/Muscle.java new file mode 100644 index 000000000000..67afe2b50a64 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Muscle.java @@ -0,0 +1,59 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Muscle in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidMuscle(String)} + */ +public class Muscle { + + public static final String MESSAGE_MUSCLE_CONSTRAINTS = + "Muscle should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String MUSCLE_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullMuscle; + + /** + * Constructs a {@code Muscle}. + * + * @param muscle A valid muscle. + */ + public Muscle(String muscle) { + requireNonNull(muscle); + checkArgument(isValidMuscle(muscle), MESSAGE_MUSCLE_CONSTRAINTS); + fullMuscle = muscle; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidMuscle(String test) { + return test.matches(MUSCLE_VALIDATION_REGEX); + } + + + @Override + public String toString() { + return fullMuscle; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Muscle // instanceof handles nulls + && fullMuscle.equals(((Muscle) other).fullMuscle)); // state check + } + + @Override + public int hashCode() { + return fullMuscle.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Type.java b/src/main/java/seedu/address/model/person/Type.java new file mode 100644 index 000000000000..60644b0c5167 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Type.java @@ -0,0 +1,59 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Workout's Type in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidType(String)} + */ +public class Type { + + public static final String MESSAGE_TYPE_CONSTRAINTS = + "Types should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the address must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String TYPE_VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String fullType; + + /** + * Constructs a {@code Type}. + * + * @param type A valid type. + */ + public Type(String type) { + requireNonNull(type); + checkArgument(isValidType(type), MESSAGE_TYPE_CONSTRAINTS); + fullType = type; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidType(String test) { + return test.matches(TYPE_VALIDATION_REGEX); + } + + + @Override + public String toString() { + return fullType; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Type // instanceof handles nulls + && fullType.equals(((Type) other).fullType)); // state check + } + + @Override + public int hashCode() { + return fullType.hashCode(); + } + +} From 66ba9d00eae47fdca82278756bb8241f669dcb5f Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 17 Sep 2018 21:52:30 +0800 Subject: [PATCH 004/881] update UserGuide and HelpWindow --- docs/UserGuide.adoc | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 7e0070e12f49..46cbf197c525 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -1,4 +1,4 @@ -= AddressBook Level 4 - User Guide += WorkoutBook - User Guide :site-section: UserGuide :toc: :toc-title: @@ -12,30 +12,23 @@ ifdef::env-github[] :tip-caption: :bulb: :note-caption: :information_source: endif::[] -:repoURL: https://github.com/se-edu/addressbook-level4 +:repoURL: https://github.com/CS2113-AY1819S1-T13-5/addressbook-level4 -By: `Team SE-EDU` Since: `Jun 2016` Licence: `MIT` +By: `Team T13-5` Since: `Sept 2018` #Licence: `MIT` == Introduction -AddressBook Level 4 (AB4) is for those who *prefer to use a desktop app for managing contacts*. More importantly, AB4 is *optimized for those who prefer to work with a Command Line Interface* (CLI) while still having the benefits of a Graphical User Interface (GUI). If you can type fast, AB4 can get your contact management tasks done faster than traditional GUI apps. Interested? Jump to the <> to get started. Enjoy! +WorkoutBook is for those who *prefer to use a desktop app for managing workouts*. More importantly, WorkoutBook is *optimized for those who prefer to work with a Command Line Interface* (CLI) while still having the benefits of a Graphical User Interface (GUI). == Quick Start -. Ensure you have Java version `9` or later installed in your Computer. -. Download the latest `addressbook.jar` link:{repoURL}/releases[here]. -. Copy the file to the folder you want to use as the home folder for your Address Book. -. Double-click the file to start the app. The GUI should appear in a few seconds. -+ -image::Ui.png[width="790"] -+ . Type the command in the command box and press kbd:[Enter] to execute it. + e.g. typing *`help`* and pressing kbd:[Enter] will open the help window. . Some example commands you can try: -* *`list`* : lists all contacts -* **`add`**`n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01` : adds a contact named `John Doe` to the Address Book. -* **`delete`**`3` : deletes the 3rd contact shown in the current list +* *`list`* : lists all workouts +* **`add`**`add name/commando workout type/strength duration/20m difficulty/advanced equipment/dumbbell, bench muscle/bicep, tricep calories/150 instruction/set 1: bicep curl reps: 4-6 set 2: tricep extension reps: 4-6 tag/heavy` : adds a Workout named `commando` to the WorkoutBook. +* **`delete`**`3` : deletes the 3rd workout shown in the current list * *`exit`* : exits the app . Refer to <> for details of each command. From 272bddc31f45246a2644e83d5101fc12d5fb62a1 Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 17 Sep 2018 22:12:35 +0800 Subject: [PATCH 005/881] update UserGuide and HelpWindow --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 823d175eb670..89b5a23cd86d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ build/ .settings/ .idea/ lib/* -*.iml *.log *.log.* *.csv From 6c87e805fbe2ba7fe05c2d39f24f9e504da44d7b Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 17 Sep 2018 22:14:51 +0800 Subject: [PATCH 006/881] update UserGuide and HelpWindow --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 89b5a23cd86d..90391e84defe 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ lib/* *.log *.log.* *.csv +*.iml config.json src/test/data/sandbox/ preferences.json From 5728a551f399d726b1a27f799baab0320078819f Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 17 Sep 2018 22:32:48 +0800 Subject: [PATCH 007/881] update UserGuide and HelpWindow --- docs/UserGuide.adoc | 112 +++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 46cbf197c525..e1ba72928e16 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -39,82 +39,81 @@ e.g. typing *`help`* and pressing kbd:[Enter] will open the help window. ==== *Command Format* -* Words in `UPPER_CASE` are the parameters to be supplied by the user e.g. in `add n/NAME`, `NAME` is a parameter which can be used as `add n/John Doe`. -* Items in square brackets are optional e.g `n/NAME [t/TAG]` can be used as `n/John Doe t/friend` or as `n/John Doe`. -* Items with `…`​ after them can be used multiple times including zero times e.g. `[t/TAG]...` can be used as `{nbsp}` (i.e. 0 times), `t/friend`, `t/friend t/family` etc. -* Parameters can be in any order e.g. if the command specifies `n/NAME p/PHONE_NUMBER`, `p/PHONE_NUMBER n/NAME` is also acceptable. +* Words in `UPPER_CASE` are the parameters to be supplied by the user e.g. in `add name/NAME`, `NAME` is a parameter which can be used as `add name/commando workout`. +* Items in square brackets are optional e.g `name/NAME [tag/TAG]` can be used as `name/commando workout tag/strength` or as `name/commando workout`. +* Items with `…`​ after them can be used multiple times including zero times e.g. `[tag/TAG]...` can be used as `{nbsp}` (i.e. 0 times), `tag/strength`, `tag/strength tag/fast-paced` etc. +* Parameters can be in any order e.g. if the command specifies `name/NAME type/TYPE`, `type/TYPE name/NAME` is also acceptable. ==== === Viewing help : `help` Format: `help` -=== Adding a person: `add` +=== Adding a workout: `add` -Adds a person to the address book + -Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]...` +Adds a workout to the workout book + +Format: `add name/NAME [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] [tag/TAG]…​` [TIP] -A person can have any number of tags (including 0) +A workout can have any number of tags (including 0) Examples: -* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01` -* `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal` +* `add name/commando workout type/strength, cardio duration/20m difficulty/advanced equipment/dumbbell, bench muscle/bicep, tricep calories/150 instruction/set 1: bicep curl reps: 4-6 set 2: tricep extension reps: 4-6 tag/heavy` -=== Listing all persons : `list` +=== Listing all workouts : `list` -Shows a list of all persons in the address book. + +Shows a list of all workouts in the workout book. + Format: `list` -=== Editing a person : `edit` +=== Editing a workout : `edit` -Edits an existing person in the address book. + -Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]...` +Edits an existing workout in the workout book. + +Format: `edit INDEX name/NAME [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] [tag/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 workout at the specified `INDEX`. The index refers to the index number shown in the displayed workout 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. +* When editing tags, the existing tags of the workout will be removed i.e adding of tags is not cumulative. +* You can remove all the workout's tags by typing `tag/` without specifying any tags after it. **** Examples: -* `edit 1 p/91234567 e/johndoe@example.com` + -Edits the phone number and email address of the 1st person to be `91234567` and `johndoe@example.com` respectively. -* `edit 2 n/Betsy Crower t/` + -Edits the name of the 2nd person to be `Betsy Crower` and clears all existing tags. +* `edit 1 type/strength duration/20m` + +Edits the type and duration of the 1st workout to be `strength` and `20m` respectively. +* `edit 2 name/Arnold's workout tag/` + +Edits the name of the 2nd workout to be `Arnold's workout` and clears all existing tags. -=== Locating persons by name: `find` +=== Locating workouts by name: `find` -Finds persons whose names contain any of the given keywords. + +Finds workouts whose names contain any of the given keywords. + Format: `find KEYWORD [MORE_KEYWORDS]` **** -* The search is case insensitive. e.g `hans` will match `Hans` -* The order of the keywords does not matter. e.g. `Hans Bo` will match `Bo Hans` +* The search is case insensitive. e.g `Commando workout` will match `commando workout` +* The order of the keywords does not matter. e.g. `workout commando` will match `commando workout` * Only the name is searched. -* Only full words will be matched e.g. `Han` will not match `Hans` -* Persons matching at least one keyword will be returned (i.e. `OR` search). e.g. `Hans Bo` will return `Hans Gruber`, `Bo Yang` +* Only full words will be matched e.g. `command workout` will not match `commando workout` +* workouts matching at least one keyword will be returned (i.e. `OR` search). e.g. `commando arnold's` will return `commando workout`, `Arnold's workout` **** Examples: -* `find John` + -Returns `john` and `John Doe` -* `find Betsy Tim John` + -Returns any person having names `Betsy`, `Tim`, or `John` +* `find commando` + +Returns `command workout` +* `find commando arnold's` + +Returns any workout having names `commando` or `arnold's` -=== Deleting a person : `delete` +=== Deleting a workout : `delete` -Deletes the specified person from the address book. + +Deletes the specified workout from the workout book. + Format: `delete INDEX` **** -* Deletes the person at the specified `INDEX`. -* The index refers to the index number shown in the displayed person list. +* Deletes the workout at the specified `INDEX`. +* The index refers to the index number shown in the displayed workout list. * The index *must be a positive integer* 1, 2, 3, ... **** @@ -122,19 +121,19 @@ Examples: * `list` + `delete 2` + -Deletes the 2nd person in the address book. -* `find Betsy` + +Deletes the 2nd workout in the workout book. +* `find commando` + `delete 1` + -Deletes the 1st person in the results of the `find` command. +Deletes the 1st workout in the results of the `find` command. -=== Selecting a person : `select` +=== Selecting a workout : `select` -Selects the person identified by the index number used in the displayed person list. + +Selects the workout identified by the index number used in the displayed workout list. + Format: `select INDEX` **** -* Selects the person and loads the Google search page the person at the specified `INDEX`. -* The index refers to the index number shown in the displayed person list. +* Selects the workout and loads the Google search page the workout at the specified `INDEX`. +* The index refers to the index number shown in the displayed workout list. * The index *must be a positive integer* `1, 2, 3, ...` **** @@ -142,10 +141,10 @@ Examples: * `list` + `select 2` + -Selects the 2nd person in the address book. -* `find Betsy` + +Selects the 2nd workout in the workout book. +* `find commando` + `select 1` + -Selects the 1st person in the results of the `find` command. +Selects the 1st workout in the results of the `find` command. === Listing entered commands : `history` @@ -160,12 +159,12 @@ Pressing the kbd:[↑] and kbd:[↓] arrows will display the previous and // tag::undoredo[] === Undoing previous command : `undo` -Restores the address book to the state before the previous _undoable_ command was executed. + +Restores the workout book to the state before the previous _undoable_ command was executed. + Format: `undo` [NOTE] ==== -Undoable commands: those commands that modify the address book's content (`add`, `delete`, `edit` and `clear`). +Undoable commands: those commands that modify the workout book's content (`add`, `delete`, `edit` and `clear`). ==== Examples: @@ -209,7 +208,7 @@ The `redo` command fails as there are no `undo` commands executed previously. === Clearing all entries : `clear` -Clears all entries from the address book. + +Clears all entries from the workout book. + Format: `clear` === Exiting the program : `exit` @@ -219,7 +218,7 @@ Format: `exit` === Saving the data -Address book data are saved in the hard disk automatically after any command that changes the data. + +workout book data are saved in the hard disk automatically after any command that changes the data. + There is no need to save manually. // tag::dataencryption[] @@ -230,20 +229,17 @@ _{explain how the user can enable/disable data encryption}_ == FAQ -*Q*: How do I transfer my data to another Computer? + -*A*: Install the app in the other computer and overwrite the empty data file it creates with the file that contains the data of your previous Address Book folder. - == Command Summary -* *Add* `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [t/TAG]...` + -e.g. `add n/James Ho p/22224444 e/jamesho@example.com a/123, Clementi Rd, 1234665 t/friend t/colleague` +* *Add* `add name/NAME [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] [tag/TAG]...` + +e.g. `add name/commando workout type/strength, cardio duration/20m difficulty/advanced equipment/dumbbell, bench muscle/bicep, tricep calories/150 instruction/set 1: bicep curl reps: 4-6 set 2: tricep extension reps: 4-6 tag/heavy` * *Clear* : `clear` * *Delete* : `delete INDEX` + e.g. `delete 3` -* *Edit* : `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]...` + -e.g. `edit 2 n/James Lee e/jameslee@example.com` +* *Edit* : `dit INDEX [name/NAME] [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] [tag/TAG]…​` + +e.g. `edit 1 type/light duration/25m` * *Find* : `find KEYWORD [MORE_KEYWORDS]` + -e.g. `find James Jake` +e.g. `find bench` * *List* : `list` * *Help* : `help` * *Select* : `select INDEX` + From b71b8aa38538aa0c0a96d987ce2304dfa30f76db Mon Sep 17 00:00:00 2001 From: DarylTew Date: Mon, 17 Sep 2018 22:52:22 +0800 Subject: [PATCH 008/881] Change EditCommandParser and ParserUtil classes Add [type/TYPE] [duration/DURATION] [difficulty/DIFFICULTY] [equipment/EQUIPMENT] [muscle/MUSCLE] [calories/CALORIES] [instruction/INSTRUCTION] into methods --- .../logic/parser/EditCommandParser.java | 49 ++++-- .../address/logic/parser/ParserUtil.java | 166 +++++++++++++++--- 2 files changed, 178 insertions(+), 37 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 845644b7dea1..956db28751ce 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -2,10 +2,17 @@ import static java.util.Objects.requireNonNull; 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_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +//import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +//import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +//import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DURATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EQUIPMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INSTRUCTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.Collection; @@ -32,7 +39,8 @@ public class EditCommandParser implements Parser { public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TYPE, PREFIX_DURATION, PREFIX_DIFFICULTY, + PREFIX_EQUIPMENT, PREFIX_MUSCLE, PREFIX_CALORIES, PREFIX_INSTRUCTION, PREFIX_TAG); Index index; @@ -46,14 +54,35 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_NAME).isPresent()) { editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get())); } - if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { - editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get())); +// if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { +// editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get())); +// } +// if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { +// editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); +// } +// if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { +// editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); +// } + if (argMultimap.getValue(PREFIX_TYPE).isPresent()) { + editPersonDescriptor.setType(ParserUtil.parseType(argMultimap.getValue(PREFIX_TYPE).get())); } - if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { - editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); + if (argMultimap.getValue(PREFIX_DURATION).isPresent()) { + editPersonDescriptor.setDuration(ParserUtil.parseDuration(argMultimap.getValue(PREFIX_DURATION).get())); } - if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { - editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); + if (argMultimap.getValue(PREFIX_DIFFICULTY).isPresent()) { + editPersonDescriptor.setDifficulty(ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get())); + } + if (argMultimap.getValue(PREFIX_EQUIPMENT).isPresent()) { + editPersonDescriptor.setEquipment(ParserUtil.parseEquipment(argMultimap.getValue(PREFIX_EQUIPMENT).get())); + } + if (argMultimap.getValue(PREFIX_MUSCLE).isPresent()) { + editPersonDescriptor.setMuscle(ParserUtil.parseMuscle(argMultimap.getValue(PREFIX_MUSCLE).get())); + } + if (argMultimap.getValue(PREFIX_CALORIES).isPresent()) { + editPersonDescriptor.setCalories(ParserUtil.parseCalories(argMultimap.getValue(PREFIX_CALORIES).get())); + } + if (argMultimap.getValue(PREFIX_INSTRUCTION).isPresent()) { + editPersonDescriptor.setInstruction(ParserUtil.parseInstruction(argMultimap.getValue(PREFIX_INSTRUCTION).get())); } parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 76daf40807e2..d9e4848072fb 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,10 +9,17 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Phone; +//import seedu.address.model.person.Address; +//import seedu.address.model.person.Email; +//import seedu.address.model.person.Phone; +import seedu.address.model.person.Type; +import seedu.address.model.person.Duration; +import seedu.address.model.person.Difficulty; +import seedu.address.model.person.Equipment; +import seedu.address.model.person.Muscle; +import seedu.address.model.person.Calories; +import seedu.address.model.person.Instruction; import seedu.address.model.tag.Tag; /** @@ -50,49 +57,154 @@ public static Name parseName(String name) throws ParseException { return new Name(trimmedName); } +// /** +// * Parses a {@code String phone} into a {@code Phone}. +// * Leading and trailing whitespaces will be trimmed. +// * +// * @throws ParseException if the given {@code phone} is invalid. +// */ +// public static Phone parsePhone(String phone) throws ParseException { +// requireNonNull(phone); +// String trimmedPhone = phone.trim(); +// if (!Phone.isValidPhone(trimmedPhone)) { +// throw new ParseException(Phone.MESSAGE_PHONE_CONSTRAINTS); +// } +// return new Phone(trimmedPhone); +// } +// +// /** +// * Parses a {@code String address} into an {@code Address}. +// * Leading and trailing whitespaces will be trimmed. +// * +// * @throws ParseException if the given {@code address} is invalid. +// */ +// public static Address parseAddress(String address) throws ParseException { +// requireNonNull(address); +// String trimmedAddress = address.trim(); +// if (!Address.isValidAddress(trimmedAddress)) { +// throw new ParseException(Address.MESSAGE_ADDRESS_CONSTRAINTS); +// } +// return new Address(trimmedAddress); +// } +// +// /** +// * Parses a {@code String email} into an {@code Email}. +// * Leading and trailing whitespaces will be trimmed. +// * +// * @throws ParseException if the given {@code email} is invalid. +// */ +// public static Email parseEmail(String email) throws ParseException { +// requireNonNull(email); +// String trimmedEmail = email.trim(); +// if (!Email.isValidEmail(trimmedEmail)) { +// throw new ParseException(Email.MESSAGE_EMAIL_CONSTRAINTS); +// } +// return new Email(trimmedEmail); +// } + + /** + * Parses a {@code String type} into a {@code type}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code type} is invalid. + */ + public static Type parseType(String type) throws ParseException { + requireNonNull(type); + String trimmedType = type.trim(); + if (!Type.isValidType(trimmedType)) { + throw new ParseException(Type.MESSAGE_TYPE_CONSTRAINTS); + } + return new Type(trimmedType); + } + + /** + * Parses a {@code String duration} into a {@code duration}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code duration} is invalid. + */ + public static Duration parseDuration(String duration) throws ParseException { + requireNonNull(duration); + String trimmedDuration = duration.trim(); + if (!Duration.isValidDuration(trimmedDuration)) { + throw new ParseException(Duration.MESSAGE_DURATION_CONSTRAINTS); + } + return new Duration(trimmedDuration); + } + + /** + * Parses a {@code String difficulty} into a {@code difficulty}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code difficulty} is invalid. + */ + public static Difficulty parseDifficulty(String difficulty) throws ParseException { + requireNonNull(difficulty); + String trimmedDifficulty = difficulty.trim(); + if (!Difficulty.isValidDifficulty(trimmedDifficulty)) { + throw new ParseException(Difficulty.MESSAGE_DIFFICULTY_CONSTRAINTS); + } + return new Difficulty(trimmedDifficulty); + } + + /** + * Parses a {@code String equipment} into a {@code equipment}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code equipment} is invalid. + */ + public static Equipment parseEquipment(String equipment) throws ParseException { + requireNonNull(equipment); + String trimmedEquipment = equipment.trim(); + if (!Equipment.isValidEquipment(trimmedEquipment)) { + throw new ParseException(Equipment.MESSAGE_EQUIPMENT_CONSTRAINTS); + } + return new Equipment(trimmedEquipment); + } + /** - * Parses a {@code String phone} into a {@code Phone}. + * Parses a {@code String muscle} into a {@code muscle}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code phone} is invalid. + * @throws ParseException if the given {@code muscle} is invalid. */ - public static Phone parsePhone(String phone) throws ParseException { - requireNonNull(phone); - String trimmedPhone = phone.trim(); - if (!Phone.isValidPhone(trimmedPhone)) { - throw new ParseException(Phone.MESSAGE_PHONE_CONSTRAINTS); + public static Muscle parseMuscle(String muscle) throws ParseException { + requireNonNull(muscle); + String trimmedMuscle = muscle.trim(); + if (!Muscle.isValidMuscle(trimmedMuscle)) { + throw new ParseException(Muscle.MESSAGE_MUSCLE_CONSTRAINTS); } - return new Phone(trimmedPhone); + return new Muscle(trimmedMuscle); } /** - * Parses a {@code String address} into an {@code Address}. + * Parses a {@code String calories} into a {@code calories}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code address} is invalid. + * @throws ParseException if the given {@code calories} is invalid. */ - public static Address parseAddress(String address) throws ParseException { - requireNonNull(address); - String trimmedAddress = address.trim(); - if (!Address.isValidAddress(trimmedAddress)) { - throw new ParseException(Address.MESSAGE_ADDRESS_CONSTRAINTS); + public static Calories parseCalories(String calories) throws ParseException { + requireNonNull(calories); + String trimmedCalories = calories.trim(); + if (!Calories.isValidCalories(trimmedCalories)) { + throw new ParseException(Calories.MESSAGE_CALORIES_CONSTRAINTS); } - return new Address(trimmedAddress); + return new Calories(trimmedCalories); } /** - * Parses a {@code String email} into an {@code Email}. + * Parses a {@code String instruction} into a {@code instruction}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code email} is invalid. + * @throws ParseException if the given {@code instruction} is invalid. */ - public static Email parseEmail(String email) throws ParseException { - requireNonNull(email); - String trimmedEmail = email.trim(); - if (!Email.isValidEmail(trimmedEmail)) { - throw new ParseException(Email.MESSAGE_EMAIL_CONSTRAINTS); + public static Instruction parseInstruction(String instruction) throws ParseException { + requireNonNull(instruction); + String trimmedInstruction = instruction.trim(); + if (!Instruction.isValidInstruction(trimmedInstruction)) { + throw new ParseException(Instruction.MESSAGE_INSTRUCTION_CONSTRAINTS); } - return new Email(trimmedEmail); + return new Instruction(trimmedInstruction); } /** From b75fd96b0f7229d20110768fc62ed0baf0410b5d Mon Sep 17 00:00:00 2001 From: shouteck Date: Wed, 19 Sep 2018 17:01:09 +0800 Subject: [PATCH 009/881] Changed MESSAGE_USAGE in AddCommand and added our new prefixes to CliSyntax. --- .../address/logic/commands/AddCommand.java | 39 ++++++++++++------- .../seedu/address/logic/parser/CliSyntax.java | 21 +++++----- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index d88e831ff1ce..a6832a285d17 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -1,10 +1,15 @@ package seedu.address.logic.commands; 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_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DURATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EQUIPMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INSTRUCTION; +// import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import seedu.address.logic.CommandHistory; @@ -19,20 +24,28 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a workout to the workout book. " + "Parameters: " + PREFIX_NAME + "NAME " - + PREFIX_PHONE + "PHONE " - + PREFIX_EMAIL + "EMAIL " - + PREFIX_ADDRESS + "ADDRESS " + + PREFIX_TYPE + "TYPE " + + PREFIX_DURATION + "DURATION " + + PREFIX_DIFFICULTY + "DIFFICULTY " + + PREFIX_EQUIPMENT + "EQUIPMENT " + + PREFIX_MUSCLE + "MUSCLE " + + PREFIX_CALORIES + "CALORIES " + + PREFIX_INSTRUCTION + "INSTRUCTION " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " - + PREFIX_NAME + "John Doe " - + PREFIX_PHONE + "98765432 " - + PREFIX_EMAIL + "johnd@example.com " - + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " - + PREFIX_TAG + "friends " - + PREFIX_TAG + "owesMoney"; + + PREFIX_NAME + "john doe's workout " + + PREFIX_TYPE + "strength " + + PREFIX_DURATION + "20m " + + PREFIX_DIFFICULTY + "beginner " + + PREFIX_EQUIPMENT + "dumbbell " + + PREFIX_MUSCLE + "bicep " + + PREFIX_CALORIES + "150 " + + PREFIX_INSTRUCTION + "set1: bicep curl reps: 4-6 " + + PREFIX_TAG + "heavy " + + PREFIX_TAG + "current favourite "; public static final String MESSAGE_SUCCESS = "New person added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 445b743e1f0a..efb1622c98d8 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -6,17 +6,14 @@ public class CliSyntax { /* Prefix definitions */ - public static final Prefix PREFIX_NAME = new Prefix("n/"); -// public static final Prefix PREFIX_PHONE = new Prefix("p/"); -// public static final Prefix PREFIX_EMAIL = new Prefix("e/"); -// public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); - public static final Prefix PREFIX_TYPE = new Prefix("t/"); - public static final Prefix PREFIX_DURATION = new Prefix("du/"); - public static final Prefix PREFIX_DIFFICULTY = new Prefix("di/"); - public static final Prefix PREFIX_EQUIPMENT = new Prefix("e/"); - public static final Prefix PREFIX_MUSCLE = new Prefix("m/"); - public static final Prefix PREFIX_CALORIES = new Prefix("c/"); - public static final Prefix PREFIX_INSTRUCTION = new Prefix("i/"); - public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_NAME = new Prefix("name/"); + public static final Prefix PREFIX_TYPE = new Prefix("type/"); + public static final Prefix PREFIX_DURATION = new Prefix("duration/"); + public static final Prefix PREFIX_DIFFICULTY = new Prefix("difficulty/"); + public static final Prefix PREFIX_EQUIPMENT = new Prefix("equipment/"); + public static final Prefix PREFIX_MUSCLE = new Prefix("muscle/"); + public static final Prefix PREFIX_CALORIES = new Prefix("calories/"); + public static final Prefix PREFIX_INSTRUCTION = new Prefix("instruction/"); + public static final Prefix PREFIX_TAG = new Prefix("tag/"); } From d4d923b59b85d1595ecf06859f1095fe633671ae Mon Sep 17 00:00:00 2001 From: shouteck Date: Wed, 19 Sep 2018 20:29:11 +0800 Subject: [PATCH 010/881] Modified AddCommand to accommodate our new parameters. --- .../address/logic/commands/AddCommand.java | 1 - .../logic/parser/AddCommandParser.java | 37 +++--- .../seedu/address/model/person/Person.java | 2 +- .../address/model/util/SampleDataUtil.java | 12 +- .../address/storage/XmlAdaptedPerson.java | 115 ++++++++++++++++-- .../java/seedu/address/ui/PersonCard.java | 29 ++++- .../guitests/guihandles/PersonCardHandle.java | 67 +++++++++- .../address/commons/util/XmlUtilTest.java | 23 +++- .../logic/commands/CommandTestUtil.java | 60 +++++++-- .../logic/parser/EditCommandParserTest.java | 3 + .../testutil/EditPersonDescriptorBuilder.java | 27 +++- .../seedu/address/testutil/PersonBuilder.java | 23 +++- .../seedu/address/testutil/PersonUtil.java | 29 ++++- .../address/ui/testutil/GuiTestAssert.java | 4 + 14 files changed, 375 insertions(+), 57 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index a6832a285d17..9fbf17fd7947 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -9,7 +9,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_CALORIES; import static seedu.address.logic.parser.CliSyntax.PREFIX_INSTRUCTION; -// import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import seedu.address.logic.CommandHistory; diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 3b8bfa035e83..94180d5eb026 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -1,10 +1,14 @@ package seedu.address.logic.parser; 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_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DURATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EQUIPMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INSTRUCTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.Set; @@ -12,11 +16,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; /** @@ -31,20 +31,29 @@ public class AddCommandParser implements Parser { */ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TYPE, PREFIX_DURATION, PREFIX_DIFFICULTY, + PREFIX_EQUIPMENT, PREFIX_MUSCLE, PREFIX_CALORIES, PREFIX_INSTRUCTION, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_TYPE, PREFIX_DURATION, PREFIX_DIFFICULTY, + PREFIX_EQUIPMENT, PREFIX_MUSCLE, PREFIX_INSTRUCTION) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.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()); + Type type = ParserUtil.parseType(argMultimap.getValue(PREFIX_TYPE).get()); + Duration duration = ParserUtil.parseDuration(argMultimap.getValue(PREFIX_DURATION).get()); + Difficulty difficulty = ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get()); + Equipment equipment = ParserUtil.parseEquipment(argMultimap.getValue(PREFIX_EQUIPMENT).get()); + Muscle muscle = ParserUtil.parseMuscle(argMultimap.getValue(PREFIX_MUSCLE).get()); + Calories calories = ParserUtil.parseCalories(argMultimap.getValue(PREFIX_CALORIES).get()); + Instruction instruction = ParserUtil.parseInstruction(argMultimap.getValue(PREFIX_INSTRUCTION).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()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList); + Person person = new Person(name, type, duration, difficulty, equipment, muscle, calories, instruction, tagList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 289275d39d6a..e2e923c764aa 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -20,11 +20,11 @@ public class Person { // private final Phone phone; // private final Email email; private final Type type; - private final Duration duration; private final Difficulty difficulty; // Data fields // private final Address address; + private final Duration duration; private final Equipment equipment; private final Muscle muscle; private final Calories calories; diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facfa..0a174c84d0e0 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -6,11 +6,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; /** @@ -19,6 +15,11 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[] { + new Person(new Name("alex yeoh's workout"), new Type("strength"), new Duration("20m"), + new Difficulty("beginner"), new Equipment("dumbbell"), new Muscle("tricep"), + new Calories("150"), new Instruction("set1: tricep extension reps: 4-6"), + getTagSet("heavy", "morning")) + /* new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), getTagSet("friends")), @@ -37,6 +38,7 @@ public static Person[] getSamplePersons() { new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), getTagSet("colleagues")) + */ }; } diff --git a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java index c03785e5700f..2a6bbbc2307e 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java @@ -10,11 +10,7 @@ import javax.xml.bind.annotation.XmlElement; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; /** @@ -26,12 +22,28 @@ public class XmlAdaptedPerson { @XmlElement(required = true) private String name; + @XmlElement(required = true) + private String type; + @XmlElement(required = true) + private String duration; + @XmlElement(required = true) + private String difficulty; + @XmlElement(required = true) + private String equipment; + @XmlElement(required = true) + private String muscle; + @XmlElement(required = true) + private String calories; + @XmlElement(required = true) + private String instruction; +/* @XmlElement(required = true) private String phone; @XmlElement(required = true) private String email; @XmlElement(required = true) private String address; +*/ @XmlElement private List tagged = new ArrayList<>(); @@ -45,11 +57,22 @@ public XmlAdaptedPerson() {} /** * Constructs an {@code XmlAdaptedPerson} with the given person details. */ - public XmlAdaptedPerson(String name, String phone, String email, String address, List tagged) { + public XmlAdaptedPerson(String name, String type, String duration, String difficulty, + String equipment, String muscle, String calories, + String instruction, List tagged) { this.name = name; + this.type = type; + this.duration = duration; + this.difficulty = difficulty; + this.equipment = equipment; + this.muscle = muscle; + this.calories = calories; + this.instruction = instruction; + /* this.phone = phone; this.email = email; this.address = address; + */ if (tagged != null) { this.tagged = new ArrayList<>(tagged); } @@ -62,9 +85,18 @@ public XmlAdaptedPerson(String name, String phone, String email, String address, */ public XmlAdaptedPerson(Person source) { name = source.getName().fullName; + type = source.getType().fullType; + duration = source.getDuration().fullDuration; + difficulty = source.getDifficulty().fullDifficulty; + equipment = source.getEquipment().fullEquipment; + muscle = source.getMuscle().fullMuscle; + calories = source.getCalories().fullCalories; + instruction = source.getInstruction().fullInstruction; + /* phone = source.getPhone().value; email = source.getEmail().value; address = source.getAddress().value; + */ tagged = source.getTags().stream() .map(XmlAdaptedTag::new) .collect(Collectors.toList()); @@ -89,6 +121,63 @@ public Person toModelType() throws IllegalValueException { } final Name modelName = new Name(name); + if (type == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Type.class.getSimpleName())); + } + if (!Type.isValidType(type)) { + throw new IllegalValueException(Type.MESSAGE_TYPE_CONSTRAINTS); + } + final Type modelType = new Type(type); + + if (duration == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Duration.class.getSimpleName())); + } + if (!Duration.isValidDuration(duration)) { + throw new IllegalValueException(Duration.MESSAGE_DURATION_CONSTRAINTS); + } + final Duration modelDuration = new Duration(duration); + + if (difficulty == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Difficulty.class.getSimpleName())); + } + if (!Difficulty.isValidDifficulty(difficulty)) { + throw new IllegalValueException(Difficulty.MESSAGE_DIFFICULTY_CONSTRAINTS); + } + final Difficulty modelDifficulty = new Difficulty(difficulty); + + if (equipment == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Equipment.class.getSimpleName())); + } + if (!Equipment.isValidEquipment(equipment)) { + throw new IllegalValueException(Equipment.MESSAGE_EQUIPMENT_CONSTRAINTS); + } + final Equipment modelEquipment = new Equipment(equipment); + + if (muscle == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Muscle.class.getSimpleName())); + } + if (!Muscle.isValidMuscle(muscle)) { + throw new IllegalValueException(Muscle.MESSAGE_MUSCLE_CONSTRAINTS); + } + final Muscle modelMuscle = new Muscle(muscle); + + if (calories == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Calories.class.getSimpleName())); + } + if (!Calories.isValidCalories(calories)) { + throw new IllegalValueException(Calories.MESSAGE_CALORIES_CONSTRAINTS); + } + final Calories modelCalories = new Calories(calories); + + if (instruction == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Instruction.class.getSimpleName())); + } + if (!Instruction.isValidInstruction(instruction)) { + throw new IllegalValueException(Instruction.MESSAGE_INSTRUCTION_CONSTRAINTS); + } + final Instruction modelInstruction = new Instruction(instruction); + + /* if (phone == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); } @@ -112,9 +201,10 @@ public Person toModelType() throws IllegalValueException { throw new IllegalValueException(Address.MESSAGE_ADDRESS_CONSTRAINTS); } final Address modelAddress = new Address(address); - + */ final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + return new Person(modelName, modelType, modelDuration, modelDifficulty, modelEquipment, + modelMuscle, modelCalories, modelInstruction, modelTags); } @Override @@ -129,9 +219,18 @@ public boolean equals(Object other) { XmlAdaptedPerson otherPerson = (XmlAdaptedPerson) other; return Objects.equals(name, otherPerson.name) + /* && Objects.equals(phone, otherPerson.phone) && Objects.equals(email, otherPerson.email) && Objects.equals(address, otherPerson.address) + */ + && Objects.equals(type, otherPerson.type) + && Objects.equals(duration, otherPerson.duration) + && Objects.equals(difficulty, otherPerson.difficulty) + && Objects.equals(equipment, otherPerson.equipment) + && Objects.equals(muscle, otherPerson.muscle) + && Objects.equals(calories, otherPerson.calories) + && Objects.equals(instruction, otherPerson.instruction) && tagged.equals(otherPerson.tagged); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index f6727ea83abd..32fadfa3939e 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -30,12 +30,28 @@ public class PersonCard extends UiPart { private Label name; @FXML private Label id; + @FXML + private Label type; + @FXML + private Label duration; + @FXML + private Label difficulty; + @FXML + private Label equipment; + @FXML + private Label muscle; + @FXML + private Label calories; + @FXML + private Label instruction; +/* @FXML private Label phone; @FXML private Label address; @FXML private Label email; +*/ @FXML private FlowPane tags; @@ -44,9 +60,16 @@ public PersonCard(Person person, int displayedIndex) { this.person = person; id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); - phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); - email.setText(person.getEmail().value); + type.setText(person.getType().fullType); + duration.setText(person.getDuration().fullDuration); + difficulty.setText(person.getDifficulty().fullDifficulty); + equipment.setText(person.getEquipment().fullEquipment); + muscle.setText(person.getMuscle().fullMuscle); + calories.setText(person.getCalories().fullCalories); + instruction.setText(person.getInstruction().fullInstruction); +// phone.setText(person.getPhone().value); +// address.setText(person.getAddress().value); +// email.setText(person.getEmail().value); person.getTags().forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); } diff --git a/src/test/java/guitests/guihandles/PersonCardHandle.java b/src/test/java/guitests/guihandles/PersonCardHandle.java index 1789735e49a8..9684a4d9e3d6 100644 --- a/src/test/java/guitests/guihandles/PersonCardHandle.java +++ b/src/test/java/guitests/guihandles/PersonCardHandle.java @@ -16,16 +16,34 @@ public class PersonCardHandle extends NodeHandle { private static final String ID_FIELD_ID = "#id"; private static final String NAME_FIELD_ID = "#name"; + private static final String TYPE_FIELD_ID = "#type"; + private static final String DURATION_FIELD_ID = "#duration"; + private static final String DIFFICULTY_FIELD_ID = "#difficulty"; + private static final String EQUIPMENT_FIELD_ID = "#equipment"; + private static final String MUSCLE_FIELD_ID = "#muscle"; + private static final String CALORIES_FIELD_ID = "#calories"; + private static final String INSTRUCTION_FIELD_ID = "#instruction"; + /* private static final String ADDRESS_FIELD_ID = "#address"; private static final String PHONE_FIELD_ID = "#phone"; private static final String EMAIL_FIELD_ID = "#email"; + */ private static final String TAGS_FIELD_ID = "#tags"; private final Label idLabel; private final Label nameLabel; + private final Label typeLabel; + private final Label durationLabel; + private final Label difficultyLabel; + private final Label equipmentLabel; + private final Label muscleLabel; + private final Label caloriesLabel; + private final Label instructionLabel; + /* private final Label addressLabel; private final Label phoneLabel; private final Label emailLabel; + */ private final List