From e337b668ff2eb0235d4467bf39e522380a48fc15 Mon Sep 17 00:00:00 2001 From: Cheepeng Date: Tue, 10 Sep 2019 16:11:18 +0800 Subject: [PATCH 001/129] Update README.adoc Update links to travis CI and coveralls to personal organization link. --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index d34211c9341..9fe58090403 100644 --- a/README.adoc +++ b/README.adoc @@ -1,9 +1,9 @@ = Address Book (Level 3) ifdef::env-github,env-browser[:relfileprefix: docs/] -https://travis-ci.org/se-edu/addressbook-level3[image:https://travis-ci.org/se-edu/addressbook-level3.svg?branch=master[Build Status]] +https://travis-ci.org/AY1920S1-CS2103T-T09-2/main[image:https://travis-ci.org/AY1920S1-CS2103T-T09-2/main.svg?branch=master[Build Status]] https://ci.appveyor.com/project/damithc/addressbook-level3[image:https://ci.appveyor.com/api/projects/status/3boko2x2vr5cc3w2?svg=true[Build status]] -https://coveralls.io/github/se-edu/addressbook-level3?branch=master[image:https://coveralls.io/repos/github/se-edu/addressbook-level3/badge.svg?branch=master[Coverage Status]] +https://coveralls.io/github/AY1920S1-CS2103T-T09-2/main?branch=master[image:https://coveralls.io/repos/github/AY1920S1-CS2103T-T09-2/main/badge.svg?branch=master[Coverage]] https://www.codacy.com/app/damith/addressbook-level3?utm_source=github.com&utm_medium=referral&utm_content=se-edu/addressbook-level3&utm_campaign=Badge_Grade[image:https://api.codacy.com/project/badge/Grade/fc0b7775cf7f4fdeaf08776f3d8e364a[Codacy Badge]] https://gitter.im/se-edu/Lobby[image:https://badges.gitter.im/se-edu/Lobby.svg[Gitter chat]] From 3115284d4505de924359652a8b3afc1f951167c2 Mon Sep 17 00:00:00 2001 From: Cheepeng Date: Tue, 10 Sep 2019 16:25:45 +0800 Subject: [PATCH 002/129] Update README.adoc Removed the codacy badge from README --- README.adoc | 1 - 1 file changed, 1 deletion(-) diff --git a/README.adoc b/README.adoc index 9fe58090403..9e095015248 100644 --- a/README.adoc +++ b/README.adoc @@ -4,7 +4,6 @@ ifdef::env-github,env-browser[:relfileprefix: docs/] https://travis-ci.org/AY1920S1-CS2103T-T09-2/main[image:https://travis-ci.org/AY1920S1-CS2103T-T09-2/main.svg?branch=master[Build Status]] https://ci.appveyor.com/project/damithc/addressbook-level3[image:https://ci.appveyor.com/api/projects/status/3boko2x2vr5cc3w2?svg=true[Build status]] https://coveralls.io/github/AY1920S1-CS2103T-T09-2/main?branch=master[image:https://coveralls.io/repos/github/AY1920S1-CS2103T-T09-2/main/badge.svg?branch=master[Coverage]] -https://www.codacy.com/app/damith/addressbook-level3?utm_source=github.com&utm_medium=referral&utm_content=se-edu/addressbook-level3&utm_campaign=Badge_Grade[image:https://api.codacy.com/project/badge/Grade/fc0b7775cf7f4fdeaf08776f3d8e364a[Codacy Badge]] https://gitter.im/se-edu/Lobby[image:https://badges.gitter.im/se-edu/Lobby.svg[Gitter chat]] ifdef::env-github[] From 8af053e2ab4b58cf0ad8a7d437085ffbbd08108f Mon Sep 17 00:00:00 2001 From: garylyp Date: Thu, 19 Sep 2019 17:01:59 +0800 Subject: [PATCH 003/129] Set up repo for local development --- docs/DeveloperGuide.adoc | 2 +- docs/UserGuide.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/DeveloperGuide.adoc b/docs/DeveloperGuide.adoc index 3d65905a853..7b329aaf5d9 100644 --- a/docs/DeveloperGuide.adoc +++ b/docs/DeveloperGuide.adoc @@ -12,7 +12,7 @@ ifdef::env-github[] :note-caption: :information_source: :warning-caption: :warning: endif::[] -:repoURL: https://github.com/se-edu/addressbook-level3/tree/master +:repoURL: https://github.com/AY1920S1-CS2103T-T09-2/main/tree/master By: `Team SE-EDU`      Since: `Jun 2016`      Licence: `MIT` diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4e5d297a19f..3cefa2b9fbc 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -12,7 +12,7 @@ ifdef::env-github[] :tip-caption: :bulb: :note-caption: :information_source: endif::[] -:repoURL: https://github.com/se-edu/addressbook-level3 +:repoURL: https://github.com/AY1920S1-CS2103T-T09-2/main/tree/master By: `Team SE-EDU` Since: `Jun 2016` Licence: `MIT` From 1542b8e92eab471fc1a933ea72a7c130ccba4ee6 Mon Sep 17 00:00:00 2001 From: t-cheepeng Date: Thu, 26 Sep 2019 20:15:14 +0800 Subject: [PATCH 004/129] Update contact us doc to match ExerHealth --- docs/ContactUs.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ContactUs.adoc b/docs/ContactUs.adoc index 81be279ef6d..69869da0c03 100644 --- a/docs/ContactUs.adoc +++ b/docs/ContactUs.adoc @@ -2,6 +2,6 @@ :site-section: ContactUs :stylesDir: stylesheets -* *Bug reports, Suggestions* : Post in our https://github.com/se-edu/addressbook-level3/issues[issue tracker] if you noticed bugs or have suggestions on how to improve. +* *Bug reports, Suggestions* : Post in our https://github.com/AY1920S1-CS2103T-T09-2/main/issues[issue tracker] if you noticed bugs or have suggestions on how to improve. * *Contributing* : We welcome pull requests. Follow the process described https://github.com/oss-generic/process[here] -* *Email us* : You can also reach us at `damith [at] comp.nus.edu.sg` +* *Email us* : You can also reach us at `e0310551 [at] u.nus.edu` From 42ddbbd553d08fac5a29e11868d4a7fd29b21c37 Mon Sep 17 00:00:00 2001 From: weihaw08 Date: Fri, 27 Sep 2019 22:53:05 +0800 Subject: [PATCH 005/129] Refactor code base for ExerHealth --- src/main/java/seedu/address/MainApp.java | 38 ++-- .../address/commons/core/GuiSettings.java | 4 +- .../seedu/address/commons/core/Messages.java | 4 +- src/main/java/seedu/address/logic/Logic.java | 15 +- .../seedu/address/logic/LogicManager.java | 22 +- .../address/logic/commands/AddCommand.java | 54 ++--- .../address/logic/commands/ClearCommand.java | 6 +- .../address/logic/commands/DeleteCommand.java | 14 +- .../address/logic/commands/EditCommand.java | 181 ++++++++-------- .../address/logic/commands/ExitCommand.java | 2 +- .../address/logic/commands/FindCommand.java | 6 +- .../address/logic/commands/ListCommand.java | 4 +- .../logic/parser/AddCommandParser.java | 40 ++-- .../seedu/address/logic/parser/CliSyntax.java | 8 +- .../logic/parser/EditCommandParser.java | 47 ++-- .../logic/parser/FindCommandParser.java | 2 +- .../address/logic/parser/ParserUtil.java | 89 ++++---- .../java/seedu/address/model/AddressBook.java | 120 ---------- .../seedu/address/model/ExerciseBook.java | 121 +++++++++++ src/main/java/seedu/address/model/Model.java | 56 ++--- .../seedu/address/model/ModelManager.java | 90 ++++---- ...essBook.java => ReadOnlyExerciseBook.java} | 6 +- .../address/model/ReadOnlyUserPrefs.java | 2 +- .../java/seedu/address/model/UserPrefs.java | 20 +- .../address/model/exercise/Calories.java | 52 +++++ .../seedu/address/model/exercise/Date.java | 60 +++++ .../address/model/exercise/Exercise.java | 120 ++++++++++ .../model/{person => exercise}/Name.java | 8 +- .../NameContainsKeywordsPredicate.java | 8 +- .../address/model/exercise/Property.java | 13 ++ .../Address.java => exercise/Quantity.java} | 30 +-- .../model/exercise/UniqueExerciseList.java | 138 ++++++++++++ .../DuplicateExerciseException.java | 11 + .../exceptions/ExerciseNotFoundException.java | 6 + .../seedu/address/model/person/Email.java | 67 ------ .../seedu/address/model/person/Person.java | 120 ---------- .../seedu/address/model/person/Phone.java | 53 ----- .../model/person/UniquePersonList.java | 137 ------------ .../exceptions/DuplicatePersonException.java | 11 - .../exceptions/PersonNotFoundException.java | 6 - .../java/seedu/address/model/tag/Muscle.java | 54 +++++ .../java/seedu/address/model/tag/Tag.java | 54 ----- .../address/model/util/SampleDataUtil.java | 74 +++---- .../address/storage/AddressBookStorage.java | 45 ---- .../address/storage/ExerciseBookStorage.java | 46 ++++ .../address/storage/JsonAdaptedExercise.java | 113 ++++++++++ .../address/storage/JsonAdaptedMuscle.java | 48 ++++ .../address/storage/JsonAdaptedPerson.java | 109 ---------- .../seedu/address/storage/JsonAdaptedTag.java | 48 ---- ...rage.java => JsonExerciseBookStorage.java} | 36 +-- .../storage/JsonSerializableAddressBook.java | 60 ----- .../storage/JsonSerializableExerciseBook.java | 60 +++++ .../java/seedu/address/storage/Storage.java | 10 +- .../seedu/address/storage/StorageManager.java | 32 +-- .../ui/{PersonCard.java => ExerciseCard.java} | 38 ++-- .../seedu/address/ui/ExerciseListPanel.java | 46 ++++ .../java/seedu/address/ui/MainWindow.java | 25 ++- .../seedu/address/ui/PersonListPanel.java | 46 ---- ...sonListCard.fxml => ExerciseListCard.fxml} | 6 +- .../resources/view/ExerciseListPanel.fxml | 8 + src/main/resources/view/MainWindow.fxml | 39 ++-- src/main/resources/view/PersonListPanel.fxml | 8 - .../invalidAndValidPersonAddressBook.json | 13 -- .../invalidPersonAddressBook.json | 8 - .../invalidAndValidExerciseBook.json | 13 ++ .../invalidExerciseBook.json | 8 + .../notJsonFormatExerciseBook.json} | 0 .../duplicatePersonAddressBook.json | 14 -- .../invalidPersonAddressBook.json | 8 - .../typicalPersonsAddressBook.json | 46 ---- .../duplicateExerciseBook.json | 13 ++ .../invalidExerciseBook.json | 8 + .../typicalExerciseBook.json | 46 ++++ .../seedu/address/logic/LogicManagerTest.java | 65 +++--- .../commands/AddCommandIntegrationTest.java | 26 +-- .../logic/commands/AddCommandTest.java | 99 +++++---- .../logic/commands/ClearCommandTest.java | 10 +- .../logic/commands/CommandTestUtil.java | 117 +++++----- .../logic/commands/DeleteCommandTest.java | 62 +++--- .../logic/commands/EditCommandTest.java | 147 +++++++------ .../commands/EditExerciseDescriptorTest.java | 63 ++++++ .../commands/EditPersonDescriptorTest.java | 58 ----- .../logic/commands/FindCommandTest.java | 30 +-- .../logic/commands/ListCommandTest.java | 12 +- .../logic/parser/AddCommandParserTest.java | 195 +++++++++-------- .../logic/parser/DeleteCommandParserTest.java | 4 +- .../logic/parser/EditCommandParserTest.java | 205 +++++++++--------- ...rTest.java => ExerciseBookParserTest.java} | 34 +-- .../logic/parser/FindCommandParserTest.java | 8 +- .../address/logic/parser/ParserUtilTest.java | 150 ++++++------- .../seedu/address/model/AddressBookTest.java | 102 --------- .../seedu/address/model/ExerciseBookTest.java | 102 +++++++++ .../seedu/address/model/ModelManagerTest.java | 67 +++--- .../seedu/address/model/UserPrefsTest.java | 2 +- .../address/model/exercise/CaloriesTest.java | 42 ++++ .../address/model/exercise/DateTest.java | 41 ++++ .../address/model/exercise/ExerciseTest.java | 87 ++++++++ .../NameContainsKeywordsPredicateTest.java | 34 +-- .../model/{person => exercise}/NameTest.java | 17 +- .../address/model/exercise/QuantityTest.java | 36 +++ .../exercise/UniqueExerciseListTest.java | 171 +++++++++++++++ .../address/model/person/AddressTest.java | 36 --- .../seedu/address/model/person/EmailTest.java | 61 ------ .../address/model/person/PersonTest.java | 95 -------- .../seedu/address/model/person/PhoneTest.java | 40 ---- .../model/person/UniquePersonListTest.java | 170 --------------- .../java/seedu/address/model/tag/TagTest.java | 6 +- .../storage/JsonAdaptedExerciseTest.java | 114 ++++++++++ .../storage/JsonAdaptedPersonTest.java | 110 ---------- .../storage/JsonAddressBookStorageTest.java | 110 ---------- .../storage/JsonExerciseBookStorageTest.java | 110 ++++++++++ .../JsonSerializableAddressBookTest.java | 47 ---- .../JsonSerializableExerciseBookTest.java | 47 ++++ .../storage/JsonUserPrefsStorageTest.java | 8 +- .../address/storage/StorageManagerTest.java | 26 +-- .../address/testutil/AddressBookBuilder.java | 34 --- .../EditExerciseDescriptorBuilder.java | 87 ++++++++ .../testutil/EditPersonDescriptorBuilder.java | 87 -------- .../address/testutil/ExerciseBookBuilder.java | 34 +++ .../address/testutil/ExerciseBuilder.java | 93 ++++++++ .../seedu/address/testutil/ExerciseUtil.java | 62 ++++++ .../seedu/address/testutil/PersonBuilder.java | 93 -------- .../seedu/address/testutil/PersonUtil.java | 62 ------ .../java/seedu/address/testutil/TestUtil.java | 10 +- .../address/testutil/TypicalExercises.java | 74 +++++++ .../address/testutil/TypicalIndexes.java | 6 +- .../address/testutil/TypicalPersons.java | 76 ------- 127 files changed, 3367 insertions(+), 3290 deletions(-) delete mode 100644 src/main/java/seedu/address/model/AddressBook.java create mode 100644 src/main/java/seedu/address/model/ExerciseBook.java rename src/main/java/seedu/address/model/{ReadOnlyAddressBook.java => ReadOnlyExerciseBook.java} (65%) create mode 100644 src/main/java/seedu/address/model/exercise/Calories.java create mode 100644 src/main/java/seedu/address/model/exercise/Date.java create mode 100644 src/main/java/seedu/address/model/exercise/Exercise.java rename src/main/java/seedu/address/model/{person => exercise}/Name.java (84%) rename src/main/java/seedu/address/model/{person => exercise}/NameContainsKeywordsPredicate.java (85%) create mode 100644 src/main/java/seedu/address/model/exercise/Property.java rename src/main/java/seedu/address/model/{person/Address.java => exercise/Quantity.java} (50%) create mode 100644 src/main/java/seedu/address/model/exercise/UniqueExerciseList.java create mode 100644 src/main/java/seedu/address/model/exercise/exceptions/DuplicateExerciseException.java create mode 100644 src/main/java/seedu/address/model/exercise/exceptions/ExerciseNotFoundException.java delete mode 100644 src/main/java/seedu/address/model/person/Email.java delete mode 100644 src/main/java/seedu/address/model/person/Person.java delete mode 100644 src/main/java/seedu/address/model/person/Phone.java delete mode 100644 src/main/java/seedu/address/model/person/UniquePersonList.java delete mode 100644 src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java delete mode 100644 src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java create mode 100644 src/main/java/seedu/address/model/tag/Muscle.java delete mode 100644 src/main/java/seedu/address/model/tag/Tag.java delete mode 100644 src/main/java/seedu/address/storage/AddressBookStorage.java create mode 100644 src/main/java/seedu/address/storage/ExerciseBookStorage.java create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedExercise.java create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedMuscle.java delete mode 100644 src/main/java/seedu/address/storage/JsonAdaptedPerson.java delete mode 100644 src/main/java/seedu/address/storage/JsonAdaptedTag.java rename src/main/java/seedu/address/storage/{JsonAddressBookStorage.java => JsonExerciseBookStorage.java} (54%) delete mode 100644 src/main/java/seedu/address/storage/JsonSerializableAddressBook.java create mode 100644 src/main/java/seedu/address/storage/JsonSerializableExerciseBook.java rename src/main/java/seedu/address/ui/{PersonCard.java => ExerciseCard.java} (57%) create mode 100644 src/main/java/seedu/address/ui/ExerciseListPanel.java delete mode 100644 src/main/java/seedu/address/ui/PersonListPanel.java rename src/main/resources/view/{PersonListCard.fxml => ExerciseListCard.fxml} (83%) create mode 100644 src/main/resources/view/ExerciseListPanel.fxml delete mode 100644 src/main/resources/view/PersonListPanel.fxml delete mode 100644 src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json delete mode 100644 src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json create mode 100644 src/test/data/JsonExerciseBookStorageTest/invalidAndValidExerciseBook.json create mode 100644 src/test/data/JsonExerciseBookStorageTest/invalidExerciseBook.json rename src/test/data/{JsonAddressBookStorageTest/notJsonFormatAddressBook.json => JsonExerciseBookStorageTest/notJsonFormatExerciseBook.json} (100%) delete mode 100644 src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json delete mode 100644 src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json delete mode 100644 src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json create mode 100644 src/test/data/JsonSerializableExerciseBookTest/duplicateExerciseBook.json create mode 100644 src/test/data/JsonSerializableExerciseBookTest/invalidExerciseBook.json create mode 100644 src/test/data/JsonSerializableExerciseBookTest/typicalExerciseBook.json create mode 100644 src/test/java/seedu/address/logic/commands/EditExerciseDescriptorTest.java delete mode 100644 src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java rename src/test/java/seedu/address/logic/parser/{AddressBookParserTest.java => ExerciseBookParserTest.java} (75%) delete mode 100644 src/test/java/seedu/address/model/AddressBookTest.java create mode 100644 src/test/java/seedu/address/model/ExerciseBookTest.java create mode 100644 src/test/java/seedu/address/model/exercise/CaloriesTest.java create mode 100644 src/test/java/seedu/address/model/exercise/DateTest.java create mode 100644 src/test/java/seedu/address/model/exercise/ExerciseTest.java rename src/test/java/seedu/address/model/{person => exercise}/NameContainsKeywordsPredicateTest.java (67%) rename src/test/java/seedu/address/model/{person => exercise}/NameTest.java (57%) create mode 100644 src/test/java/seedu/address/model/exercise/QuantityTest.java create mode 100644 src/test/java/seedu/address/model/exercise/UniqueExerciseListTest.java delete mode 100644 src/test/java/seedu/address/model/person/AddressTest.java delete mode 100644 src/test/java/seedu/address/model/person/EmailTest.java delete mode 100644 src/test/java/seedu/address/model/person/PersonTest.java delete mode 100644 src/test/java/seedu/address/model/person/PhoneTest.java delete mode 100644 src/test/java/seedu/address/model/person/UniquePersonListTest.java create mode 100644 src/test/java/seedu/address/storage/JsonAdaptedExerciseTest.java delete mode 100644 src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java delete mode 100644 src/test/java/seedu/address/storage/JsonAddressBookStorageTest.java create mode 100644 src/test/java/seedu/address/storage/JsonExerciseBookStorageTest.java delete mode 100644 src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java create mode 100644 src/test/java/seedu/address/storage/JsonSerializableExerciseBookTest.java delete mode 100644 src/test/java/seedu/address/testutil/AddressBookBuilder.java create mode 100644 src/test/java/seedu/address/testutil/EditExerciseDescriptorBuilder.java delete mode 100644 src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java create mode 100644 src/test/java/seedu/address/testutil/ExerciseBookBuilder.java create mode 100644 src/test/java/seedu/address/testutil/ExerciseBuilder.java create mode 100644 src/test/java/seedu/address/testutil/ExerciseUtil.java delete mode 100644 src/test/java/seedu/address/testutil/PersonBuilder.java delete mode 100644 src/test/java/seedu/address/testutil/PersonUtil.java create mode 100644 src/test/java/seedu/address/testutil/TypicalExercises.java delete mode 100644 src/test/java/seedu/address/testutil/TypicalPersons.java diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index e5cfb161b73..cf15bcf6fc7 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -15,15 +15,15 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.Logic; import seedu.address.logic.LogicManager; -import seedu.address.model.AddressBook; +import seedu.address.model.ExerciseBook; import seedu.address.model.Model; import seedu.address.model.ModelManager; -import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyExerciseBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; import seedu.address.model.util.SampleDataUtil; -import seedu.address.storage.AddressBookStorage; -import seedu.address.storage.JsonAddressBookStorage; +import seedu.address.storage.ExerciseBookStorage; +import seedu.address.storage.JsonExerciseBookStorage; import seedu.address.storage.JsonUserPrefsStorage; import seedu.address.storage.Storage; import seedu.address.storage.StorageManager; @@ -48,7 +48,7 @@ public class MainApp extends Application { @Override public void init() throws Exception { - logger.info("=============================[ Initializing AddressBook ]==========================="); + logger.info("=============================[ Initializing ExerciseBook ]==========================="); super.init(); AppParameters appParameters = AppParameters.parse(getParameters()); @@ -56,8 +56,8 @@ public void init() throws Exception { UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath()); UserPrefs userPrefs = initPrefs(userPrefsStorage); - AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath()); - storage = new StorageManager(addressBookStorage, userPrefsStorage); + ExerciseBookStorage exerciseBookStorage = new JsonExerciseBookStorage(userPrefs.getExerciseBookFilePath()); + storage = new StorageManager(exerciseBookStorage, userPrefsStorage); initLogging(config); @@ -74,20 +74,20 @@ public void init() throws Exception { * or an empty address book will be used instead if errors occur when reading {@code storage}'s address book. */ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { - Optional addressBookOptional; - ReadOnlyAddressBook initialData; + Optional addressBookOptional; + ReadOnlyExerciseBook initialData; try { - addressBookOptional = storage.readAddressBook(); + addressBookOptional = storage.readExerciseBook(); if (!addressBookOptional.isPresent()) { - logger.info("Data file not found. Will be starting with a sample AddressBook"); + logger.info("Data file not found. Will be starting with a sample ExerciseBook"); } - initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook); + initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleExerciseBook); } catch (DataConversionException e) { - logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook"); - initialData = new AddressBook(); + logger.warning("Data file not in the correct format. Will be starting with an empty ExerciseBook"); + initialData = new ExerciseBook(); } catch (IOException e) { - logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook"); - initialData = new AddressBook(); + logger.warning("Problem while reading from the file. Will be starting with an empty ExerciseBook"); + initialData = new ExerciseBook(); } return new ModelManager(initialData, userPrefs); @@ -151,7 +151,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) { + "Using default user prefs"); initializedPrefs = new UserPrefs(); } catch (IOException e) { - logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook"); + logger.warning("Problem while reading from the file. Will be starting with an empty ExerciseBook"); initializedPrefs = new UserPrefs(); } @@ -167,13 +167,13 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) { @Override public void start(Stage primaryStage) { - logger.info("Starting AddressBook " + MainApp.VERSION); + logger.info("Starting ExerciseBook " + MainApp.VERSION); ui.start(primaryStage); } @Override public void stop() { - logger.info("============================ [ Stopping Address Book ] ============================="); + logger.info("============================ [ Stopping Quantity Book ] ============================="); try { storage.saveUserPrefs(model.getUserPrefs()); } catch (IOException e) { diff --git a/src/main/java/seedu/address/commons/core/GuiSettings.java b/src/main/java/seedu/address/commons/core/GuiSettings.java index 5ace559ad15..e2a5f12c37c 100644 --- a/src/main/java/seedu/address/commons/core/GuiSettings.java +++ b/src/main/java/seedu/address/commons/core/GuiSettings.java @@ -10,8 +10,8 @@ */ public class GuiSettings implements Serializable { - private static final double DEFAULT_HEIGHT = 600; - private static final double DEFAULT_WIDTH = 740; + private static final double DEFAULT_HEIGHT = 1000; + private static final double DEFAULT_WIDTH = 1000; private final double windowWidth; private final double windowHeight; diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 1deb3a1e469..0d514aea35a 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -7,7 +7,7 @@ public class Messages { public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; - public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; - public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; + public static final String MESSAGE_INVALID_EXERCISE_DISPLAYED_INDEX = "The exercise index provided is invalid"; + public static final String MESSAGE_EXERCISES_LISTED_OVERVIEW = "%1$d exercises listed!"; } diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 92cd8fa605a..01de5fb544e 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -7,8 +7,8 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; +import seedu.address.model.ReadOnlyExerciseBook; +import seedu.address.model.exercise.Exercise; /** * API of the Logic component @@ -24,14 +24,16 @@ public interface Logic { CommandResult execute(String commandText) throws CommandException, ParseException; /** - * Returns the AddressBook. + * Returns the ExerciseBook. * - * @see seedu.address.model.Model#getAddressBook() + * @see seedu.address.model.Model#getAllData() */ - ReadOnlyAddressBook getAddressBook(); + ReadOnlyExerciseBook getAddressBook(); /** Returns an unmodifiable view of the filtered list of persons */ - ObservableList getFilteredPersonList(); + ObservableList getFilteredExerciseList(); + + ObservableList getSortedExerciseList(); /** * Returns the user prefs' address book file path. @@ -47,4 +49,5 @@ public interface Logic { * Set the user prefs' GUI settings. */ void setGuiSettings(GuiSettings guiSettings); + } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index d47ce874b1a..a07c8b0c0e4 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -13,8 +13,8 @@ import seedu.address.logic.parser.AddressBookParser; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; +import seedu.address.model.ReadOnlyExerciseBook; +import seedu.address.model.exercise.Exercise; import seedu.address.storage.Storage; /** @@ -43,7 +43,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE commandResult = command.execute(model); try { - storage.saveAddressBook(model.getAddressBook()); + storage.saveExerciseBook(model.getAllData()); } catch (IOException ioe) { throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe); } @@ -52,18 +52,23 @@ public CommandResult execute(String commandText) throws CommandException, ParseE } @Override - public ReadOnlyAddressBook getAddressBook() { - return model.getAddressBook(); + public ReadOnlyExerciseBook getAddressBook() { + return model.getAllData(); } @Override - public ObservableList getFilteredPersonList() { - return model.getFilteredPersonList(); + public ObservableList getFilteredExerciseList() { + return model.getFilteredExerciseList(); + } + + @Override + public ObservableList getSortedExerciseList() { + return model.getSortedExerciseList(); } @Override public Path getAddressBookFilePath() { - return model.getAddressBookFilePath(); + return model.getExerciseBookFilePath(); } @Override @@ -75,4 +80,5 @@ public GuiSettings getGuiSettings() { public void setGuiSettings(GuiSettings guiSettings) { model.setGuiSettings(guiSettings); } + } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 71656d7c5c8..cbc5dbc2573 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -1,67 +1,67 @@ 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_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_QUANTITY; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Person; +import seedu.address.model.exercise.Exercise; /** - * Adds a person to the address book. + * Adds an exercise to the exercise book. */ 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. " - + "Parameters: " - + PREFIX_NAME + "NAME " - + PREFIX_PHONE + "PHONE " - + PREFIX_EMAIL + "EMAIL " - + PREFIX_ADDRESS + "ADDRESS " - + "[" + 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"; + + "Parameters: " + + PREFIX_NAME + "NAME " + + PREFIX_DATE + "PHONE " + + PREFIX_CALORIES + "EMAIL " + + PREFIX_QUANTITY + "ADDRESS " + + "[" + PREFIX_MUSCLE + "TAG]...\n" + + "Example: " + COMMAND_WORD + " " + + PREFIX_NAME + "John Doe " + + PREFIX_DATE + "98765432 " + + PREFIX_CALORIES + "johnd@example.com " + + PREFIX_QUANTITY + "311, Clementi Ave 2, #02-25 " + + PREFIX_MUSCLE + "friends " + + PREFIX_MUSCLE + "owesMoney"; 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"; - private final Person toAdd; + private final Exercise toAdd; /** * Creates an AddCommand to add the specified {@code Person} */ - public AddCommand(Person person) { - requireNonNull(person); - toAdd = person; + public AddCommand(Exercise exercise) { + requireNonNull(exercise); + toAdd = exercise; } @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - if (model.hasPerson(toAdd)) { + if (model.hasExercise(toAdd)) { throw new CommandException(MESSAGE_DUPLICATE_PERSON); } - model.addPerson(toAdd); + model.addExercise(toAdd); return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); } @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof AddCommand // instanceof handles nulls - && toAdd.equals(((AddCommand) other).toAdd)); + || (other instanceof AddCommand // instanceof handles nulls + && toAdd.equals(((AddCommand) other).toAdd)); } } diff --git a/src/main/java/seedu/address/logic/commands/ClearCommand.java b/src/main/java/seedu/address/logic/commands/ClearCommand.java index 9c86b1fa6e4..ff53ffd8a1a 100644 --- a/src/main/java/seedu/address/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClearCommand.java @@ -2,7 +2,7 @@ import static java.util.Objects.requireNonNull; -import seedu.address.model.AddressBook; +import seedu.address.model.ExerciseBook; import seedu.address.model.Model; /** @@ -11,13 +11,13 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; - public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; + public static final String MESSAGE_SUCCESS = "Exercise book has been cleared!"; @Override public CommandResult execute(Model model) { requireNonNull(model); - model.setAddressBook(new AddressBook()); + model.setExerciseBook(new ExerciseBook()); return new CommandResult(MESSAGE_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 02fd256acba..e4cce783328 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -8,7 +8,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Person; +import seedu.address.model.exercise.Exercise; /** * Deletes a person identified using it's displayed index from the address book. @@ -22,7 +22,7 @@ public class DeleteCommand extends Command { + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1"; - public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; + public static final String MESSAGE_DELETE_EXERCISE_SUCCESS = "Deleted Exercise: %1$s"; private final Index targetIndex; @@ -33,15 +33,15 @@ public DeleteCommand(Index targetIndex) { @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - List lastShownList = model.getFilteredPersonList(); + List lastShownList = model.getFilteredExerciseList(); if (targetIndex.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_EXERCISE_DISPLAYED_INDEX); } - Person personToDelete = lastShownList.get(targetIndex.getZeroBased()); - model.deletePerson(personToDelete); - return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete)); + Exercise exerciseToDelete = lastShownList.get(targetIndex.getZeroBased()); + model.deleteExercise(exerciseToDelete); + return new CommandResult(String.format(MESSAGE_DELETE_EXERCISE_SUCCESS, exerciseToDelete)); } @Override diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 7e36114902f..9ccfd02ffa8 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,12 +1,11 @@ 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_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_QUANTITY; import java.util.Collections; import java.util.HashSet; @@ -19,87 +18,88 @@ import seedu.address.commons.util.CollectionUtil; 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.tag.Tag; +import seedu.address.model.exercise.Calories; +import seedu.address.model.exercise.Date; +import seedu.address.model.exercise.Exercise; +import seedu.address.model.exercise.Name; +import seedu.address.model.exercise.Quantity; +import seedu.address.model.tag.Muscle; /** - * Edits the details of an existing person in the address book. + * Edits the details of an existing exercise in the exercise 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. " - + "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_TAG + "TAG]...\n" - + "Example: " + COMMAND_WORD + " 1 " - + PREFIX_PHONE + "91234567 " - + PREFIX_EMAIL + "johndoe@example.com"; - - public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; + + "by the index number used in the displayed person list. " + + "Existing values will be overwritten by the input values.\n" + + "Parameters: INDEX (must be a positive integer) " + + "[" + PREFIX_NAME + "NAME] " + + "[" + PREFIX_DATE + "PHONE] " + + "[" + PREFIX_CALORIES + "EMAIL] " + + "[" + PREFIX_QUANTITY + "ADDRESS] " + + "[" + PREFIX_MUSCLE + "TAG]...\n" + + "Example: " + COMMAND_WORD + " 1 " + + PREFIX_DATE + "91234567 " + + PREFIX_CALORIES + "johndoe@example.com"; + + public static final String MESSAGE_EDIT_EXERCISE_SUCCESS = "Edited Exercise: %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_EXERCISE = "This exercise already exists in the exercise book."; private final Index index; - private final EditPersonDescriptor editPersonDescriptor; + private final EditExerciseDescriptor editExerciseDescriptor; /** - * @param index of the person in the filtered person list to edit - * @param editPersonDescriptor details to edit the person with + * @param index of the exercise in the filtered exercise list to edit + * @param editExerciseDescriptor details to edit the person with */ - public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { + public EditCommand(Index index, EditExerciseDescriptor editExerciseDescriptor) { requireNonNull(index); - requireNonNull(editPersonDescriptor); + requireNonNull(editExerciseDescriptor); this.index = index; - this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); + this.editExerciseDescriptor = new EditExerciseDescriptor(editExerciseDescriptor); } @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - List lastShownList = model.getFilteredPersonList(); + List lastShownList = model.getFilteredExerciseList(); if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_EXERCISE_DISPLAYED_INDEX); } - Person personToEdit = lastShownList.get(index.getZeroBased()); - Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); + Exercise exerciseToEdit = lastShownList.get(index.getZeroBased()); + Exercise editedExercise = createEditedExercise(exerciseToEdit, editExerciseDescriptor); - if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + if (!exerciseToEdit.isSameExercise(editedExercise) && model.hasExercise(editedExercise)) { + throw new CommandException(MESSAGE_DUPLICATE_EXERCISE); } - model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson)); + model.setExercise(exerciseToEdit, editedExercise); + model.updateFilteredExerciseList(Model.PREDICATE_SHOW_ALL_EXERCISES); + return new CommandResult(String.format(MESSAGE_EDIT_EXERCISE_SUCCESS, editedExercise)); } /** - * Creates and returns a {@code Person} with the details of {@code personToEdit} - * edited with {@code editPersonDescriptor}. + * Creates and returns a {@code Exercise} with the details of {@code exerciseToEdit} + * edited with {@code editExerciseDescriptor}. */ - private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) { - assert personToEdit != null; + private static Exercise createEditedExercise( + Exercise exerciseToEdit, EditExerciseDescriptor editExerciseDescriptor) { + assert exerciseToEdit != 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()); - Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); + Name updatedName = editExerciseDescriptor.getName().orElse(exerciseToEdit.getName()); + Calories updatedCalories = editExerciseDescriptor.getCalories().orElse(exerciseToEdit.getCalories()); + Date updatedDate = editExerciseDescriptor.getDate().orElse(exerciseToEdit.getDate()); + Quantity updatedQuantity = editExerciseDescriptor.getQuantity().orElse(exerciseToEdit.getQuantity()); + Set updatedMuscles = editExerciseDescriptor.getMuscles().orElse(exerciseToEdit.getMuscles()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Exercise(updatedName, updatedDate, updatedCalories, updatedQuantity, updatedMuscles); } @Override @@ -117,39 +117,40 @@ public boolean equals(Object other) { // state check EditCommand e = (EditCommand) other; return index.equals(e.index) - && editPersonDescriptor.equals(e.editPersonDescriptor); + && editExerciseDescriptor.equals(e.editExerciseDescriptor); } /** * Stores the details to edit the person with. Each non-empty field value will replace the * corresponding field value of the person. */ - public static class EditPersonDescriptor { + public static class EditExerciseDescriptor { private Name name; - private Phone phone; - private Email email; - private Address address; - private Set tags; + private Calories calories; + private Date date; + private Quantity quantity; + private Set muscles; - public EditPersonDescriptor() {} + public EditExerciseDescriptor() { + } /** * Copy constructor. - * A defensive copy of {@code tags} is used internally. + * A defensive copy of {@code muscles} is used internally. */ - public EditPersonDescriptor(EditPersonDescriptor toCopy) { + public EditExerciseDescriptor(EditExerciseDescriptor toCopy) { setName(toCopy.name); - setPhone(toCopy.phone); - setEmail(toCopy.email); - setAddress(toCopy.address); - setTags(toCopy.tags); + setCalories(toCopy.calories); + setDate(toCopy.date); + setQuantity(toCopy.quantity); + setMuscles(toCopy.muscles); } /** * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); + return CollectionUtil.isAnyNonNull(name, calories, date, quantity, muscles); } public void setName(Name name) { @@ -160,45 +161,45 @@ public Optional getName() { return Optional.ofNullable(name); } - public void setPhone(Phone phone) { - this.phone = phone; + public void setCalories(Calories calories) { + this.calories = calories; } - public Optional getPhone() { - return Optional.ofNullable(phone); + public Optional getCalories() { + return Optional.ofNullable(calories); } - public void setEmail(Email email) { - this.email = email; + public void setDate(Date date) { + this.date = date; } - public Optional getEmail() { - return Optional.ofNullable(email); + public Optional getDate() { + return Optional.ofNullable(date); } - public void setAddress(Address address) { - this.address = address; + public void setQuantity(Quantity quantity) { + this.quantity = quantity; } - public Optional
getAddress() { - return Optional.ofNullable(address); + public Optional getQuantity() { + return Optional.ofNullable(quantity); } /** - * Sets {@code tags} to this object's {@code tags}. - * A defensive copy of {@code tags} is used internally. + * Sets {@code muscles} to this object's {@code muscles}. + * A defensive copy of {@code muscles} is used internally. */ - public void setTags(Set tags) { - this.tags = (tags != null) ? new HashSet<>(tags) : null; + public void setMuscles(Set muscles) { + this.muscles = (muscles != null) ? new HashSet<>(muscles) : null; } /** * Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. - * Returns {@code Optional#empty()} if {@code tags} is null. + * Returns {@code Optional#empty()} if {@code muscles} is null. */ - public Optional> getTags() { - return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); + public Optional> getMuscles() { + return (muscles != null) ? Optional.of(Collections.unmodifiableSet(muscles)) : Optional.empty(); } @Override @@ -209,18 +210,18 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof EditPersonDescriptor)) { + if (!(other instanceof EditExerciseDescriptor)) { return false; } // state check - EditPersonDescriptor e = (EditPersonDescriptor) other; + EditExerciseDescriptor e = (EditExerciseDescriptor) other; return getName().equals(e.getName()) - && getPhone().equals(e.getPhone()) - && getEmail().equals(e.getEmail()) - && getAddress().equals(e.getAddress()) - && getTags().equals(e.getTags()); + && getCalories().equals(e.getCalories()) + && getDate().equals(e.getDate()) + && getQuantity().equals(e.getQuantity()) + && getMuscles().equals(e.getMuscles()); } } } diff --git a/src/main/java/seedu/address/logic/commands/ExitCommand.java b/src/main/java/seedu/address/logic/commands/ExitCommand.java index 3dd85a8ba90..48cf0a86bbb 100644 --- a/src/main/java/seedu/address/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/address/logic/commands/ExitCommand.java @@ -9,7 +9,7 @@ public class ExitCommand extends Command { public static final String COMMAND_WORD = "exit"; - public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ..."; + public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Quantity Book as requested ..."; @Override public CommandResult execute(Model model) { diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index d6b19b0a0de..f52fa6cd151 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -4,7 +4,7 @@ import seedu.address.commons.core.Messages; import seedu.address.model.Model; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.exercise.NameContainsKeywordsPredicate; /** * Finds and lists all persons in address book whose name contains any of the argument keywords. @@ -28,9 +28,9 @@ public FindCommand(NameContainsKeywordsPredicate predicate) { @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredPersonList(predicate); + model.updateFilteredExerciseList(predicate); return new CommandResult( - String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); + String.format(Messages.MESSAGE_EXERCISES_LISTED_OVERVIEW, model.getFilteredExerciseList().size())); } @Override diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 84be6ad2596..54feec5445e 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -1,7 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_EXERCISES; import seedu.address.model.Model; @@ -18,7 +18,7 @@ public class ListCommand extends Command { @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + model.updateFilteredExerciseList(PREDICATE_SHOW_ALL_EXERCISES); return new CommandResult(MESSAGE_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 3b8bfa035e8..024833938fe 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -1,23 +1,23 @@ 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_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_QUANTITY; import java.util.Set; import java.util.stream.Stream; 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.tag.Tag; +import seedu.address.model.exercise.Calories; +import seedu.address.model.exercise.Date; +import seedu.address.model.exercise.Exercise; +import seedu.address.model.exercise.Name; +import seedu.address.model.exercise.Quantity; +import seedu.address.model.tag.Muscle; /** * Parses input arguments and creates a new AddCommand object @@ -27,26 +27,28 @@ public class AddCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the AddCommand * and returns an AddCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ 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_DATE, PREFIX_CALORIES, PREFIX_QUANTITY, + PREFIX_MUSCLE); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) - || !argMultimap.getPreamble().isEmpty()) { + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_QUANTITY, PREFIX_DATE, PREFIX_CALORIES) + || !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()); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()); + Calories calories = ParserUtil.parseCalories(argMultimap.getValue(PREFIX_CALORIES).get()); + Quantity quantity = ParserUtil.parseQuantity(argMultimap.getValue(PREFIX_QUANTITY).get()); + Set muscleList = ParserUtil.parseMuscles(argMultimap.getAllValues(PREFIX_MUSCLE)); - Person person = new Person(name, phone, email, address, tagList); + Exercise exercise = new Exercise(name, date, calories, quantity, muscleList); - return new AddCommand(person); + return new AddCommand(exercise); } /** diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf119..ea6fca4606c 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -7,9 +7,9 @@ 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_TAG = new Prefix("t/"); + public static final Prefix PREFIX_DATE = new Prefix("d/"); + public static final Prefix PREFIX_CALORIES = new Prefix("c/"); + public static final Prefix PREFIX_QUANTITY = new Prefix("q/"); + public static final Prefix PREFIX_MUSCLE = new Prefix("m/"); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 845644b7dea..24511886406 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -2,11 +2,11 @@ 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_CALORIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MUSCLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_QUANTITY; import java.util.Collection; import java.util.Collections; @@ -15,9 +15,9 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; +import seedu.address.logic.commands.EditCommand.EditExerciseDescriptor; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.tag.Tag; +import seedu.address.model.tag.Muscle; /** * Parses input arguments and creates a new EditCommand object @@ -27,12 +27,13 @@ public class EditCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the EditCommand * and returns an EditCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public EditCommand parse(String args) throws ParseException { requireNonNull(args); - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DATE, PREFIX_CALORIES, + PREFIX_QUANTITY, PREFIX_MUSCLE); Index index; @@ -42,41 +43,41 @@ public EditCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } - EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); + EditCommand.EditExerciseDescriptor editExerciseDescriptor = new EditExerciseDescriptor(); if (argMultimap.getValue(PREFIX_NAME).isPresent()) { - editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get())); + editExerciseDescriptor.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_DATE).isPresent()) { + editExerciseDescriptor.setDate(ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get())); } - if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { - editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); + if (argMultimap.getValue(PREFIX_CALORIES).isPresent()) { + editExerciseDescriptor.setCalories(ParserUtil.parseCalories(argMultimap.getValue(PREFIX_CALORIES).get())); } - if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { - editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); + if (argMultimap.getValue(PREFIX_QUANTITY).isPresent()) { + editExerciseDescriptor.setQuantity(ParserUtil.parseQuantity(argMultimap.getValue(PREFIX_QUANTITY).get())); } - parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); + parseTagsForEdit(argMultimap.getAllValues(PREFIX_MUSCLE)).ifPresent(editExerciseDescriptor::setMuscles); - if (!editPersonDescriptor.isAnyFieldEdited()) { + if (!editExerciseDescriptor.isAnyFieldEdited()) { throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); } - return new EditCommand(index, editPersonDescriptor); + return new EditCommand(index, editExerciseDescriptor); } /** - * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. * If {@code tags} contain only one element which is an empty string, it will be parsed into a - * {@code Set} containing zero tags. + * {@code Set} containing zero tags. */ - private Optional> parseTagsForEdit(Collection tags) throws ParseException { + private Optional> parseTagsForEdit(Collection tags) throws ParseException { assert tags != null; if (tags.isEmpty()) { return Optional.empty(); } Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; - return Optional.of(ParserUtil.parseTags(tagSet)); + return Optional.of(ParserUtil.parseMuscles(tagSet)); } } diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 4fb71f23103..69747196e48 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -6,7 +6,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.exercise.NameContainsKeywordsPredicate; /** * Parses input arguments and creates a new FindCommand object diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b117acb9c55..0bc7747f078 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,11 +9,11 @@ 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.tag.Tag; +import seedu.address.model.exercise.Calories; +import seedu.address.model.exercise.Date; +import seedu.address.model.exercise.Name; +import seedu.address.model.exercise.Quantity; +import seedu.address.model.tag.Muscle; /** * Contains utility methods used for parsing strings in the various *Parser classes. @@ -25,6 +25,7 @@ public class ParserUtil { /** * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be * trimmed. + * * @throws ParseException if the specified index is invalid (not non-zero unsigned integer). */ public static Index parseIndex(String oneBasedIndex) throws ParseException { @@ -51,74 +52,74 @@ public static Name parseName(String name) throws ParseException { } /** - * Parses a {@code String phone} into a {@code Phone}. + * Parses a {@code String calories} into a {@code Calories}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code phone} is invalid. + * @throws ParseException if the given {@code calories} 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_CONSTRAINTS); + public static Calories parseCalories(String calories) throws ParseException { + requireNonNull(calories); + String trimmedCalories = calories.trim(); + if (!Calories.isValidCalories(trimmedCalories)) { + throw new ParseException(Calories.MESSAGE_CONSTRAINTS); } - return new Phone(trimmedPhone); + return new Calories(trimmedCalories); } /** - * Parses a {@code String address} into an {@code Address}. + * Parses a {@code String quantity} into an {@code Quantity}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code address} is invalid. + * @throws ParseException if the given {@code quantity} 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_CONSTRAINTS); + public static Quantity parseQuantity(String quantity) throws ParseException { + requireNonNull(quantity); + String trimmedQuantity = quantity.trim(); + if (!Quantity.isValidQuantity(trimmedQuantity)) { + throw new ParseException(Quantity.MESSAGE_CONSTRAINTS); } - return new Address(trimmedAddress); + return new Quantity(trimmedQuantity); } /** - * Parses a {@code String email} into an {@code Email}. + * Parses a {@code String date} into an {@code Date}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code email} is invalid. + * @throws ParseException if the given {@code date} 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_CONSTRAINTS); + public static Date parseDate(String date) throws ParseException { + requireNonNull(date); + String trimmedDate = date.trim(); + if (!Date.isValidDate(trimmedDate)) { + throw new ParseException(Date.MESSAGE_CONSTRAINTS); } - return new Email(trimmedEmail); + return new Date(trimmedDate); } /** - * Parses a {@code String tag} into a {@code Tag}. + * Parses a {@code String muscle} into a {@code Muscle}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code tag} is invalid. + * @throws ParseException if the given {@code muscle} is invalid. */ - public static Tag parseTag(String tag) throws ParseException { - requireNonNull(tag); - String trimmedTag = tag.trim(); - if (!Tag.isValidTagName(trimmedTag)) { - throw new ParseException(Tag.MESSAGE_CONSTRAINTS); + public static Muscle parseMuscle(String muscle) throws ParseException { + requireNonNull(muscle); + String trimmedMuscle = muscle.trim(); + if (!Muscle.isValidMuscleName(trimmedMuscle)) { + throw new ParseException(Muscle.MESSAGE_CONSTRAINTS); } - return new Tag(trimmedTag); + return new Muscle(trimmedMuscle); } /** - * Parses {@code Collection tags} into a {@code Set}. + * Parses {@code Collection tags} into a {@code Set}. */ - public static Set parseTags(Collection tags) throws ParseException { - requireNonNull(tags); - final Set tagSet = new HashSet<>(); - for (String tagName : tags) { - tagSet.add(parseTag(tagName)); + public static Set parseMuscles(Collection muscles) throws ParseException { + requireNonNull(muscles); + final Set muscleSet = new HashSet<>(); + for (String muscleName : muscles) { + muscleSet.add(parseMuscle(muscleName)); } - return tagSet; + return muscleSet; } } diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java deleted file mode 100644 index 1a943a0781a..00000000000 --- a/src/main/java/seedu/address/model/AddressBook.java +++ /dev/null @@ -1,120 +0,0 @@ -package seedu.address.model; - -import static java.util.Objects.requireNonNull; - -import java.util.List; - -import javafx.collections.ObservableList; -import seedu.address.model.person.Person; -import seedu.address.model.person.UniquePersonList; - -/** - * Wraps all data at the address-book level - * Duplicates are not allowed (by .isSamePerson comparison) - */ -public class AddressBook implements ReadOnlyAddressBook { - - private final UniquePersonList persons; - - /* - * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication - * between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html - * - * Note that non-static init blocks are not recommended to use. There are other ways to avoid duplication - * among constructors. - */ - { - persons = new UniquePersonList(); - } - - public AddressBook() {} - - /** - * Creates an AddressBook using the Persons in the {@code toBeCopied} - */ - public AddressBook(ReadOnlyAddressBook toBeCopied) { - this(); - resetData(toBeCopied); - } - - //// list overwrite operations - - /** - * Replaces the contents of the person list with {@code persons}. - * {@code persons} must not contain duplicate persons. - */ - public void setPersons(List persons) { - this.persons.setPersons(persons); - } - - /** - * Resets the existing data of this {@code AddressBook} with {@code newData}. - */ - public void resetData(ReadOnlyAddressBook newData) { - requireNonNull(newData); - - setPersons(newData.getPersonList()); - } - - //// person-level operations - - /** - * Returns true if a person with the same identity as {@code person} exists in the address book. - */ - public boolean hasPerson(Person person) { - requireNonNull(person); - return persons.contains(person); - } - - /** - * Adds a person to the address book. - * The person must not already exist in the address book. - */ - public void addPerson(Person p) { - persons.add(p); - } - - /** - * Replaces the given person {@code target} in the list with {@code editedPerson}. - * {@code target} must exist in the address book. - * The person identity of {@code editedPerson} must not be the same as another existing person in the address book. - */ - public void setPerson(Person target, Person editedPerson) { - requireNonNull(editedPerson); - - persons.setPerson(target, editedPerson); - } - - /** - * Removes {@code key} from this {@code AddressBook}. - * {@code key} must exist in the address book. - */ - public void removePerson(Person key) { - persons.remove(key); - } - - //// util methods - - @Override - public String toString() { - return persons.asUnmodifiableObservableList().size() + " persons"; - // TODO: refine later - } - - @Override - public ObservableList getPersonList() { - return persons.asUnmodifiableObservableList(); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof AddressBook // instanceof handles nulls - && persons.equals(((AddressBook) other).persons)); - } - - @Override - public int hashCode() { - return persons.hashCode(); - } -} diff --git a/src/main/java/seedu/address/model/ExerciseBook.java b/src/main/java/seedu/address/model/ExerciseBook.java new file mode 100644 index 00000000000..cf1792a83fe --- /dev/null +++ b/src/main/java/seedu/address/model/ExerciseBook.java @@ -0,0 +1,121 @@ +package seedu.address.model; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import javafx.collections.ObservableList; +import seedu.address.model.exercise.Exercise; +import seedu.address.model.exercise.UniqueExerciseList; + +/** + * Wraps all data at the exercise-book level + * Duplicates are not allowed (by .isSameExercise comparison) + */ +public class ExerciseBook implements ReadOnlyExerciseBook { + + private final UniqueExerciseList exercises; + + /* + * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication + * between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html + * + * Note that non-static init blocks are not recommended to use. There are other ways to avoid duplication + * among constructors. + */ + { + exercises = new UniqueExerciseList(); + } + + public ExerciseBook() {} + + /** + * Creates an ExerciseBook using the Exercises in the {@code toBeCopied} + */ + public ExerciseBook(ReadOnlyExerciseBook toBeCopied) { + this(); + resetData(toBeCopied); + } + + //// list overwrite operations + + /** + * Replaces the contents of the person list with {@code exercises}. + * {@code exercises} must not contain duplicate exercises. + */ + public void setExercises(List exercises) { + this.exercises.setExercises(exercises); + } + + /** + * Resets the existing data of this {@code ExerciseBook} with {@code newData}. + */ + public void resetData(ReadOnlyExerciseBook newData) { + requireNonNull(newData); + + setExercises(newData.getExerciseList()); + } + + //// person-level operations + + /** + * Returns true if a exercise with the same identity as {@code exercise} exists in the exercise book. + */ + public boolean hasExercise(Exercise exercise) { + requireNonNull(exercise); + return exercises.contains(exercise); + } + + /** + * Adds an exercise to the exercise book. + * The exercise must not already exist in the exercise book. + */ + public void addExercise(Exercise p) { + exercises.add(p); + } + + /** + * Replaces the given exercise {@code target} in the list with {@code editedExercise}. + * {@code target} must exist in the exercise book. + * The exercise identity of {@code editedExercise} must not be the same as another existing exercise in the + * exercise book. + */ + public void setExercise(Exercise target, Exercise editedExercise) { + requireNonNull(editedExercise); + + exercises.setExercise(target, editedExercise); + } + + /** + * Removes {@code key} from this {@code ExerciseBook}. + * {@code key} must exist in the exercise book. + */ + public void removeExercise(Exercise key) { + exercises.remove(key); + } + + //// util methods + + @Override + public String toString() { + return exercises.asUnmodifiableObservableList().size() + " exercises"; + // TODO: refine later + } + + @Override + public ObservableList getExerciseList() { + return exercises.asUnmodifiableObservableList(); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ExerciseBook // instanceof handles nulls + && exercises.equals(((ExerciseBook) other).exercises)); + } + + @Override + public int hashCode() { + return exercises.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index d54df471c1f..41995f440a0 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -5,14 +5,14 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; -import seedu.address.model.person.Person; +import seedu.address.model.exercise.Exercise; /** * The API of the Model component. */ public interface Model { /** {@code Predicate} that always evaluate to true */ - Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; + Predicate PREDICATE_SHOW_ALL_EXERCISES = unused -> true; /** * Replaces user prefs data with the data in {@code userPrefs}. @@ -35,53 +35,57 @@ public interface Model { void setGuiSettings(GuiSettings guiSettings); /** - * Returns the user prefs' address book file path. + * Returns the user prefs' exercise book file path. */ - Path getAddressBookFilePath(); + Path getExerciseBookFilePath(); /** - * Sets the user prefs' address book file path. + * Sets the user prefs' exercise book file path. */ - void setAddressBookFilePath(Path addressBookFilePath); + void setExerciseBookFilePath(Path exerciseBookFilePath); /** - * Replaces address book data with the data in {@code addressBook}. + * Replaces exercise book data with the data in {@code anotherBook}. */ - void setAddressBook(ReadOnlyAddressBook addressBook); + void setExerciseBook(ReadOnlyExerciseBook anotherBook); - /** Returns the AddressBook */ - ReadOnlyAddressBook getAddressBook(); + /** Returns the data in the exercise book */ + ReadOnlyExerciseBook getAllData(); /** - * Returns true if a person with the same identity as {@code person} exists in the address book. + * Returns true if an exercise with the same identity as {@code exercise} exists in the exercise book. */ - boolean hasPerson(Person person); + boolean hasExercise(Exercise exercise); /** - * Deletes the given person. - * The person must exist in the address book. + * Deletes the given exercise. + * The exercise must exist in the exercise book. */ - void deletePerson(Person target); + void deleteExercise(Exercise target); /** - * Adds the given person. - * {@code person} must not already exist in the address book. + * Adds the given exercise. + * {@code exercise} must not already exist in exercise book. */ - void addPerson(Person person); + void addExercise(Exercise exercise); /** - * Replaces the given person {@code target} with {@code editedPerson}. - * {@code target} must exist in the address book. - * The person identity of {@code editedPerson} must not be the same as another existing person in the address book. + * Replaces the given exercise {@code target} with {@code editedExercise}. + * {@code target} must exist in exercise book. + * The exercise identity of {@code editedExercise} must not be the same as another existing exercise in + * the exercise book. */ - void setPerson(Person target, Person editedPerson); + void setExercise(Exercise target, Exercise editedExercise); - /** Returns an unmodifiable view of the filtered person list */ - ObservableList getFilteredPersonList(); + /** Returns an unmodifiable view of the filtered exercise list */ + ObservableList getFilteredExerciseList(); + + ObservableList getSortedExerciseList(); /** - * Updates the filter of the filtered person list to filter by the given {@code predicate}. + * Updates the filter of the filtered exercise list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. */ - void updateFilteredPersonList(Predicate predicate); + void updateFilteredExerciseList(Predicate predicate); + } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 0650c954f5c..ba10d65f6a7 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -9,9 +9,10 @@ import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; +import javafx.collections.transformation.SortedList; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; -import seedu.address.model.person.Person; +import seedu.address.model.exercise.Exercise; /** * Represents the in-memory model of the address book data. @@ -19,26 +20,29 @@ public class ModelManager implements Model { private static final Logger logger = LogsCenter.getLogger(ModelManager.class); - private final AddressBook addressBook; + private final ExerciseBook exerciseBook; private final UserPrefs userPrefs; - private final FilteredList filteredPersons; + private final FilteredList filteredExercises; + private final SortedList sortedExercises; /** - * Initializes a ModelManager with the given addressBook and userPrefs. + * Initializes a ModelManager with the given exerciseBook and userPrefs. */ - public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) { + public ModelManager(ReadOnlyExerciseBook addressBook, ReadOnlyUserPrefs userPrefs) { super(); requireAllNonNull(addressBook, userPrefs); logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); - this.addressBook = new AddressBook(addressBook); + this.exerciseBook = new ExerciseBook(addressBook); this.userPrefs = new UserPrefs(userPrefs); - filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); + filteredExercises = new FilteredList<>(this.exerciseBook.getExerciseList()); + sortedExercises = new SortedList<>(this.exerciseBook.getExerciseList()); + } public ModelManager() { - this(new AddressBook(), new UserPrefs()); + this(new ExerciseBook(), new UserPrefs()); } //=========== UserPrefs ================================================================================== @@ -66,67 +70,73 @@ public void setGuiSettings(GuiSettings guiSettings) { } @Override - public Path getAddressBookFilePath() { - return userPrefs.getAddressBookFilePath(); + public Path getExerciseBookFilePath() { + return userPrefs.getExerciseBookFilePath(); } @Override - public void setAddressBookFilePath(Path addressBookFilePath) { - requireNonNull(addressBookFilePath); - userPrefs.setAddressBookFilePath(addressBookFilePath); + public void setExerciseBookFilePath(Path exerciseBookFilePath) { + requireNonNull(exerciseBookFilePath); + userPrefs.setExerciseBookFilePath(exerciseBookFilePath); } - //=========== AddressBook ================================================================================ + //=========== ExerciseBook ================================================================================ @Override - public void setAddressBook(ReadOnlyAddressBook addressBook) { - this.addressBook.resetData(addressBook); + public void setExerciseBook(ReadOnlyExerciseBook anotherBook) { + this.exerciseBook.resetData(anotherBook); } @Override - public ReadOnlyAddressBook getAddressBook() { - return addressBook; + public ReadOnlyExerciseBook getAllData() { + return exerciseBook; } @Override - public boolean hasPerson(Person person) { - requireNonNull(person); - return addressBook.hasPerson(person); + public boolean hasExercise(Exercise exercise) { + requireNonNull(exercise); + return exerciseBook.hasExercise(exercise); } @Override - public void deletePerson(Person target) { - addressBook.removePerson(target); + public void deleteExercise(Exercise target) { + exerciseBook.removeExercise(target); } - @Override - public void addPerson(Person person) { - addressBook.addPerson(person); - updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + /** + * Adds an {@code Exercise} object into the exercise book. + */ + public void addExercise(Exercise exercise) { + exerciseBook.addExercise(exercise); + updateFilteredExerciseList(PREDICATE_SHOW_ALL_EXERCISES); } - @Override - public void setPerson(Person target, Person editedPerson) { - requireAllNonNull(target, editedPerson); + public void setExercise(Exercise target, Exercise editedExercise) { + requireAllNonNull(target, editedExercise); - addressBook.setPerson(target, editedPerson); + exerciseBook.setExercise(target, editedExercise); } - //=========== Filtered Person List Accessors ============================================================= + //=========== Filtered Exercise List Accessors ============================================================= /** - * Returns an unmodifiable view of the list of {@code Person} backed by the internal list of + * Returns an unmodifiable view of the list of {@code Exercise} backed by the internal list of * {@code versionedAddressBook} */ @Override - public ObservableList getFilteredPersonList() { - return filteredPersons; + public ObservableList getFilteredExerciseList() { + return filteredExercises; } @Override - public void updateFilteredPersonList(Predicate predicate) { + public ObservableList getSortedExerciseList() { + return sortedExercises; + } + + @Override + public void updateFilteredExerciseList(Predicate predicate) { requireNonNull(predicate); - filteredPersons.setPredicate(predicate); + filteredExercises.setPredicate(predicate); } @Override @@ -143,9 +153,9 @@ public boolean equals(Object obj) { // state check ModelManager other = (ModelManager) obj; - return addressBook.equals(other.addressBook) + return exerciseBook.equals(other.exerciseBook) && userPrefs.equals(other.userPrefs) - && filteredPersons.equals(other.filteredPersons); + && filteredExercises.equals(other.filteredExercises) + && sortedExercises.equals(other.sortedExercises); } - } diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyExerciseBook.java similarity index 65% rename from src/main/java/seedu/address/model/ReadOnlyAddressBook.java rename to src/main/java/seedu/address/model/ReadOnlyExerciseBook.java index 6ddc2cd9a29..51166f94dc6 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyExerciseBook.java @@ -1,17 +1,17 @@ package seedu.address.model; import javafx.collections.ObservableList; -import seedu.address.model.person.Person; +import seedu.address.model.exercise.Exercise; /** * Unmodifiable view of an address book */ -public interface ReadOnlyAddressBook { +public interface ReadOnlyExerciseBook { /** * Returns an unmodifiable view of the persons list. * This list will not contain any duplicate persons. */ - ObservableList getPersonList(); + ObservableList getExerciseList(); } diff --git a/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java b/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java index befd58a4c73..deb4f8e9863 100644 --- a/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java +++ b/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java @@ -11,6 +11,6 @@ public interface ReadOnlyUserPrefs { GuiSettings getGuiSettings(); - Path getAddressBookFilePath(); + Path getExerciseBookFilePath(); } diff --git a/src/main/java/seedu/address/model/UserPrefs.java b/src/main/java/seedu/address/model/UserPrefs.java index 25a5fd6eab9..9f6a194b0b4 100644 --- a/src/main/java/seedu/address/model/UserPrefs.java +++ b/src/main/java/seedu/address/model/UserPrefs.java @@ -14,7 +14,7 @@ public class UserPrefs implements ReadOnlyUserPrefs { private GuiSettings guiSettings = new GuiSettings(); - private Path addressBookFilePath = Paths.get("data" , "addressbook.json"); + private Path exerciseBookFilePath = Paths.get("data" , "addressbook.json"); /** * Creates a {@code UserPrefs} with default values. @@ -35,7 +35,7 @@ public UserPrefs(ReadOnlyUserPrefs userPrefs) { public void resetData(ReadOnlyUserPrefs newUserPrefs) { requireNonNull(newUserPrefs); setGuiSettings(newUserPrefs.getGuiSettings()); - setAddressBookFilePath(newUserPrefs.getAddressBookFilePath()); + setExerciseBookFilePath(newUserPrefs.getExerciseBookFilePath()); } public GuiSettings getGuiSettings() { @@ -47,13 +47,13 @@ public void setGuiSettings(GuiSettings guiSettings) { this.guiSettings = guiSettings; } - public Path getAddressBookFilePath() { - return addressBookFilePath; + public Path getExerciseBookFilePath() { + return exerciseBookFilePath; } - public void setAddressBookFilePath(Path addressBookFilePath) { - requireNonNull(addressBookFilePath); - this.addressBookFilePath = addressBookFilePath; + public void setExerciseBookFilePath(Path exerciseBookFilePath) { + requireNonNull(exerciseBookFilePath); + this.exerciseBookFilePath = exerciseBookFilePath; } @Override @@ -68,19 +68,19 @@ public boolean equals(Object other) { UserPrefs o = (UserPrefs) other; return guiSettings.equals(o.guiSettings) - && addressBookFilePath.equals(o.addressBookFilePath); + && exerciseBookFilePath.equals(o.exerciseBookFilePath); } @Override public int hashCode() { - return Objects.hash(guiSettings, addressBookFilePath); + return Objects.hash(guiSettings, exerciseBookFilePath); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Gui Settings : " + guiSettings); - sb.append("\nLocal data file location : " + addressBookFilePath); + sb.append("\nLocal data file location : " + exerciseBookFilePath); return sb.toString(); } diff --git a/src/main/java/seedu/address/model/exercise/Calories.java b/src/main/java/seedu/address/model/exercise/Calories.java new file mode 100644 index 00000000000..7403b5915fb --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/Calories.java @@ -0,0 +1,52 @@ +package seedu.address.model.exercise; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents the estimated amount of calories burnt in an exercise. + * Guarantees: immutable; is valid as declared in {@link #isValidCalories(String)} + */ +public class Calories extends Property { + + public static final String MESSAGE_CONSTRAINTS = + "Calories should only contain numbers"; + public static final String VALIDATION_REGEX = "\\d+"; + public final String value; + + /** + * Constructs a {@code Calories}. + * + * @param calories A valid phone number. + */ + public Calories(String calories) { + requireNonNull(calories); + checkArgument(isValidCalories(calories), MESSAGE_CONSTRAINTS); + value = calories; + } + + /** + * Returns true if a given string is a valid phone number. + */ + public static boolean isValidCalories(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Calories // instanceof handles nulls + && value.equals(((Calories) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/exercise/Date.java b/src/main/java/seedu/address/model/exercise/Date.java new file mode 100644 index 00000000000..534741f36b7 --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/Date.java @@ -0,0 +1,60 @@ +package seedu.address.model.exercise; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Represents an Exercise's date in ExerHealth. + * Guarantees: immutable; is valid as declared in {@link #isValidDate(String)} + */ +public class Date extends Property { + + public static final String MESSAGE_CONSTRAINTS = "Dates should be of the format dd/MM/yyyy and must be valid."; + private static final String VALIDATION_REGEX = "dd/MM/yyyy"; + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(VALIDATION_REGEX); + public final LocalDate value; + + /** + * Constructs a {@code Date}. + * + * @param date A valid date. + */ + public Date(String date) { + requireNonNull(date); + checkArgument(isValidDate(date), MESSAGE_CONSTRAINTS); + value = LocalDate.parse(date, formatter); + } + + /** + * Returns if a given string is a valid date. + */ + public static boolean isValidDate(String test) { + try { + LocalDate.parse(test, formatter); + return true; + } catch (DateTimeParseException e) { + return false; + } + } + + @Override + public String toString() { + return value.format(formatter); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Date // instanceof handles nulls + && value.equals(((Date) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/exercise/Exercise.java b/src/main/java/seedu/address/model/exercise/Exercise.java new file mode 100644 index 00000000000..3d5efd3a673 --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/Exercise.java @@ -0,0 +1,120 @@ +package seedu.address.model.exercise; + +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import seedu.address.model.tag.Muscle; + +/** + * Represents a Person in the quantity book. + * Guarantees: details are present and not null, field values are validated, immutable. + */ +public class Exercise { + + // Identity fields + private final Name name; + private final Date date; + + // Data fields + private final Quantity quantity; + private final Calories calories; + private final Set muscles = new HashSet<>(); + + /** + * Every field must be present and not null. + */ + public Exercise(Name name, Date date, Calories calories, Quantity quantity, Set muscles) { + requireAllNonNull(name, date, calories, quantity, muscles); + this.name = name; + this.date = date; + this.calories = calories; + this.quantity = quantity; + this.muscles.addAll(muscles); + } + + public Name getName() { + return name; + } + + public Calories getCalories() { + return calories; + } + + public Date getDate() { + return date; + } + + public Quantity getQuantity() { + return quantity; + } + + /** + * Returns an immutable tag set, which throws {@code UnsupportedOperationException} + * if modification is attempted. + */ + public Set getMuscles() { + return Collections.unmodifiableSet(muscles); + } + + /** + * Returns true if both persons of the same name have at least one other identity field that is the same. + * This defines a weaker notion of equality between two persons. + */ + public boolean isSameExercise(Exercise otherExercise) { + if (otherExercise == this) { + return true; + } + + return otherExercise != null + && otherExercise.getName().equals(getName()) + && otherExercise.getDate().equals(getDate()); + } + + /** + * Returns true if both persons have the same identity and data fields. + * This defines a stronger notion of equality between two persons. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof Exercise)) { + return false; + } + + Exercise otherExercise = (Exercise) other; + return otherExercise.getName().equals(getName()) + && otherExercise.getCalories().equals(getCalories()) + && otherExercise.getDate().equals(getDate()) + && otherExercise.getQuantity().equals(getQuantity()) + && otherExercise.getMuscles().equals(getMuscles()); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(name, date, calories, quantity, muscles); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append(getName()) + .append(" Date: ") + .append(getDate()) + .append(" Calories: ") + .append(getCalories()) + .append(" Quantity: ") + .append(getQuantity()) + .append(" Muscle(s): "); + getMuscles().forEach(builder::append); + return builder.toString(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/exercise/Name.java similarity index 84% rename from src/main/java/seedu/address/model/person/Name.java rename to src/main/java/seedu/address/model/exercise/Name.java index 79244d71cf7..43d04b916c8 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/exercise/Name.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.exercise; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; @@ -7,16 +7,16 @@ * Represents a Person's name in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidName(String)} */ -public class Name { +public class Name extends Property { public static final String MESSAGE_CONSTRAINTS = - "Names should only contain alphanumeric characters and spaces, and it should not be blank"; + "Names should only contain alphabets 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 VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + public static final String VALIDATION_REGEX = "^[ A-Za-z]+$"; public final String fullName; diff --git a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/exercise/NameContainsKeywordsPredicate.java similarity index 85% rename from src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/exercise/NameContainsKeywordsPredicate.java index c9b5868427c..a669f4014b0 100644 --- a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/exercise/NameContainsKeywordsPredicate.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.exercise; import java.util.List; import java.util.function.Predicate; @@ -8,7 +8,7 @@ /** * Tests that a {@code Person}'s {@code Name} matches any of the keywords given. */ -public class NameContainsKeywordsPredicate implements Predicate { +public class NameContainsKeywordsPredicate implements Predicate { private final List keywords; public NameContainsKeywordsPredicate(List keywords) { @@ -16,9 +16,9 @@ public NameContainsKeywordsPredicate(List keywords) { } @Override - public boolean test(Person person) { + public boolean test(Exercise exercise) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getName().fullName, keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(exercise.getName().fullName, keyword)); } @Override diff --git a/src/main/java/seedu/address/model/exercise/Property.java b/src/main/java/seedu/address/model/exercise/Property.java new file mode 100644 index 00000000000..0e8a8e2bc7c --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/Property.java @@ -0,0 +1,13 @@ +package seedu.address.model.exercise; + +/** + * Represents a property of an {@code Exercise} object. + */ +public abstract class Property { + + public abstract boolean equals(Object other); + + public abstract String toString(); + + public abstract int hashCode(); +} diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/exercise/Quantity.java similarity index 50% rename from src/main/java/seedu/address/model/person/Address.java rename to src/main/java/seedu/address/model/exercise/Quantity.java index 60472ca22a0..c16b3c8717f 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/exercise/Quantity.java @@ -1,15 +1,15 @@ -package seedu.address.model.person; +package seedu.address.model.exercise; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; /** - * Represents a Person's address in the address book. - * Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} + * Represents a the quantity of an exercise done in the exercise book. + * Guarantees: immutable; is valid as declared in {@link #isValidQuantity(String)} */ -public class Address { +public class Quantity extends Property { - public static final String MESSAGE_CONSTRAINTS = "Addresses can take any values, and it should not be blank"; + public static final String MESSAGE_CONSTRAINTS = "Quantity can take any values, and it should not be blank"; /* * The first character of the address must not be a whitespace, @@ -20,20 +20,20 @@ public class Address { public final String value; /** - * Constructs an {@code Address}. + * Constructs an {@code Quantity}. * - * @param address A valid address. + * @param quantity A valid quantity. */ - public Address(String address) { - requireNonNull(address); - checkArgument(isValidAddress(address), MESSAGE_CONSTRAINTS); - value = address; + public Quantity(String quantity) { + requireNonNull(quantity); + checkArgument(isValidQuantity(quantity), MESSAGE_CONSTRAINTS); + value = quantity; } /** - * Returns true if a given string is a valid email. + * Returns true if a given string is a valid quantity. */ - public static boolean isValidAddress(String test) { + public static boolean isValidQuantity(String test) { return test.matches(VALIDATION_REGEX); } @@ -45,8 +45,8 @@ public String toString() { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof Address // instanceof handles nulls - && value.equals(((Address) other).value)); // state check + || (other instanceof Quantity // instanceof handles nulls + && value.equals(((Quantity) other).value)); // state check } @Override diff --git a/src/main/java/seedu/address/model/exercise/UniqueExerciseList.java b/src/main/java/seedu/address/model/exercise/UniqueExerciseList.java new file mode 100644 index 00000000000..0a98d338670 --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/UniqueExerciseList.java @@ -0,0 +1,138 @@ +package seedu.address.model.exercise; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.Iterator; +import java.util.List; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import seedu.address.model.exercise.exceptions.DuplicateExerciseException; +import seedu.address.model.exercise.exceptions.ExerciseNotFoundException; + +/** + * A list of exercises that enforces uniqueness between its elements and does not allow nulls. + * An exercise is considered unique by comparing using {@code Exercise#isSameExercise(Exercise)}. + * As such, adding and updating of exercises uses Exercise#isSameExercise(Exercise) for equality so as to ensure that + * the exercise being added or updated is unique in terms of identity in the UniqueExerciseList. + * However, the removal of an exercise uses Exercise#equals(Object) so as to ensure that the exercise with exactly the + * same fields will be removed. + * + * Supports a minimal set of list operations. + * + * @see Exercise#isSameExercise(Exercise) + */ +public class UniqueExerciseList implements Iterable { + + private final ObservableList internalList = FXCollections.observableArrayList(); + private final ObservableList internalUnmodifiableList = + FXCollections.unmodifiableObservableList(internalList); + + /** + * Returns true if the list contains an equivalent exercise as the given argument. + */ + public boolean contains(Exercise toCheck) { + requireNonNull(toCheck); + return internalList.stream().anyMatch(toCheck::isSameExercise); + } + + /** + * Adds an exercise to the list. + * The person must not already exist in the list. + */ + public void add(Exercise toAdd) { + requireNonNull(toAdd); + if (contains(toAdd)) { + throw new DuplicateExerciseException(); + } + internalList.add(toAdd); + } + + /** + * Replaces the exercise {@code target} in the list with {@code editedExercise}. + * {@code target} must exist in the list. + * The exercise identity of {@code editedExercise} must not be the same as another existing exercise in the list. + */ + public void setExercise(Exercise target, Exercise editedExercise) { + requireAllNonNull(target, editedExercise); + + int index = internalList.indexOf(target); + if (index == -1) { + throw new ExerciseNotFoundException(); + } + + if (!target.isSameExercise(editedExercise) && contains(editedExercise)) { + throw new DuplicateExerciseException(); + } + + internalList.set(index, editedExercise); + } + + /** + * Removes the equivalent exercise from the list. + * The exercise must exist in the list. + */ + public void remove(Exercise toRemove) { + requireNonNull(toRemove); + if (!internalList.remove(toRemove)) { + throw new ExerciseNotFoundException(); + } + } + + public void setExercises(UniqueExerciseList replacement) { + requireNonNull(replacement); + internalList.setAll(replacement.internalList); + } + + /** + * Replaces the contents of this list with {@code exercises}. + * {@code exercises} must not contain duplicate exercises. + */ + public void setExercises(List exercises) { + requireAllNonNull(exercises); + if (!exercisesAreUnique(exercises)) { + throw new DuplicateExerciseException(); + } + + internalList.setAll(exercises); + } + + /** + * Returns the backing list as an unmodifiable {@code ObservableList}. + */ + public ObservableList asUnmodifiableObservableList() { + return internalUnmodifiableList; + } + + @Override + public Iterator iterator() { + return internalList.iterator(); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof UniqueExerciseList // instanceof handles nulls + && internalList.equals(((UniqueExerciseList) other).internalList)); + } + + @Override + public int hashCode() { + return internalList.hashCode(); + } + + /** + * Returns true if {@code persons} contains only unique exercises. + */ + private boolean exercisesAreUnique(List exercises) { + for (int i = 0; i < exercises.size() - 1; i++) { + for (int j = i + 1; j < exercises.size(); j++) { + if (exercises.get(i).isSameExercise(exercises.get(j))) { + return false; + } + } + } + return true; + } +} diff --git a/src/main/java/seedu/address/model/exercise/exceptions/DuplicateExerciseException.java b/src/main/java/seedu/address/model/exercise/exceptions/DuplicateExerciseException.java new file mode 100644 index 00000000000..d978fd71378 --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/exceptions/DuplicateExerciseException.java @@ -0,0 +1,11 @@ +package seedu.address.model.exercise.exceptions; + +/** + * Signals that the operation will result in duplicate exercises (Exercises are considered duplicates if they have + * the same identity). + */ +public class DuplicateExerciseException extends RuntimeException { + public DuplicateExerciseException() { + super("Operation would result in duplicate exercises."); + } +} diff --git a/src/main/java/seedu/address/model/exercise/exceptions/ExerciseNotFoundException.java b/src/main/java/seedu/address/model/exercise/exceptions/ExerciseNotFoundException.java new file mode 100644 index 00000000000..6299f396162 --- /dev/null +++ b/src/main/java/seedu/address/model/exercise/exceptions/ExerciseNotFoundException.java @@ -0,0 +1,6 @@ +package seedu.address.model.exercise.exceptions; + +/** + * Signals that the operation is unable to find the specified exercise. + */ +public class ExerciseNotFoundException extends RuntimeException {} diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java deleted file mode 100644 index a5bbe0b6a5f..00000000000 --- a/src/main/java/seedu/address/model/person/Email.java +++ /dev/null @@ -1,67 +0,0 @@ -package seedu.address.model.person; - -import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.AppUtil.checkArgument; - -/** - * Represents a Person's email in the address book. - * Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} - */ -public class Email { - - private static final String SPECIAL_CHARACTERS = "!#$%&'*+/=?`{|}~^.-"; - public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain " - + "and adhere to the following constraints:\n" - + "1. The local-part should only contain alphanumeric characters and these special characters, excluding " - + "the parentheses, (" + SPECIAL_CHARACTERS + ") .\n" - + "2. This is followed by a '@' and then a domain name. " - + "The domain name must:\n" - + " - be at least 2 characters long\n" - + " - start and end with alphanumeric characters\n" - + " - consist of alphanumeric characters, a period or a hyphen for the characters in between, if any."; - // alphanumeric and special characters - private static final String LOCAL_PART_REGEX = "^[\\w" + SPECIAL_CHARACTERS + "]+"; - private static final String DOMAIN_FIRST_CHARACTER_REGEX = "[^\\W_]"; // alphanumeric characters except underscore - private static final String DOMAIN_MIDDLE_REGEX = "[a-zA-Z0-9.-]*"; // alphanumeric, period and hyphen - private static final String DOMAIN_LAST_CHARACTER_REGEX = "[^\\W_]$"; - public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" - + DOMAIN_FIRST_CHARACTER_REGEX + DOMAIN_MIDDLE_REGEX + DOMAIN_LAST_CHARACTER_REGEX; - - public final String value; - - /** - * Constructs an {@code Email}. - * - * @param email A valid email address. - */ - public Email(String email) { - requireNonNull(email); - checkArgument(isValidEmail(email), MESSAGE_CONSTRAINTS); - value = email; - } - - /** - * Returns if a given string is a valid email. - */ - public static boolean isValidEmail(String test) { - return test.matches(VALIDATION_REGEX); - } - - @Override - public String toString() { - return value; - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof Email // instanceof handles nulls - && value.equals(((Email) other).value)); // state check - } - - @Override - public int hashCode() { - return value.hashCode(); - } - -} diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java deleted file mode 100644 index 557a7a60cd5..00000000000 --- a/src/main/java/seedu/address/model/person/Person.java +++ /dev/null @@ -1,120 +0,0 @@ -package seedu.address.model.person; - -import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import seedu.address.model.tag.Tag; - -/** - * Represents a Person in the address book. - * Guarantees: details are present and not null, field values are validated, immutable. - */ -public class Person { - - // Identity fields - private final Name name; - private final Phone phone; - private final Email email; - - // Data fields - private final Address address; - 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); - this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - this.tags.addAll(tags); - } - - public Name getName() { - return name; - } - - 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. - */ - public Set getTags() { - return Collections.unmodifiableSet(tags); - } - - /** - * Returns true if both persons of the same name have at least one other identity field that is the same. - * This defines a weaker notion of equality between two persons. - */ - public boolean isSamePerson(Person otherPerson) { - if (otherPerson == this) { - return true; - } - - return otherPerson != null - && otherPerson.getName().equals(getName()) - && (otherPerson.getPhone().equals(getPhone()) || otherPerson.getEmail().equals(getEmail())); - } - - /** - * Returns true if both persons have the same identity and data fields. - * This defines a stronger notion of equality between two persons. - */ - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - if (!(other instanceof Person)) { - return false; - } - - Person otherPerson = (Person) other; - return otherPerson.getName().equals(getName()) - && otherPerson.getPhone().equals(getPhone()) - && otherPerson.getEmail().equals(getEmail()) - && otherPerson.getAddress().equals(getAddress()) - && 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); - } - - @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(" Tags: "); - getTags().forEach(builder::append); - return builder.toString(); - } - -} diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java deleted file mode 100644 index 872c76b382f..00000000000 --- a/src/main/java/seedu/address/model/person/Phone.java +++ /dev/null @@ -1,53 +0,0 @@ -package seedu.address.model.person; - -import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.AppUtil.checkArgument; - -/** - * Represents a Person's phone number in the address book. - * Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)} - */ -public class Phone { - - - public static final String MESSAGE_CONSTRAINTS = - "Phone numbers should only contain numbers, and it should be at least 3 digits long"; - public static final String VALIDATION_REGEX = "\\d{3,}"; - public final String value; - - /** - * Constructs a {@code Phone}. - * - * @param phone A valid phone number. - */ - public Phone(String phone) { - requireNonNull(phone); - checkArgument(isValidPhone(phone), MESSAGE_CONSTRAINTS); - value = phone; - } - - /** - * Returns true if a given string is a valid phone number. - */ - public static boolean isValidPhone(String test) { - return test.matches(VALIDATION_REGEX); - } - - @Override - public String toString() { - return value; - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof Phone // instanceof handles nulls - && value.equals(((Phone) other).value)); // state check - } - - @Override - public int hashCode() { - return value.hashCode(); - } - -} diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java deleted file mode 100644 index 0fee4fe57e6..00000000000 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ /dev/null @@ -1,137 +0,0 @@ -package seedu.address.model.person; - -import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; - -import java.util.Iterator; -import java.util.List; - -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import seedu.address.model.person.exceptions.DuplicatePersonException; -import seedu.address.model.person.exceptions.PersonNotFoundException; - -/** - * A list of persons that enforces uniqueness between its elements and does not allow nulls. - * A person is considered unique by comparing using {@code Person#isSamePerson(Person)}. As such, adding and updating of - * persons uses Person#isSamePerson(Person) for equality so as to ensure that the person being added or updated is - * unique in terms of identity in the UniquePersonList. However, the removal of a person uses Person#equals(Object) so - * as to ensure that the person with exactly the same fields will be removed. - * - * Supports a minimal set of list operations. - * - * @see Person#isSamePerson(Person) - */ -public class UniquePersonList implements Iterable { - - private final ObservableList internalList = FXCollections.observableArrayList(); - private final ObservableList internalUnmodifiableList = - FXCollections.unmodifiableObservableList(internalList); - - /** - * Returns true if the list contains an equivalent person as the given argument. - */ - public boolean contains(Person toCheck) { - requireNonNull(toCheck); - return internalList.stream().anyMatch(toCheck::isSamePerson); - } - - /** - * Adds a person to the list. - * The person must not already exist in the list. - */ - public void add(Person toAdd) { - requireNonNull(toAdd); - if (contains(toAdd)) { - throw new DuplicatePersonException(); - } - internalList.add(toAdd); - } - - /** - * Replaces the person {@code target} in the list with {@code editedPerson}. - * {@code target} must exist in the list. - * The person identity of {@code editedPerson} must not be the same as another existing person in the list. - */ - public void setPerson(Person target, Person editedPerson) { - requireAllNonNull(target, editedPerson); - - int index = internalList.indexOf(target); - if (index == -1) { - throw new PersonNotFoundException(); - } - - if (!target.isSamePerson(editedPerson) && contains(editedPerson)) { - throw new DuplicatePersonException(); - } - - internalList.set(index, editedPerson); - } - - /** - * Removes the equivalent person from the list. - * The person must exist in the list. - */ - public void remove(Person toRemove) { - requireNonNull(toRemove); - if (!internalList.remove(toRemove)) { - throw new PersonNotFoundException(); - } - } - - public void setPersons(UniquePersonList replacement) { - requireNonNull(replacement); - internalList.setAll(replacement.internalList); - } - - /** - * Replaces the contents of this list with {@code persons}. - * {@code persons} must not contain duplicate persons. - */ - public void setPersons(List persons) { - requireAllNonNull(persons); - if (!personsAreUnique(persons)) { - throw new DuplicatePersonException(); - } - - internalList.setAll(persons); - } - - /** - * Returns the backing list as an unmodifiable {@code ObservableList}. - */ - public ObservableList asUnmodifiableObservableList() { - return internalUnmodifiableList; - } - - @Override - public Iterator iterator() { - return internalList.iterator(); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof UniquePersonList // instanceof handles nulls - && internalList.equals(((UniquePersonList) other).internalList)); - } - - @Override - public int hashCode() { - return internalList.hashCode(); - } - - /** - * Returns true if {@code persons} contains only unique persons. - */ - private boolean personsAreUnique(List persons) { - for (int i = 0; i < persons.size() - 1; i++) { - for (int j = i + 1; j < persons.size(); j++) { - if (persons.get(i).isSamePerson(persons.get(j))) { - return false; - } - } - } - return true; - } -} diff --git a/src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java b/src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java deleted file mode 100644 index d7290f59442..00000000000 --- a/src/main/java/seedu/address/model/person/exceptions/DuplicatePersonException.java +++ /dev/null @@ -1,11 +0,0 @@ -package seedu.address.model.person.exceptions; - -/** - * Signals that the operation will result in duplicate Persons (Persons are considered duplicates if they have the same - * identity). - */ -public class DuplicatePersonException extends RuntimeException { - public DuplicatePersonException() { - super("Operation would result in duplicate persons"); - } -} diff --git a/src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java b/src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java deleted file mode 100644 index fa764426ca7..00000000000 --- a/src/main/java/seedu/address/model/person/exceptions/PersonNotFoundException.java +++ /dev/null @@ -1,6 +0,0 @@ -package seedu.address.model.person.exceptions; - -/** - * Signals that the operation is unable to find the specified person. - */ -public class PersonNotFoundException extends RuntimeException {} diff --git a/src/main/java/seedu/address/model/tag/Muscle.java b/src/main/java/seedu/address/model/tag/Muscle.java new file mode 100644 index 00000000000..9c776079d6e --- /dev/null +++ b/src/main/java/seedu/address/model/tag/Muscle.java @@ -0,0 +1,54 @@ +package seedu.address.model.tag; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Muscle tag in ExerHealth. + * Guarantees: immutable; name is valid as declared in {@link #isValidMuscleName(String)} + */ +public class Muscle { + + public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric"; + public static final String VALIDATION_REGEX = "^[ A-Za-z]+$"; + + public final String muscleName; + + /** + * Constructs a {@code Muscle}. + * + * @param muscleName A valid tag name. + */ + public Muscle(String muscleName) { + requireNonNull(muscleName); + checkArgument(isValidMuscleName(muscleName), MESSAGE_CONSTRAINTS); + this.muscleName = muscleName; + } + + /** + * Returns true if a given string is a valid tag name. + */ + public static boolean isValidMuscleName(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Muscle // instanceof handles nulls + && muscleName.equals(((Muscle) other).muscleName)); // state check + } + + @Override + public int hashCode() { + return muscleName.hashCode(); + } + + /** + * Format state as text for viewing. + */ + public String toString() { + return '[' + muscleName + ']'; + } + +} diff --git a/src/main/java/seedu/address/model/tag/Tag.java b/src/main/java/seedu/address/model/tag/Tag.java deleted file mode 100644 index b0ea7e7dad7..00000000000 --- a/src/main/java/seedu/address/model/tag/Tag.java +++ /dev/null @@ -1,54 +0,0 @@ -package seedu.address.model.tag; - -import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.AppUtil.checkArgument; - -/** - * Represents a Tag in the address book. - * Guarantees: immutable; name is valid as declared in {@link #isValidTagName(String)} - */ -public class Tag { - - public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric"; - public static final String VALIDATION_REGEX = "\\p{Alnum}+"; - - public final String tagName; - - /** - * Constructs a {@code Tag}. - * - * @param tagName A valid tag name. - */ - public Tag(String tagName) { - requireNonNull(tagName); - checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS); - this.tagName = tagName; - } - - /** - * Returns true if a given string is a valid tag name. - */ - public static boolean isValidTagName(String test) { - return test.matches(VALIDATION_REGEX); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof Tag // instanceof handles nulls - && tagName.equals(((Tag) other).tagName)); // state check - } - - @Override - public int hashCode() { - return tagName.hashCode(); - } - - /** - * Format state as text for viewing. - */ - public String toString() { - return '[' + tagName + ']'; - } - -} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..798db20de5d 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -4,57 +4,57 @@ import java.util.Set; import java.util.stream.Collectors; -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.tag.Tag; +import seedu.address.model.ExerciseBook; +import seedu.address.model.ReadOnlyExerciseBook; +import seedu.address.model.exercise.Calories; +import seedu.address.model.exercise.Date; +import seedu.address.model.exercise.Exercise; +import seedu.address.model.exercise.Name; +import seedu.address.model.exercise.Quantity; +import seedu.address.model.tag.Muscle; /** - * Contains utility methods for populating {@code AddressBook} with sample data. + * Contains utility methods for populating {@code ExerciseBook} with sample data. */ public class SampleDataUtil { - public static Person[] getSamplePersons() { - return new Person[] { - 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")), - new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), - new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), - new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), - new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), - 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")) + public static Exercise[] getSampleExercises() { + return new Exercise[]{ + new Exercise(new Name("Rope Skipping"), new Date("26/09/2019"), new Calories("330"), + new Quantity("10 counts of 10"), + getMuscleSet("Legs")), + new Exercise(new Name("Cycling"), new Date("26/09/2019"), new Calories("284"), + new Quantity("Cycled 5km"), + getMuscleSet("Legs")), + new Exercise(new Name("Strength Training"), new Date("26/09/2019"), new Calories("341"), + new Quantity("20 counts of 10"), + getMuscleSet("Chest")), + new Exercise(new Name("Swimming"), new Date("26/09/2019"), new Calories("354"), + new Quantity("10 laps"), + getMuscleSet("Calves")), + new Exercise(new Name("Bench Press"), new Date("26/09/2019"), new Calories("222"), + new Quantity("30 counts"), + getMuscleSet("Triceps")), + new Exercise(new Name("Running"), new Date("26/09/2019"), new Calories("9999999"), + new Quantity("2.4km clocked"), + getMuscleSet("Legs")) }; } - public static ReadOnlyAddressBook getSampleAddressBook() { - AddressBook sampleAb = new AddressBook(); - for (Person samplePerson : getSamplePersons()) { - sampleAb.addPerson(samplePerson); + public static ReadOnlyExerciseBook getSampleExerciseBook() { + ExerciseBook sampleEb = new ExerciseBook(); + for (Exercise sampleExercise : getSampleExercises()) { + sampleEb.addExercise(sampleExercise); } - return sampleAb; + return sampleEb; } /** * Returns a tag set containing the list of strings given. */ - public static Set getTagSet(String... strings) { + public static Set getMuscleSet(String... strings) { return Arrays.stream(strings) - .map(Tag::new) - .collect(Collectors.toSet()); + .map(Muscle::new) + .collect(Collectors.toSet()); } } diff --git a/src/main/java/seedu/address/storage/AddressBookStorage.java b/src/main/java/seedu/address/storage/AddressBookStorage.java deleted file mode 100644 index 4599182b3f9..00000000000 --- a/src/main/java/seedu/address/storage/AddressBookStorage.java +++ /dev/null @@ -1,45 +0,0 @@ -package seedu.address.storage; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Optional; - -import seedu.address.commons.exceptions.DataConversionException; -import seedu.address.model.ReadOnlyAddressBook; - -/** - * Represents a storage for {@link seedu.address.model.AddressBook}. - */ -public interface AddressBookStorage { - - /** - * Returns the file path of the data file. - */ - Path getAddressBookFilePath(); - - /** - * Returns AddressBook data as a {@link ReadOnlyAddressBook}. - * Returns {@code Optional.empty()} if storage file is not found. - * @throws DataConversionException if the data in storage is not in the expected format. - * @throws IOException if there was any problem when reading from the storage. - */ - Optional readAddressBook() throws DataConversionException, IOException; - - /** - * @see #getAddressBookFilePath() - */ - Optional readAddressBook(Path filePath) throws DataConversionException, IOException; - - /** - * Saves the given {@link ReadOnlyAddressBook} to the storage. - * @param addressBook cannot be null. - * @throws IOException if there was any problem writing to the file. - */ - void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; - - /** - * @see #saveAddressBook(ReadOnlyAddressBook) - */ - void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException; - -} diff --git a/src/main/java/seedu/address/storage/ExerciseBookStorage.java b/src/main/java/seedu/address/storage/ExerciseBookStorage.java new file mode 100644 index 00000000000..8405ee379d7 --- /dev/null +++ b/src/main/java/seedu/address/storage/ExerciseBookStorage.java @@ -0,0 +1,46 @@ +package seedu.address.storage; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; + +import seedu.address.commons.exceptions.DataConversionException; +import seedu.address.model.ExerciseBook; +import seedu.address.model.ReadOnlyExerciseBook; + +/** + * Represents a storage for {@link ExerciseBook}. + */ +public interface ExerciseBookStorage { + + /** + * Returns the file path of the data file. + */ + Path getExerciseBookFilePath(); + + /** + * Returns ExerciseBook data as a {@link ReadOnlyExerciseBook}. + * Returns {@code Optional.empty()} if storage file is not found. + * @throws DataConversionException if the data in storage is not in the expected format. + * @throws IOException if there was any problem when reading from the storage. + */ + Optional readExerciseBook() throws DataConversionException, IOException; + + /** + * @see #getExerciseBookFilePath() + */ + Optional readExerciseBook(Path filePath) throws DataConversionException, IOException; + + /** + * Saves the given {@link ReadOnlyExerciseBook} to the storage. + * @param exerciseBook cannot be null. + * @throws IOException if there was any problem writing to the file. + */ + void saveExerciseBook(ReadOnlyExerciseBook exerciseBook) throws IOException; + + /** + * @see #saveExerciseBook(ReadOnlyExerciseBook) + */ + void saveExerciseBook(ReadOnlyExerciseBook exerciseBook, Path filePath) throws IOException; + +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedExercise.java b/src/main/java/seedu/address/storage/JsonAdaptedExercise.java new file mode 100644 index 00000000000..108102b7f6c --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedExercise.java @@ -0,0 +1,113 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.exercise.Calories; +import seedu.address.model.exercise.Date; +import seedu.address.model.exercise.Exercise; +import seedu.address.model.exercise.Name; +import seedu.address.model.exercise.Quantity; +import seedu.address.model.tag.Muscle; + +/** + * Jackson-friendly version of {@link Exercise}. + */ +class JsonAdaptedExercise { + + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Exercise's %s field is missing!"; + + private final String name; + private final String date; + private final String calories; + private final String quantity; + private final List muscles = new ArrayList<>(); + + /** + * Constructs a {@code JsonAdaptedExercise} with the given exercise details. + */ + @JsonCreator + public JsonAdaptedExercise(@JsonProperty("name") String name, @JsonProperty("date") String date, + @JsonProperty("calories") String calories, @JsonProperty("quantity") String quantity, + @JsonProperty("muscles") List muscles) { + this.name = name; + this.date = date; + this.calories = calories; + this.quantity = quantity; + if (muscles != null) { + this.muscles.addAll(muscles); + } + } + + /** + * Converts a given {@code Exercise} into this class for Jackson use. + */ + public JsonAdaptedExercise(Exercise source) { + name = source.getName().fullName; + date = source.getDate().toString(); + calories = source.getCalories().value; + quantity = source.getQuantity().value; + muscles.addAll(source.getMuscles().stream() + .map(JsonAdaptedMuscle::new) + .collect(Collectors.toList())); + } + + /** + * Converts this Jackson-friendly adapted exercise object into the model's {@code Exercise} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted exercise. + */ + public Exercise toModelType() throws IllegalValueException { + final List personMuscles = new ArrayList<>(); + for (JsonAdaptedMuscle tag : muscles) { + personMuscles.add(tag.toModelType()); + } + + if (name == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Name.class.getSimpleName())); + } + if (!Name.isValidName(name)) { + throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); + } + final Name modelName = new Name(name); + + if (date == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Date.class.getSimpleName())); + } + if (!Date.isValidDate(date)) { + throw new IllegalValueException(Date.MESSAGE_CONSTRAINTS); + } + final Date modelDate = new Date(date); + + if (calories == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Calories.class.getSimpleName())); + } + if (!Calories.isValidCalories(calories)) { + throw new IllegalValueException(Calories.MESSAGE_CONSTRAINTS); + } + final Calories modelCalories = new Calories(calories); + + if (quantity == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Quantity.class.getSimpleName())); + } + if (!Quantity.isValidQuantity(quantity)) { + throw new IllegalValueException(Quantity.MESSAGE_CONSTRAINTS); + } + final Quantity modelQuantity = new Quantity(quantity); + + final Set modelMuscles = new HashSet<>(personMuscles); + return new Exercise(modelName, modelDate, modelCalories, modelQuantity, modelMuscles); + } + +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedMuscle.java b/src/main/java/seedu/address/storage/JsonAdaptedMuscle.java new file mode 100644 index 00000000000..429e541f4a2 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedMuscle.java @@ -0,0 +1,48 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.tag.Muscle; + +/** + * Jackson-friendly version of {@link Muscle}. + */ +class JsonAdaptedMuscle { + + private final String muscle; + + /** + * Constructs a {@code JsonAdaptedMuscle} with the given {@code muscle}. + */ + @JsonCreator + public JsonAdaptedMuscle(String muscle) { + this.muscle = muscle; + } + + /** + * Converts a given {@code Muscle} into this class for Jackson use. + */ + public JsonAdaptedMuscle(Muscle source) { + muscle = source.muscleName; + } + + @JsonValue + public String getMuscle() { + return muscle; + } + + /** + * Converts this Jackson-friendly adapted muscle object into the model's {@code Muscle} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted muscle. + */ + public Muscle toModelType() throws IllegalValueException { + if (!Muscle.isValidMuscleName(muscle)) { + throw new IllegalValueException(Muscle.MESSAGE_CONSTRAINTS); + } + return new Muscle(muscle); + } + +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java deleted file mode 100644 index a6321cec2ea..00000000000 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ /dev/null @@ -1,109 +0,0 @@ -package seedu.address.storage; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -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.tag.Tag; - -/** - * Jackson-friendly version of {@link Person}. - */ -class JsonAdaptedPerson { - - public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; - - private final String name; - private final String phone; - private final String email; - private final String address; - private final List tagged = new ArrayList<>(); - - /** - * Constructs a {@code JsonAdaptedPerson} with the given person details. - */ - @JsonCreator - public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tagged") List tagged) { - this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - if (tagged != null) { - this.tagged.addAll(tagged); - } - } - - /** - * Converts a given {@code Person} into this class for Jackson use. - */ - public JsonAdaptedPerson(Person source) { - name = source.getName().fullName; - phone = source.getPhone().value; - email = source.getEmail().value; - address = source.getAddress().value; - tagged.addAll(source.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList())); - } - - /** - * Converts this Jackson-friendly adapted person object into the model's {@code Person} object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted person. - */ - public Person toModelType() throws IllegalValueException { - final List personTags = new ArrayList<>(); - for (JsonAdaptedTag tag : tagged) { - personTags.add(tag.toModelType()); - } - - if (name == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); - } - if (!Name.isValidName(name)) { - throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); - } - final Name modelName = new Name(name); - - if (phone == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); - } - if (!Phone.isValidPhone(phone)) { - throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); - } - final Phone modelPhone = new Phone(phone); - - if (email == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); - } - if (!Email.isValidEmail(email)) { - throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); - } - final Email modelEmail = new Email(email); - - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); - } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); - } - final Address modelAddress = new Address(address); - - final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); - } - -} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTag.java b/src/main/java/seedu/address/storage/JsonAdaptedTag.java deleted file mode 100644 index 0df22bdb754..00000000000 --- a/src/main/java/seedu/address/storage/JsonAdaptedTag.java +++ /dev/null @@ -1,48 +0,0 @@ -package seedu.address.storage; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.tag.Tag; - -/** - * Jackson-friendly version of {@link Tag}. - */ -class JsonAdaptedTag { - - private final String tagName; - - /** - * Constructs a {@code JsonAdaptedTag} with the given {@code tagName}. - */ - @JsonCreator - public JsonAdaptedTag(String tagName) { - this.tagName = tagName; - } - - /** - * Converts a given {@code Tag} into this class for Jackson use. - */ - public JsonAdaptedTag(Tag source) { - tagName = source.tagName; - } - - @JsonValue - public String getTagName() { - return tagName; - } - - /** - * Converts this Jackson-friendly adapted tag object into the model's {@code Tag} object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted tag. - */ - public Tag toModelType() throws IllegalValueException { - if (!Tag.isValidTagName(tagName)) { - throw new IllegalValueException(Tag.MESSAGE_CONSTRAINTS); - } - return new Tag(tagName); - } - -} diff --git a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java b/src/main/java/seedu/address/storage/JsonExerciseBookStorage.java similarity index 54% rename from src/main/java/seedu/address/storage/JsonAddressBookStorage.java rename to src/main/java/seedu/address/storage/JsonExerciseBookStorage.java index dfab9daaa0d..b02327fa3db 100644 --- a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java +++ b/src/main/java/seedu/address/storage/JsonExerciseBookStorage.java @@ -12,41 +12,41 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.FileUtil; import seedu.address.commons.util.JsonUtil; -import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyExerciseBook; /** - * A class to access AddressBook data stored as a json file on the hard disk. + * A class to access ExerciseBook data stored as a json file on the hard disk. */ -public class JsonAddressBookStorage implements AddressBookStorage { +public class JsonExerciseBookStorage implements ExerciseBookStorage { - private static final Logger logger = LogsCenter.getLogger(JsonAddressBookStorage.class); + private static final Logger logger = LogsCenter.getLogger(JsonExerciseBookStorage.class); private Path filePath; - public JsonAddressBookStorage(Path filePath) { + public JsonExerciseBookStorage(Path filePath) { this.filePath = filePath; } - public Path getAddressBookFilePath() { + public Path getExerciseBookFilePath() { return filePath; } @Override - public Optional readAddressBook() throws DataConversionException { - return readAddressBook(filePath); + public Optional readExerciseBook() throws DataConversionException { + return readExerciseBook(filePath); } /** - * Similar to {@link #readAddressBook()}. + * Similar to {@link #readExerciseBook()}. * * @param filePath location of the data. Cannot be null. * @throws DataConversionException if the file is not in the correct format. */ - public Optional readAddressBook(Path filePath) throws DataConversionException { + public Optional readExerciseBook(Path filePath) throws DataConversionException { requireNonNull(filePath); - Optional jsonAddressBook = JsonUtil.readJsonFile( - filePath, JsonSerializableAddressBook.class); + Optional jsonAddressBook = JsonUtil.readJsonFile( + filePath, JsonSerializableExerciseBook.class); if (!jsonAddressBook.isPresent()) { return Optional.empty(); } @@ -60,21 +60,21 @@ public Optional readAddressBook(Path filePath) throws DataC } @Override - public void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException { - saveAddressBook(addressBook, filePath); + public void saveExerciseBook(ReadOnlyExerciseBook exerciseBook) throws IOException { + saveExerciseBook(exerciseBook, filePath); } /** - * Similar to {@link #saveAddressBook(ReadOnlyAddressBook)}. + * Similar to {@link #saveExerciseBook(ReadOnlyExerciseBook)}. * * @param filePath location of the data. Cannot be null. */ - public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException { - requireNonNull(addressBook); + public void saveExerciseBook(ReadOnlyExerciseBook exerciseBook, Path filePath) throws IOException { + requireNonNull(exerciseBook); requireNonNull(filePath); FileUtil.createIfMissing(filePath); - JsonUtil.saveJsonFile(new JsonSerializableAddressBook(addressBook), filePath); + JsonUtil.saveJsonFile(new JsonSerializableExerciseBook(exerciseBook), filePath); } } diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java deleted file mode 100644 index 5efd834091d..00000000000 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ /dev/null @@ -1,60 +0,0 @@ -package seedu.address.storage; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.AddressBook; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; - -/** - * An Immutable AddressBook that is serializable to JSON format. - */ -@JsonRootName(value = "addressbook") -class JsonSerializableAddressBook { - - public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; - - private final List persons = new ArrayList<>(); - - /** - * Constructs a {@code JsonSerializableAddressBook} with the given persons. - */ - @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { - this.persons.addAll(persons); - } - - /** - * Converts a given {@code ReadOnlyAddressBook} into this class for Jackson use. - * - * @param source future changes to this will not affect the created {@code JsonSerializableAddressBook}. - */ - public JsonSerializableAddressBook(ReadOnlyAddressBook source) { - persons.addAll(source.getPersonList().stream().map(JsonAdaptedPerson::new).collect(Collectors.toList())); - } - - /** - * Converts this address book into the model's {@code AddressBook} object. - * - * @throws IllegalValueException if there were any data constraints violated. - */ - public AddressBook toModelType() throws IllegalValueException { - AddressBook addressBook = new AddressBook(); - for (JsonAdaptedPerson jsonAdaptedPerson : persons) { - Person person = jsonAdaptedPerson.toModelType(); - if (addressBook.hasPerson(person)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_PERSON); - } - addressBook.addPerson(person); - } - return addressBook; - } - -} diff --git a/src/main/java/seedu/address/storage/JsonSerializableExerciseBook.java b/src/main/java/seedu/address/storage/JsonSerializableExerciseBook.java new file mode 100644 index 00000000000..e5252b99e81 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonSerializableExerciseBook.java @@ -0,0 +1,60 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.ExerciseBook; +import seedu.address.model.ReadOnlyExerciseBook; +import seedu.address.model.exercise.Exercise; + +/** + * An Immutable ExerciseBook that is serializable to JSON format. + */ +@JsonRootName(value = "addressbook") +class JsonSerializableExerciseBook { + + public static final String MESSAGE_DUPLICATE_EXERCISE = "Exercise list contains duplicate exercise(s)."; + + private final List exercises = new ArrayList<>(); + + /** + * Constructs a {@code JsonSerializableExerciseBook} with the given persons. + */ + @JsonCreator + public JsonSerializableExerciseBook(@JsonProperty("exercises") List exercises) { + this.exercises.addAll(exercises); + } + + /** + * Converts a given {@code ReadOnlyExerciseBook} into this class for Jackson use. + * + * @param source future changes to this will not affect the created {@code JsonSerializableExerciseBook}. + */ + public JsonSerializableExerciseBook(ReadOnlyExerciseBook source) { + exercises.addAll(source.getExerciseList().stream().map(JsonAdaptedExercise::new).collect(Collectors.toList())); + } + + /** + * Converts this address book into the model's {@code ExerciseBook} object. + * + * @throws IllegalValueException if there were any data constraints violated. + */ + public ExerciseBook toModelType() throws IllegalValueException { + ExerciseBook exerciseBook = new ExerciseBook(); + for (JsonAdaptedExercise jsonAdaptedExercise : exercises) { + Exercise exercise = jsonAdaptedExercise.toModelType(); + if (exerciseBook.hasExercise(exercise)) { + throw new IllegalValueException(MESSAGE_DUPLICATE_EXERCISE); + } + exerciseBook.addExercise(exercise); + } + return exerciseBook; + } + +} diff --git a/src/main/java/seedu/address/storage/Storage.java b/src/main/java/seedu/address/storage/Storage.java index beda8bd9f11..21dcd859e86 100644 --- a/src/main/java/seedu/address/storage/Storage.java +++ b/src/main/java/seedu/address/storage/Storage.java @@ -5,14 +5,14 @@ import java.util.Optional; import seedu.address.commons.exceptions.DataConversionException; -import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyExerciseBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; /** * API of the Storage component */ -public interface Storage extends AddressBookStorage, UserPrefsStorage { +public interface Storage extends ExerciseBookStorage, UserPrefsStorage { @Override Optional readUserPrefs() throws DataConversionException, IOException; @@ -21,12 +21,12 @@ public interface Storage extends AddressBookStorage, UserPrefsStorage { void saveUserPrefs(ReadOnlyUserPrefs userPrefs) throws IOException; @Override - Path getAddressBookFilePath(); + Path getExerciseBookFilePath(); @Override - Optional readAddressBook() throws DataConversionException, IOException; + Optional readExerciseBook() throws DataConversionException, IOException; @Override - void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; + void saveExerciseBook(ReadOnlyExerciseBook exerciseBook) throws IOException; } diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index e4f452b6cbf..d124a04e046 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -7,23 +7,23 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.commons.exceptions.DataConversionException; -import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyExerciseBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; /** - * Manages storage of AddressBook data in local storage. + * Manages storage of ExerciseBook data in local storage. */ public class StorageManager implements Storage { private static final Logger logger = LogsCenter.getLogger(StorageManager.class); - private AddressBookStorage addressBookStorage; + private ExerciseBookStorage exerciseBookStorage; private UserPrefsStorage userPrefsStorage; - public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage) { + public StorageManager(ExerciseBookStorage exerciseBookStorage, UserPrefsStorage userPrefsStorage) { super(); - this.addressBookStorage = addressBookStorage; + this.exerciseBookStorage = exerciseBookStorage; this.userPrefsStorage = userPrefsStorage; } @@ -45,33 +45,33 @@ public void saveUserPrefs(ReadOnlyUserPrefs userPrefs) throws IOException { } - // ================ AddressBook methods ============================== + // ================ ExerciseBook methods ============================== @Override - public Path getAddressBookFilePath() { - return addressBookStorage.getAddressBookFilePath(); + public Path getExerciseBookFilePath() { + return exerciseBookStorage.getExerciseBookFilePath(); } @Override - public Optional readAddressBook() throws DataConversionException, IOException { - return readAddressBook(addressBookStorage.getAddressBookFilePath()); + public Optional readExerciseBook() throws DataConversionException, IOException { + return readExerciseBook(exerciseBookStorage.getExerciseBookFilePath()); } @Override - public Optional readAddressBook(Path filePath) throws DataConversionException, IOException { + public Optional readExerciseBook(Path filePath) throws DataConversionException, IOException { logger.fine("Attempting to read data from file: " + filePath); - return addressBookStorage.readAddressBook(filePath); + return exerciseBookStorage.readExerciseBook(filePath); } @Override - public void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException { - saveAddressBook(addressBook, addressBookStorage.getAddressBookFilePath()); + public void saveExerciseBook(ReadOnlyExerciseBook exerciseBook) throws IOException { + saveExerciseBook(exerciseBook, exerciseBookStorage.getExerciseBookFilePath()); } @Override - public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException { + public void saveExerciseBook(ReadOnlyExerciseBook exerciseBook, Path filePath) throws IOException { logger.fine("Attempting to write to data file: " + filePath); - addressBookStorage.saveAddressBook(addressBook, filePath); + exerciseBookStorage.saveExerciseBook(exerciseBook, filePath); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/ExerciseCard.java similarity index 57% rename from src/main/java/seedu/address/ui/PersonCard.java rename to src/main/java/seedu/address/ui/ExerciseCard.java index 0684b088868..8a0dbb7ba6e 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/ExerciseCard.java @@ -7,14 +7,14 @@ import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; -import seedu.address.model.person.Person; +import seedu.address.model.exercise.Exercise; /** * An UI component that displays information of a {@code Person}. */ -public class PersonCard extends UiPart { +public class ExerciseCard extends UiPart { - private static final String FXML = "PersonListCard.fxml"; + private static final String FXML = "ExerciseListCard.fxml"; /** * Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. @@ -24,7 +24,7 @@ public class PersonCard extends UiPart { * @see The issue on AddressBook level 4 */ - public final Person person; + public final Exercise person; @FXML private HBox cardPane; @@ -33,25 +33,25 @@ public class PersonCard extends UiPart { @FXML private Label id; @FXML - private Label phone; + private Label date; @FXML - private Label address; + private Label calories; @FXML - private Label email; + private Label quantity; @FXML private FlowPane tags; - public PersonCard(Person person, int displayedIndex) { + public ExerciseCard(Exercise exercise, int displayedIndex) { super(FXML); - this.person = person; + this.person = exercise; id.setText(displayedIndex + ". "); - name.setText(person.getName().fullName); - phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); - email.setText(person.getEmail().value); - person.getTags().stream() - .sorted(Comparator.comparing(tag -> tag.tagName)) - .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + name.setText(exercise.getName().fullName); + date.setText(exercise.getDate().toString()); + calories.setText(exercise.getCalories().value + " kcal"); + quantity.setText(exercise.getQuantity().value); + exercise.getMuscles().stream() + .sorted(Comparator.comparing(muscle -> muscle.muscleName)) + .forEach(muscle -> tags.getChildren().add(new Label(muscle.muscleName))); } @Override @@ -62,13 +62,13 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof PersonCard)) { + if (!(other instanceof ExerciseCard)) { return false; } // state check - PersonCard card = (PersonCard) other; + ExerciseCard card = (ExerciseCard) other; return id.getText().equals(card.id.getText()) - && person.equals(card.person); + && person.equals(card.person); } } diff --git a/src/main/java/seedu/address/ui/ExerciseListPanel.java b/src/main/java/seedu/address/ui/ExerciseListPanel.java new file mode 100644 index 00000000000..1a608ef9ebf --- /dev/null +++ b/src/main/java/seedu/address/ui/ExerciseListPanel.java @@ -0,0 +1,46 @@ +package seedu.address.ui; + +import java.util.logging.Logger; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import seedu.address.commons.core.LogsCenter; +import seedu.address.model.exercise.Exercise; + +/** + * Panel containing the list of exercises. + */ +public class ExerciseListPanel extends UiPart { + private static final String FXML = "ExerciseListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(ExerciseListPanel.class); + + @FXML + private ListView exerciseListView; + + public ExerciseListPanel(ObservableList exerciseList) { + super(FXML); + exerciseListView.setItems(exerciseList); + exerciseListView.setCellFactory(listView -> new ExerciseListViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Exercise} using a {@code ExerciseCard}. + */ + class ExerciseListViewCell extends ListCell { + @Override + protected void updateItem(Exercise exercise, boolean empty) { + super.updateItem(exercise, empty); + + if (empty || exercise == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new ExerciseCard(exercise, getIndex() + 1).getRoot()); + } + } + } + +} diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 90bbf11de97..1182f053c13 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -31,7 +31,8 @@ public class MainWindow extends UiPart { private Logic logic; // Independent Ui parts residing in this Ui container - private PersonListPanel personListPanel; + private ExerciseListPanel filteredListPanel; + private ExerciseListPanel sortedListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -42,14 +43,20 @@ public class MainWindow extends UiPart { private MenuItem helpMenuItem; @FXML - private StackPane personListPanelPlaceholder; + private StackPane filteredListPanelPlaceholder; @FXML private StackPane resultDisplayPlaceholder; + @FXML + private StackPane sortedListPanelPlaceholder; + @FXML private StackPane statusbarPlaceholder; + @FXML + private StackPane resultPanel; + public MainWindow(Stage primaryStage, Logic logic) { super(FXML, primaryStage); @@ -59,6 +66,8 @@ public MainWindow(Stage primaryStage, Logic logic) { // Configure the UI setWindowDefaultSize(logic.getGuiSettings()); + primaryStage.setMaximized(true); + primaryStage.setTitle("ExerHealth"); setAccelerators(); @@ -107,8 +116,11 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) { * Fills up all the placeholders of this window. */ void fillInnerParts() { - personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + filteredListPanel = new ExerciseListPanel(logic.getFilteredExerciseList()); + filteredListPanelPlaceholder.getChildren().add(filteredListPanel.getRoot()); + + sortedListPanel = new ExerciseListPanel(logic.getSortedExerciseList()); + sortedListPanelPlaceholder.getChildren().add(sortedListPanel.getRoot()); resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); @@ -160,8 +172,8 @@ private void handleExit() { primaryStage.hide(); } - public PersonListPanel getPersonListPanel() { - return personListPanel; + public ExerciseListPanel getPersonListPanel() { + return filteredListPanel; } /** @@ -173,6 +185,7 @@ private CommandResult executeCommand(String commandText) throws CommandException try { CommandResult commandResult = logic.execute(commandText); logger.info("Result: " + commandResult.getFeedbackToUser()); + resultPanel.getChildren().add(filteredListPanel.getRoot()); resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser()); if (commandResult.isShowHelp()) { diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java deleted file mode 100644 index 1328917096e..00000000000 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ /dev/null @@ -1,46 +0,0 @@ -package seedu.address.ui; - -import java.util.logging.Logger; - -import javafx.collections.ObservableList; -import javafx.fxml.FXML; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; -import javafx.scene.layout.Region; -import seedu.address.commons.core.LogsCenter; -import seedu.address.model.person.Person; - -/** - * Panel containing the list of persons. - */ -public class PersonListPanel extends UiPart { - private static final String FXML = "PersonListPanel.fxml"; - private final Logger logger = LogsCenter.getLogger(PersonListPanel.class); - - @FXML - private ListView personListView; - - public PersonListPanel(ObservableList personList) { - super(FXML); - personListView.setItems(personList); - personListView.setCellFactory(listView -> new PersonListViewCell()); - } - - /** - * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. - */ - class PersonListViewCell extends ListCell { - @Override - protected void updateItem(Person person, boolean empty) { - super.updateItem(person, empty); - - if (empty || person == null) { - setGraphic(null); - setText(null); - } else { - setGraphic(new PersonCard(person, getIndex() + 1).getRoot()); - } - } - } - -} diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/ExerciseListCard.fxml similarity index 83% rename from src/main/resources/view/PersonListCard.fxml rename to src/main/resources/view/ExerciseListCard.fxml index f08ea32ad55..6255f0cf156 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/ExerciseListCard.fxml @@ -28,9 +28,9 @@