From f27d35d0feb67caa39cf7388c1ea9dae8939ffa5 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Mon, 30 Mar 2020 04:28:22 +0800 Subject: [PATCH 01/15] to work on jsonadaptedcooked record and cooked record --- data/addressbook.json | 2 +- src/main/java/seedu/recipe/MainApp.java | 5 +- .../recipe/model/ReadOnlyCookedRecord.java | 17 ++++ .../java/seedu/recipe/model/UserPrefs.java | 4 + .../recipe/model/cooked/CookedRecord.java | 11 +++ .../recipe/storage/CookedRecordStorage.java | 46 +++++++++++ .../storage/JsonAdaptedCookedRecord.java | 8 ++ .../storage/JsonCookedRecordStorage.java | 80 +++++++++++++++++++ .../storage/JsonSerializableCookedRecord.java | 61 ++++++++++++++ .../java/seedu/recipe/storage/Storage.java | 12 ++- .../seedu/recipe/storage/StorageManager.java | 36 ++++++++- 11 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java create mode 100644 src/main/java/seedu/recipe/model/cooked/CookedRecord.java create mode 100644 src/main/java/seedu/recipe/storage/CookedRecordStorage.java create mode 100644 src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java create mode 100644 src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java create mode 100644 src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java diff --git a/data/addressbook.json b/data/addressbook.json index 24ee3118664..347c574157e 100644 --- a/data/addressbook.json +++ b/data/addressbook.json @@ -176,4 +176,4 @@ "steps" : [ ], "goals" : [ ] } ] -} +} \ No newline at end of file diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index 1e5b9cc9ef7..9e8a514269f 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -22,7 +22,9 @@ import seedu.recipe.model.RecipeBook; import seedu.recipe.model.UserPrefs; import seedu.recipe.model.util.SampleDataUtil; +import seedu.recipe.storage.CookedRecordStorage; import seedu.recipe.storage.JsonRecipeBookStorage; +import seedu.recipe.storage.JsonCookedRecordStorage; import seedu.recipe.storage.JsonUserPrefsStorage; import seedu.recipe.storage.RecipeBookStorage; import seedu.recipe.storage.Storage; @@ -57,7 +59,8 @@ public void init() throws Exception { UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath()); UserPrefs userPrefs = initPrefs(userPrefsStorage); RecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(userPrefs.getRecipeBookFilePath()); - storage = new StorageManager(recipeBookStorage, userPrefsStorage); + CookedRecordStorage cookedRecordStorage = new JsonCookedRecordStorage(userPrefs.getCookedRecordFilePath()); + storage = new StorageManager(recipeBookStorage, cookedRecordStorage, userPrefsStorage); initLogging(config); diff --git a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java new file mode 100644 index 00000000000..5a4994d59ad --- /dev/null +++ b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java @@ -0,0 +1,17 @@ +package seedu.recipe.model; + +import javafx.collections.ObservableList; +import seedu.recipe.model.cooked.CookedRecord; + +/** + * Unmodifiable view of a cooked Records + */ +public interface ReadOnlyCookedRecord { + + /** + * Returns an unmodifiable view of the cooked record list. + * This list contains history of cooked meals + */ + ObservableList getcookedRecordList(); + +} \ No newline at end of file diff --git a/src/main/java/seedu/recipe/model/UserPrefs.java b/src/main/java/seedu/recipe/model/UserPrefs.java index d1a846688ac..2b5bde3fa38 100644 --- a/src/main/java/seedu/recipe/model/UserPrefs.java +++ b/src/main/java/seedu/recipe/model/UserPrefs.java @@ -15,6 +15,7 @@ public class UserPrefs implements ReadOnlyUserPrefs { private GuiSettings guiSettings = new GuiSettings(); private Path recipeBookFilePath = Paths.get("data" , "addressbook.json"); + private Path cookedRecordFilePath = Paths.get("data" , "cookedRecords.json"); /** * Creates a {@code UserPrefs} with default values. @@ -84,4 +85,7 @@ public String toString() { return sb.toString(); } + public Path getCookedRecordFilePath() { + return cookedRecordFilePath; + } } diff --git a/src/main/java/seedu/recipe/model/cooked/CookedRecord.java b/src/main/java/seedu/recipe/model/cooked/CookedRecord.java new file mode 100644 index 00000000000..af97e23cbc4 --- /dev/null +++ b/src/main/java/seedu/recipe/model/cooked/CookedRecord.java @@ -0,0 +1,11 @@ +package seedu.recipe.model.cooked; + +import seedu.recipe.model.recipe.Recipe; + +public class CookedRecord { + public void addRecord(Recipe recipe) { + } + + public boolean hasBeenCooked(Recipe recipe) { + } +} diff --git a/src/main/java/seedu/recipe/storage/CookedRecordStorage.java b/src/main/java/seedu/recipe/storage/CookedRecordStorage.java new file mode 100644 index 00000000000..6dad05dae53 --- /dev/null +++ b/src/main/java/seedu/recipe/storage/CookedRecordStorage.java @@ -0,0 +1,46 @@ +package seedu.recipe.storage; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; + +import seedu.recipe.commons.exceptions.DataConversionException; +import seedu.recipe.model.ReadOnlyCookedRecord; +import seedu.recipe.model.cooked.CookedRecord; + +/** + * Represents a storage for {@link CookedRecord}. + */ +public interface CookedRecordStorage { + + /** + * Returns the file path of the data file. + */ + Path getCookedRecordFilePath(); + + /** + * Returns CookedRecord data as a {@link ReadOnlyCookedRecord}. + * 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 readCookedRecord() throws DataConversionException, IOException; + + /** + * @see #getCookedRecordFilePath() + */ + Optional readCookedRecord(Path filePath) throws DataConversionException, IOException; + + /** + * Saves the given {@link ReadOnlyCookedRecord} to the storage. + * @param cookedRecord cannot be null. + * @throws IOException if there was any problem writing to the file. + */ + void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException; + + /** + * @see #saveCookedRecord(ReadOnlyCookedRecord) + */ + void saveCookedRecord(ReadOnlyCookedRecord cookedRecord, Path filePath) throws IOException; + +} \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java b/src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java new file mode 100644 index 00000000000..bc92126c266 --- /dev/null +++ b/src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java @@ -0,0 +1,8 @@ +package seedu.recipe.storage; + +import seedu.recipe.model.cooked.CookedRecord; + +public class JsonAdaptedCookedRecord { + public CookedRecord toModelType() { + } +} diff --git a/src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java b/src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java new file mode 100644 index 00000000000..87ab91b4341 --- /dev/null +++ b/src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java @@ -0,0 +1,80 @@ +package seedu.recipe.storage; + +import static java.util.Objects.requireNonNull; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; +import java.util.logging.Logger; + +import seedu.recipe.commons.core.LogsCenter; +import seedu.recipe.commons.exceptions.DataConversionException; +import seedu.recipe.commons.exceptions.IllegalValueException; +import seedu.recipe.commons.util.FileUtil; +import seedu.recipe.commons.util.JsonUtil; +import seedu.recipe.model.ReadOnlyCookedRecord; + +/** + * A class to access RecipeBook data stored as a json file on the hard disk. + */ +public class JsonCookedRecordStorage implements CookedRecordStorage { + + private static final Logger logger = LogsCenter.getLogger(JsonRecipeBookStorage.class); + + private Path filePath; + + public JsonCookedRecordStorage(Path filePath) { + this.filePath = filePath; + } + + public Path getCookedRecordFilePath() { + return filePath; + } + + @Override + public Optional readCookedRecord() throws DataConversionException { + return readCookedRecord(filePath); + } + + /** + * Similar to {@link #readCookedRecord()}. + * + * @param filePath location of the data. Cannot be null. + * @throws DataConversionException if the file is not in the correct format. + */ + public Optional readCookedRecord(Path filePath) throws DataConversionException { + requireNonNull(filePath); + + Optional jsonCookedRecord = JsonUtil.readJsonFile( + filePath, JsonSerializableCookedRecord.class); + if (!jsonCookedRecord.isPresent()) { + return Optional.empty(); + } + + try { + return Optional.of(jsonCookedRecord.get().toModelType()); + } catch (IllegalValueException ive) { + logger.info("Illegal values found in " + filePath + ": " + ive.getMessage()); + throw new DataConversionException(ive); + } + } + + @Override + public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException { + saveCookedRecord(cookedRecord, filePath); + } + + /** + * Similar to {@link #saveCookedRecord(ReadOnlyCookedRecord)}. + * + * @param filePath location of the data. Cannot be null. + */ + public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord, Path filePath) throws IOException { + requireNonNull(cookedRecord); + requireNonNull(filePath); + + FileUtil.createIfMissing(filePath); + JsonUtil.saveJsonFile(new JsonSerializableCookedRecord(cookedRecord), filePath); + } + +} \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java new file mode 100644 index 00000000000..9a7263be7f7 --- /dev/null +++ b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java @@ -0,0 +1,61 @@ +package seedu.recipe.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.recipe.commons.exceptions.IllegalValueException; +import seedu.recipe.model.ReadOnlyCookedRecord; +import seedu.recipe.model.cooked.CookedRecord; + +/** + * An Immutable CookedRecord that is serializable to JSON format. + */ +@JsonRootName(value = "cookedrecord") +class JsonSerializableCookedRecord { + + public static final String MESSAGE_COOKED_RECIPE = "Recipe has already been cooked."; + + private final List cooked = new ArrayList<>(); + + /** + * Constructs a {@code JsonSerializableCookedRecord} with the given records. + */ + @JsonCreator + public JsonSerializableCookedRecord(@JsonProperty("cooked") List recipes) { + this.cooked.addAll(recipes); + } + + /** + * Converts a given {@code ReadOnlyRecipeBook} into this class for Jackson use. + * + * @param source future changes to this will not affect the created {@code JsonSerializableRecipeBook}. + */ + public JsonSerializableCookedRecord(ReadOnlyCookedRecord source) { + cooked.addAll(source.getcookedRecordList().stream() + .map(JsonAdaptedCookedRecord::new).collect(Collectors.toList())); + } + + /** + * Converts this recipe book into the model's {@code RecipeBook} object. + * + * @throws IllegalValueException if there were any data constraints violated. + */ + public CookedRecord toModelType() throws IllegalValueException { + CookedRecord cookedRecord = new CookedRecord(); + for (JsonAdaptedCookedRecord jsonAdaptedCookedRecord : cooked) { + CookedRecord record = jsonAdaptedCookedRecord.toModelType(); + if (cookedRecord.hasBeenCooked(record)) { + throw new IllegalValueException(MESSAGE_COOKED_RECIPE); + } + cookedRecord.addRecord(record); + } + return cookedRecord; + } + +} + diff --git a/src/main/java/seedu/recipe/storage/Storage.java b/src/main/java/seedu/recipe/storage/Storage.java index 2ba039c76fb..936ed12de17 100644 --- a/src/main/java/seedu/recipe/storage/Storage.java +++ b/src/main/java/seedu/recipe/storage/Storage.java @@ -5,6 +5,7 @@ import java.util.Optional; import seedu.recipe.commons.exceptions.DataConversionException; +import seedu.recipe.model.ReadOnlyCookedRecord; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.UserPrefs; @@ -12,7 +13,7 @@ /** * API of the Storage component */ -public interface Storage extends RecipeBookStorage, UserPrefsStorage { +public interface Storage extends RecipeBookStorage, CookedRecordStorage, UserPrefsStorage { @Override Optional readUserPrefs() throws DataConversionException, IOException; @@ -29,4 +30,13 @@ public interface Storage extends RecipeBookStorage, UserPrefsStorage { @Override void saveRecipeBook(ReadOnlyRecipeBook recipeBook) throws IOException; + @Override + Path getCookedRecordFilePath(); + + @Override + Optional readCookedRecord() throws DataConversionException, IOException; + + @Override + void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException; + } diff --git a/src/main/java/seedu/recipe/storage/StorageManager.java b/src/main/java/seedu/recipe/storage/StorageManager.java index dfa48457b0c..318fc318c5b 100644 --- a/src/main/java/seedu/recipe/storage/StorageManager.java +++ b/src/main/java/seedu/recipe/storage/StorageManager.java @@ -7,9 +7,11 @@ import seedu.recipe.commons.core.LogsCenter; import seedu.recipe.commons.exceptions.DataConversionException; +import seedu.recipe.model.ReadOnlyCookedRecord; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.UserPrefs; +import seedu.recipe.model.cooked.CookedRecord; /** * Manages storage of RecipeBook data in local storage. @@ -18,12 +20,15 @@ public class StorageManager implements Storage { private static final Logger logger = LogsCenter.getLogger(StorageManager.class); private RecipeBookStorage recipeBookStorage; + private CookedRecordStorage cookedRecordStorage; private UserPrefsStorage userPrefsStorage; - public StorageManager(RecipeBookStorage recipeBookStorage, UserPrefsStorage userPrefsStorage) { + public StorageManager(RecipeBookStorage recipeBookStorage, CookedRecordStorage cookedRecordStorage, + UserPrefsStorage userPrefsStorage) { super(); this.recipeBookStorage = recipeBookStorage; + this.cookedRecordStorage = cookedRecordStorage; this.userPrefsStorage = userPrefsStorage; } @@ -74,4 +79,33 @@ public void saveRecipeBook(ReadOnlyRecipeBook recipeBook, Path filePath) throws recipeBookStorage.saveRecipeBook(recipeBook, filePath); } + // ================ CookedRecord methods ============================== + + @Override + public Path getCookedRecordFilePath() { + return cookedRecordStorage.getCookedRecordFilePath(); + } + + @Override + public Optional readCookedRecord() throws DataConversionException, IOException { + return readCookedRecord(cookedRecordStorage.getCookedRecordFilePath()); + } + + @Override + public Optional readCookedRecord(Path filePath) throws DataConversionException, IOException { + logger.fine("Attempting to read data from file: " + filePath); + return cookedRecordStorage.readCookedRecord(filePath); + } + + @Override + public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException { + saveCookedRecord(cookedRecord, cookedRecordStorage.getCookedRecordFilePath()); + } + + @Override + public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord, Path filePath) throws IOException { + logger.fine("Attempting to write to data file: " + filePath); + cookedRecordStorage.saveCookedRecord(cookedRecord, filePath); + } + } From 185cb9874073417d443b95c470ce0415ca11d032 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Mon, 30 Mar 2020 15:13:05 +0800 Subject: [PATCH 02/15] cooked records in model --- .../recipe/model/ReadOnlyCookedRecord.java | 4 +- .../recipe/model/cooked/CookedRecord.java | 118 +++++++++++++++++- .../seedu/recipe/model/cooked/Record.java | 4 + .../recipe/model/cooked/UniqueRecordList.java | 24 ++++ ...okedRecord.java => JsonAdaptedRecord.java} | 2 +- .../storage/JsonSerializableCookedRecord.java | 16 +-- 6 files changed, 153 insertions(+), 15 deletions(-) create mode 100644 src/main/java/seedu/recipe/model/cooked/Record.java create mode 100644 src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java rename src/main/java/seedu/recipe/storage/{JsonAdaptedCookedRecord.java => JsonAdaptedRecord.java} (76%) diff --git a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java index 5a4994d59ad..bdf69a6ba67 100644 --- a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java +++ b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java @@ -1,7 +1,7 @@ package seedu.recipe.model; import javafx.collections.ObservableList; -import seedu.recipe.model.cooked.CookedRecord; +import seedu.recipe.model.cooked.Record; /** * Unmodifiable view of a cooked Records @@ -12,6 +12,6 @@ public interface ReadOnlyCookedRecord { * Returns an unmodifiable view of the cooked record list. * This list contains history of cooked meals */ - ObservableList getcookedRecordList(); + ObservableList getRecordsList(); } \ No newline at end of file diff --git a/src/main/java/seedu/recipe/model/cooked/CookedRecord.java b/src/main/java/seedu/recipe/model/cooked/CookedRecord.java index af97e23cbc4..8d126fecd11 100644 --- a/src/main/java/seedu/recipe/model/cooked/CookedRecord.java +++ b/src/main/java/seedu/recipe/model/cooked/CookedRecord.java @@ -1,11 +1,121 @@ package seedu.recipe.model.cooked; -import seedu.recipe.model.recipe.Recipe; +import static java.util.Objects.requireNonNull; -public class CookedRecord { - public void addRecord(Recipe recipe) { +import java.util.List; + +import javafx.collections.ObservableList; +import seedu.recipe.model.ReadOnlyCookedRecord; + +/** + * Wraps all data at the address-book level + * Duplicates are not allowed (by .isSameRecipe comparison) + */ +public class CookedRecord implements ReadOnlyCookedRecord { + + private final UniqueRecordList records; + + /* + * 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. + */ + { + records = new UniqueRecordList(); + } + + public CookedRecord() {} + + /** + * Creates a RecipeBook using the Recipes in the {@code toBeCopied} + */ + public CookedRecord(ReadOnlyCookedRecord toBeCopied) { + this(); + resetData(toBeCopied); + } + + //// list overwrite operations + + /** + * Replaces the contents of the recipe list with {@code records}. + * {@code records} must not contain duplicate recipes. + */ + public void setRecords(List records) { + this.records.setRecords(records); + } + + /** + * Resets the existing data of this {@code CookedRecord} with {@code newData}. + * @param newData + */ + public void resetData(ReadOnlyCookedRecord newData) { + requireNonNull(newData); + + setRecords(newData.getRecordsList()); + } + + + //// recipe-level operations + + /** + * Returns true if a record with the same identity as {@code record} exists in the cookedrecord. + */ + public boolean hasRecord(Record record) { + requireNonNull(record); + return records.contains(record); + } + + /** + * Adds a record to the cookedrecords. + * The record must not already exist in the address book. + */ + public void addRecord(Record p) { + records.add(p); + } + + /** + * Replaces the given recipe {@code target} in the list with {@code editedRecipe}. + * {@code target} must exist in the address book. + * The recipe identity of {@code editedRecipe} must not be the same as another existing recipe in the address book. + */ + public void setRecord(Record target, Record editedRecord) { + requireNonNull(editedRecord); + + records.setRecipe(target, editedRecord); + } + + /** + * Removes {@code key} from this {@code CookedRcord}. + * {@code key} must exist in the cookedrecord. + */ + public void removeRecord(Record key) { + records.remove(key); + } + + //// util methods + + @Override + public String toString() { + return records.asUnmodifiableObservableList().size() + " records"; + // TODO: refine later + } + + @Override + public ObservableList getCookedRecordList() { + return records.asUnmodifiableObservableList(); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof seedu.recipe.model.cooked.CookedRecord // instanceof handles nulls + && records.equals(((seedu.recipe.model.cooked.CookedRecord) other).records)); } - public boolean hasBeenCooked(Recipe recipe) { + @Override + public int hashCode() { + return records.hashCode(); } } diff --git a/src/main/java/seedu/recipe/model/cooked/Record.java b/src/main/java/seedu/recipe/model/cooked/Record.java new file mode 100644 index 00000000000..8896cc27158 --- /dev/null +++ b/src/main/java/seedu/recipe/model/cooked/Record.java @@ -0,0 +1,4 @@ +package seedu.recipe.model.cooked; + +public class Record { +} diff --git a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java new file mode 100644 index 00000000000..601b2fd1b0c --- /dev/null +++ b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java @@ -0,0 +1,24 @@ +package seedu.recipe.model.cooked; + +import java.util.Collection; +import java.util.List; + +public class UniqueRecordList { + public void setRecords(List records) { + } + + public boolean contains(Record record) { + } + + public void add(Record p) { + } + + public void setRecipe(Record target, Record editedRecord) { + } + + public void remove(Record key) { + } + + public Collection asUnmodifiableObservableList() { + } +} diff --git a/src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java similarity index 76% rename from src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java rename to src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java index bc92126c266..ff8ffe5211b 100644 --- a/src/main/java/seedu/recipe/storage/JsonAdaptedCookedRecord.java +++ b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java @@ -2,7 +2,7 @@ import seedu.recipe.model.cooked.CookedRecord; -public class JsonAdaptedCookedRecord { +public class JsonAdaptedRecord { public CookedRecord toModelType() { } } diff --git a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java index 9a7263be7f7..d0be0a57a28 100644 --- a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java +++ b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java @@ -20,14 +20,14 @@ class JsonSerializableCookedRecord { public static final String MESSAGE_COOKED_RECIPE = "Recipe has already been cooked."; - private final List cooked = new ArrayList<>(); + private final List records = new ArrayList<>(); /** * Constructs a {@code JsonSerializableCookedRecord} with the given records. */ @JsonCreator - public JsonSerializableCookedRecord(@JsonProperty("cooked") List recipes) { - this.cooked.addAll(recipes); + public JsonSerializableCookedRecord(@JsonProperty("records") List recipes) { + this.records.addAll(recipes); } /** @@ -36,8 +36,8 @@ public JsonSerializableCookedRecord(@JsonProperty("cooked") List Date: Mon, 30 Mar 2020 21:57:25 +0800 Subject: [PATCH 03/15] added cooked command to model and parser --- src/main/java/seedu/recipe/MainApp.java | 6 +- .../recipe/logic/commands/CookedCommand.java | 64 +++++++++++++++ .../logic/parser/CookedCommandParser.java | 26 +++++++ .../recipe/logic/parser/RecipeBookParser.java | 4 + src/main/java/seedu/recipe/model/Model.java | 6 ++ .../java/seedu/recipe/model/ModelManager.java | 18 ++++- ...ord.java => ReadOnlyCookedRecordBook.java} | 2 +- ...ookedRecord.java => CookedRecordBook.java} | 25 +++--- .../seedu/recipe/model/cooked/Record.java | 78 +++++++++++++++++++ .../recipe/model/cooked/UniqueRecordList.java | 3 + .../storage/CookedRecordBookStorage.java | 46 +++++++++++ .../recipe/storage/CookedRecordStorage.java | 46 ----------- .../recipe/storage/JsonAdaptedRecord.java | 4 +- ....java => JsonCookedRecordBookStorage.java} | 22 +++--- ... => JsonSerializableCookedRecordBook.java} | 30 ++++--- .../java/seedu/recipe/storage/Storage.java | 8 +- .../seedu/recipe/storage/StorageManager.java | 17 ++-- 17 files changed, 302 insertions(+), 103 deletions(-) create mode 100644 src/main/java/seedu/recipe/logic/commands/CookedCommand.java create mode 100644 src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java rename src/main/java/seedu/recipe/model/{ReadOnlyCookedRecord.java => ReadOnlyCookedRecordBook.java} (88%) rename src/main/java/seedu/recipe/model/cooked/{CookedRecord.java => CookedRecordBook.java} (81%) create mode 100644 src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java delete mode 100644 src/main/java/seedu/recipe/storage/CookedRecordStorage.java rename src/main/java/seedu/recipe/storage/{JsonCookedRecordStorage.java => JsonCookedRecordBookStorage.java} (65%) rename src/main/java/seedu/recipe/storage/{JsonSerializableCookedRecord.java => JsonSerializableCookedRecordBook.java} (64%) diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index 9e8a514269f..78806fd58dc 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -22,9 +22,9 @@ import seedu.recipe.model.RecipeBook; import seedu.recipe.model.UserPrefs; import seedu.recipe.model.util.SampleDataUtil; -import seedu.recipe.storage.CookedRecordStorage; +import seedu.recipe.storage.CookedRecordBookStorage; import seedu.recipe.storage.JsonRecipeBookStorage; -import seedu.recipe.storage.JsonCookedRecordStorage; +import seedu.recipe.storage.JsonCookedRecordBookStorage; import seedu.recipe.storage.JsonUserPrefsStorage; import seedu.recipe.storage.RecipeBookStorage; import seedu.recipe.storage.Storage; @@ -59,7 +59,7 @@ public void init() throws Exception { UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath()); UserPrefs userPrefs = initPrefs(userPrefsStorage); RecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(userPrefs.getRecipeBookFilePath()); - CookedRecordStorage cookedRecordStorage = new JsonCookedRecordStorage(userPrefs.getCookedRecordFilePath()); + CookedRecordBookStorage cookedRecordStorage = new JsonCookedRecordBookStorage(userPrefs.getCookedRecordFilePath()); storage = new StorageManager(recipeBookStorage, cookedRecordStorage, userPrefsStorage); initLogging(config); diff --git a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java new file mode 100644 index 00000000000..4b355ab2689 --- /dev/null +++ b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java @@ -0,0 +1,64 @@ +package seedu.recipe.logic.commands; +import static java.util.Objects.requireNonNull; +import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import seedu.recipe.commons.core.Messages; +import seedu.recipe.commons.core.index.Index; +import seedu.recipe.logic.commands.exceptions.CommandException; +import seedu.recipe.model.Model; +import seedu.recipe.model.cooked.Record; +import seedu.recipe.model.recipe.Recipe; + +public class CookedCommand extends Command { + public static final String COMMAND_WORD = "cooked"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Indicate that the recipe has been cooked at the current time\n" + + "Parameters: INDEX NUMBER(s) (must be positive integers)\n" + + "Example: " + COMMAND_WORD + " 1"; + + private final Index[] targetIndex; + + public CookedCommand(Index[] targetIndex) { + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List mostRecentList = model.getFilteredRecipeList(); + StringBuilder sb = new StringBuilder().append("Cooked "); + + for (int i = 0; i < targetIndex.length; i++) { + if (targetIndex[i].getZeroBased() >= mostRecentList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_RECIPE_DISPLAYED_INDEX); + } + + Recipe recipeCooked = mostRecentList.get(targetIndex[i].getZeroBased()); + Date now = new Date(); + Record record = new Record(recipeCooked.getName(), now); + model.addRecord(record); + if (i == targetIndex.length - 1 && targetIndex.length != 1) { + sb.append(" and "); + } + sb.append(recipeCooked.getName().toString()); + if (i < targetIndex.length - 2) { + sb.append(", "); + } + } + sb.append("!"); + return new CommandResult(sb.toString()); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof CookedCommand // instanceof handles nulls + && Arrays.equals(targetIndex, ((CookedCommand) other).targetIndex)); // state check + } + +} diff --git a/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java b/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java new file mode 100644 index 00000000000..eadaa351975 --- /dev/null +++ b/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java @@ -0,0 +1,26 @@ +package seedu.recipe.logic.parser; + +import static seedu.recipe.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.recipe.commons.core.index.Index; +import seedu.recipe.logic.commands.CookedCommand; +import seedu.recipe.logic.parser.exceptions.ParseException; + +public class CookedCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the CookedCommand + * and returns a CookedCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public CookedCommand parse(String args) throws ParseException { + try { + Index[] index = ParserUtil.parseMultipleIndex(args); + return new CookedCommand(index); + } catch (ParseException exception) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, CookedCommand.MESSAGE_USAGE), exception); + } + } + +} diff --git a/src/main/java/seedu/recipe/logic/parser/RecipeBookParser.java b/src/main/java/seedu/recipe/logic/parser/RecipeBookParser.java index c21526d9009..96565539d41 100644 --- a/src/main/java/seedu/recipe/logic/parser/RecipeBookParser.java +++ b/src/main/java/seedu/recipe/logic/parser/RecipeBookParser.java @@ -11,6 +11,7 @@ import seedu.recipe.logic.commands.AddStepCommand; import seedu.recipe.logic.commands.ClearCommand; import seedu.recipe.logic.commands.Command; +import seedu.recipe.logic.commands.CookedCommand; import seedu.recipe.logic.commands.DeleteCommand; import seedu.recipe.logic.commands.DeleteIngredientCommand; import seedu.recipe.logic.commands.DeleteStepCommand; @@ -85,6 +86,9 @@ public Command parseCommand(String userInput) throws ParseException { case ListGoalsCommand.COMMAND_WORD: return new ListGoalsCommand(); + case CookedCommand.COMMAND_WORD: + return new CookedCommandParser().parse(arguments); + case FavouriteCommand.COMMAND_WORD: return new FavouriteCommandParser().parse(arguments); diff --git a/src/main/java/seedu/recipe/model/Model.java b/src/main/java/seedu/recipe/model/Model.java index 284db6697b8..0664ad152af 100644 --- a/src/main/java/seedu/recipe/model/Model.java +++ b/src/main/java/seedu/recipe/model/Model.java @@ -7,6 +7,7 @@ import seedu.recipe.commons.core.GuiSettings; import seedu.recipe.model.plan.Date; import seedu.recipe.model.recipe.Recipe; +import seedu.recipe.model.cooked.Record; /** * The API of the Model component. @@ -130,4 +131,9 @@ public interface Model { */ void planRecipe(Recipe recipeToSet, Date atDate); + /** + * Adds a record in the cookedRecord list + */ + + void addRecord(Record record); } diff --git a/src/main/java/seedu/recipe/model/ModelManager.java b/src/main/java/seedu/recipe/model/ModelManager.java index 5d027586c2a..d8764e12efb 100644 --- a/src/main/java/seedu/recipe/model/ModelManager.java +++ b/src/main/java/seedu/recipe/model/ModelManager.java @@ -11,6 +11,8 @@ import javafx.collections.transformation.FilteredList; import seedu.recipe.commons.core.GuiSettings; import seedu.recipe.commons.core.LogsCenter; +import seedu.recipe.model.cooked.CookedRecordBook; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.plan.Date; import seedu.recipe.model.plan.PlannedRecipeMap; import seedu.recipe.model.recipe.Recipe; @@ -26,11 +28,14 @@ public class ModelManager implements Model { private final FilteredList filteredRecipes; private final VersionedRecipeBook states; private final PlannedRecipeMap plannedRecipes; + private final CookedRecordBook cookedRecordBook; + private final FilteredList records; /** * Initializes a ModelManager with the given recipeBook and userPrefs. */ - public ModelManager(ReadOnlyRecipeBook recipeBook, ReadOnlyUserPrefs userPrefs) { + public ModelManager(ReadOnlyRecipeBook recipeBook, ReadOnlyUserPrefs userPrefs, + ReadOnlyCookedRecordBook cookedRecordBook) { super(); requireAllNonNull(recipeBook, userPrefs); @@ -40,11 +45,13 @@ public ModelManager(ReadOnlyRecipeBook recipeBook, ReadOnlyUserPrefs userPrefs) this.userPrefs = new UserPrefs(userPrefs); filteredRecipes = new FilteredList<>(this.recipeBook.getRecipeList()); this.states = new VersionedRecipeBook(recipeBook); + this.cookedRecordBook = new CookedRecordBook(cookedRecordBook); + this.records = new FilteredList<>(this.cookedRecordBook.getRecordsList()); plannedRecipes = new PlannedRecipeMap(); // todo: planned recipes cant be saved currently } public ModelManager() { - this(new RecipeBook(), new UserPrefs()); + this(new RecipeBook(), new UserPrefs(), new CookedRecordBook()); } //=========== UserPrefs ================================================================================== @@ -195,4 +202,11 @@ public void planRecipe(Recipe recipeToSet, Date atDate) { plannedRecipes.add(recipeToSet, atDate); } + //=========== Cooked Recipe List Accessors ============================================================= + + @Override + public void addRecord(Record record) { + cookedRecordBook.addRecord(record); + } + } diff --git a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java similarity index 88% rename from src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java rename to src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java index bdf69a6ba67..354f5d7ca84 100644 --- a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecord.java +++ b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java @@ -6,7 +6,7 @@ /** * Unmodifiable view of a cooked Records */ -public interface ReadOnlyCookedRecord { +public interface ReadOnlyCookedRecordBook { /** * Returns an unmodifiable view of the cooked record list. diff --git a/src/main/java/seedu/recipe/model/cooked/CookedRecord.java b/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java similarity index 81% rename from src/main/java/seedu/recipe/model/cooked/CookedRecord.java rename to src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java index 8d126fecd11..928037849fc 100644 --- a/src/main/java/seedu/recipe/model/cooked/CookedRecord.java +++ b/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java @@ -5,13 +5,13 @@ import java.util.List; import javafx.collections.ObservableList; -import seedu.recipe.model.ReadOnlyCookedRecord; +import seedu.recipe.model.ReadOnlyCookedRecordBook; /** * Wraps all data at the address-book level * Duplicates are not allowed (by .isSameRecipe comparison) */ -public class CookedRecord implements ReadOnlyCookedRecord { +public class CookedRecordBook implements ReadOnlyCookedRecordBook { private final UniqueRecordList records; @@ -26,12 +26,12 @@ public class CookedRecord implements ReadOnlyCookedRecord { records = new UniqueRecordList(); } - public CookedRecord() {} + public CookedRecordBook() {} /** * Creates a RecipeBook using the Recipes in the {@code toBeCopied} */ - public CookedRecord(ReadOnlyCookedRecord toBeCopied) { + public CookedRecordBook(ReadOnlyCookedRecordBook toBeCopied) { this(); resetData(toBeCopied); } @@ -47,10 +47,10 @@ public void setRecords(List records) { } /** - * Resets the existing data of this {@code CookedRecord} with {@code newData}. + * Resets the existing data of this {@code CookedRecordBook} with {@code newData}. * @param newData */ - public void resetData(ReadOnlyCookedRecord newData) { + public void resetData(ReadOnlyCookedRecordBook newData) { requireNonNull(newData); setRecords(newData.getRecordsList()); @@ -102,20 +102,21 @@ public String toString() { // TODO: refine later } - @Override - public ObservableList getCookedRecordList() { - return records.asUnmodifiableObservableList(); - } @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof seedu.recipe.model.cooked.CookedRecord // instanceof handles nulls - && records.equals(((seedu.recipe.model.cooked.CookedRecord) other).records)); + || (other instanceof CookedRecordBook // instanceof handles nulls + && records.equals(((CookedRecordBook) other).records)); } @Override public int hashCode() { return records.hashCode(); } + + @Override + public ObservableList getRecordsList() { + return null; + } } diff --git a/src/main/java/seedu/recipe/model/cooked/Record.java b/src/main/java/seedu/recipe/model/cooked/Record.java index 8896cc27158..99f2e52d843 100644 --- a/src/main/java/seedu/recipe/model/cooked/Record.java +++ b/src/main/java/seedu/recipe/model/cooked/Record.java @@ -1,4 +1,82 @@ package seedu.recipe.model.cooked; +import static seedu.recipe.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.Date; +import java.util.Objects; + +import seedu.recipe.model.recipe.Name; + public class Record { + + // Identity fields + private final Name name; + private final Date date; + + /** + * Every field must be present and not null. + */ + public Record(Name name, Date date) { + requireAllNonNull(name, date); + this.name = name; + this.date = date; + } + + public Name getName() { + return name; + } + + public Date getDate() { + return date; + } + + + /** + * Returns true if both recipes of the same name and same date. + * This defines a weaker notion of equality between two recipes. + */ + public boolean isSameRecord(Record otherRecord) { + if (otherRecord == this) { + return true; + } + + return otherRecord != null + && otherRecord.getName().equals(getName()) + && (otherRecord.getDate().equals(getDate())); + } + + /** + * Returns true if both recipes have the same identity and data fields. + * This defines a stronger notion of equality between two recipes. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof Record)) { + return false; + } + + Record otherRecord = (Record) other; + + return otherRecord.getName().equals(getName()) + && otherRecord.getDate().equals(getDate()); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(name, date); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append(getName()) + .append("\nDate: ") + .append(getDate()); + return builder.toString(); + } } diff --git a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java index 601b2fd1b0c..48b013fc05c 100644 --- a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java +++ b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java @@ -1,5 +1,6 @@ package seedu.recipe.model.cooked; +import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -8,6 +9,7 @@ public void setRecords(List records) { } public boolean contains(Record record) { + return false; } public void add(Record p) { @@ -20,5 +22,6 @@ public void remove(Record key) { } public Collection asUnmodifiableObservableList() { + return new ArrayList<>(); } } diff --git a/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java b/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java new file mode 100644 index 00000000000..d5f423af22c --- /dev/null +++ b/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java @@ -0,0 +1,46 @@ +package seedu.recipe.storage; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; + +import seedu.recipe.commons.exceptions.DataConversionException; +import seedu.recipe.model.ReadOnlyCookedRecordBook; +import seedu.recipe.model.cooked.CookedRecordBook; + +/** + * Represents a storage for {@link CookedRecordBook}. + */ +public interface CookedRecordBookStorage { + + /** + * Returns the file path of the data file. + */ + Path getCookedRecordFilePath(); + + /** + * Returns CookedRecordBook data as a {@link ReadOnlyCookedRecordBook}. + * 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 readCookedRecord() throws DataConversionException, IOException; + + /** + * @see #getCookedRecordFilePath() + */ + Optional readCookedRecord(Path filePath) throws DataConversionException, IOException; + + /** + * Saves the given {@link ReadOnlyCookedRecordBook} to the storage. + * @param cookedRecord cannot be null. + * @throws IOException if there was any problem writing to the file. + */ + void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException; + + /** + * @see #saveCookedRecord(ReadOnlyCookedRecordBook) + */ + void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePath) throws IOException; + +} \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/CookedRecordStorage.java b/src/main/java/seedu/recipe/storage/CookedRecordStorage.java deleted file mode 100644 index 6dad05dae53..00000000000 --- a/src/main/java/seedu/recipe/storage/CookedRecordStorage.java +++ /dev/null @@ -1,46 +0,0 @@ -package seedu.recipe.storage; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.Optional; - -import seedu.recipe.commons.exceptions.DataConversionException; -import seedu.recipe.model.ReadOnlyCookedRecord; -import seedu.recipe.model.cooked.CookedRecord; - -/** - * Represents a storage for {@link CookedRecord}. - */ -public interface CookedRecordStorage { - - /** - * Returns the file path of the data file. - */ - Path getCookedRecordFilePath(); - - /** - * Returns CookedRecord data as a {@link ReadOnlyCookedRecord}. - * 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 readCookedRecord() throws DataConversionException, IOException; - - /** - * @see #getCookedRecordFilePath() - */ - Optional readCookedRecord(Path filePath) throws DataConversionException, IOException; - - /** - * Saves the given {@link ReadOnlyCookedRecord} to the storage. - * @param cookedRecord cannot be null. - * @throws IOException if there was any problem writing to the file. - */ - void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException; - - /** - * @see #saveCookedRecord(ReadOnlyCookedRecord) - */ - void saveCookedRecord(ReadOnlyCookedRecord cookedRecord, Path filePath) throws IOException; - -} \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java index ff8ffe5211b..48170792bef 100644 --- a/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java +++ b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java @@ -1,8 +1,6 @@ package seedu.recipe.storage; -import seedu.recipe.model.cooked.CookedRecord; - public class JsonAdaptedRecord { - public CookedRecord toModelType() { + public void toModelType() { } } diff --git a/src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java similarity index 65% rename from src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java rename to src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java index 87ab91b4341..ac6202fc212 100644 --- a/src/main/java/seedu/recipe/storage/JsonCookedRecordStorage.java +++ b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java @@ -12,18 +12,18 @@ import seedu.recipe.commons.exceptions.IllegalValueException; import seedu.recipe.commons.util.FileUtil; import seedu.recipe.commons.util.JsonUtil; -import seedu.recipe.model.ReadOnlyCookedRecord; +import seedu.recipe.model.ReadOnlyCookedRecordBook; /** * A class to access RecipeBook data stored as a json file on the hard disk. */ -public class JsonCookedRecordStorage implements CookedRecordStorage { +public class JsonCookedRecordBookStorage implements CookedRecordBookStorage { private static final Logger logger = LogsCenter.getLogger(JsonRecipeBookStorage.class); private Path filePath; - public JsonCookedRecordStorage(Path filePath) { + public JsonCookedRecordBookStorage(Path filePath) { this.filePath = filePath; } @@ -32,7 +32,7 @@ public Path getCookedRecordFilePath() { } @Override - public Optional readCookedRecord() throws DataConversionException { + public Optional readCookedRecord() throws DataConversionException { return readCookedRecord(filePath); } @@ -42,11 +42,11 @@ public Optional readCookedRecord() throws DataConversionEx * @param filePath location of the data. Cannot be null. * @throws DataConversionException if the file is not in the correct format. */ - public Optional readCookedRecord(Path filePath) throws DataConversionException { + public Optional readCookedRecord(Path filePath) throws DataConversionException { requireNonNull(filePath); - Optional jsonCookedRecord = JsonUtil.readJsonFile( - filePath, JsonSerializableCookedRecord.class); + Optional jsonCookedRecord = JsonUtil.readJsonFile( + filePath, JsonSerializableCookedRecordBook.class); if (!jsonCookedRecord.isPresent()) { return Optional.empty(); } @@ -60,21 +60,21 @@ public Optional readCookedRecord(Path filePath) throws Dat } @Override - public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException { + public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException { saveCookedRecord(cookedRecord, filePath); } /** - * Similar to {@link #saveCookedRecord(ReadOnlyCookedRecord)}. + * Similar to {@link #saveCookedRecord(ReadOnlyCookedRecordBook)}. * * @param filePath location of the data. Cannot be null. */ - public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord, Path filePath) throws IOException { + public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePath) throws IOException { requireNonNull(cookedRecord); requireNonNull(filePath); FileUtil.createIfMissing(filePath); - JsonUtil.saveJsonFile(new JsonSerializableCookedRecord(cookedRecord), filePath); + //JsonUtil.saveJsonFile(new JsonSerializableCookedRecordBook(cookedRecord), filePath); } } \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java similarity index 64% rename from src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java rename to src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java index d0be0a57a28..4a4a2296c0e 100644 --- a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecord.java +++ b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java @@ -9,53 +9,59 @@ import com.fasterxml.jackson.annotation.JsonRootName; import seedu.recipe.commons.exceptions.IllegalValueException; -import seedu.recipe.model.ReadOnlyCookedRecord; -import seedu.recipe.model.cooked.CookedRecord; +import seedu.recipe.model.ReadOnlyCookedRecordBook; +import seedu.recipe.model.cooked.CookedRecordBook; /** - * An Immutable CookedRecord that is serializable to JSON format. + * An Immutable CookedRecordBook that is serializable to JSON format. */ @JsonRootName(value = "cookedrecord") -class JsonSerializableCookedRecord { +class JsonSerializableCookedRecordBook { public static final String MESSAGE_COOKED_RECIPE = "Recipe has already been cooked."; private final List records = new ArrayList<>(); /** - * Constructs a {@code JsonSerializableCookedRecord} with the given records. + * Constructs a {@code JsonSerializableCookedRecordBook} with the given records. */ @JsonCreator - public JsonSerializableCookedRecord(@JsonProperty("records") List recipes) { + public JsonSerializableCookedRecordBook(@JsonProperty("records") List recipes) { this.records.addAll(recipes); } + public CookedRecordBook toModelType() { + return new CookedRecordBook(); + } + /** * Converts a given {@code ReadOnlyRecipeBook} into this class for Jackson use. * * @param source future changes to this will not affect the created {@code JsonSerializableRecipeBook}. */ - public JsonSerializableCookedRecord(ReadOnlyCookedRecord source) { + /* + public JsonSerializableCookedRecordBook(ReadOnlyCookedRecordBook source) { records.addAll(source.getRecordsList().stream() .map(JsonAdaptedRecord::new).collect(Collectors.toList())); } - +*/ /** * Converts this recipe book into the model's {@code RecipeBook} object. * * @throws IllegalValueException if there were any data constraints violated. */ - public CookedRecord toModelType() throws IllegalValueException { - CookedRecord cookedRecord = new CookedRecord(); + /* + public CookedRecordBook toModelType() throws IllegalValueException { + CookedRecordBook cookedRecord = new CookedRecordBook(); for (JsonAdaptedRecord jsonAdaptedRecord : records) { - CookedRecord record = jsonAdaptedRecord.toModelType(); + CookedRecordBook record = jsonAdaptedRecord.toModelType(); if (cookedRecord.hasRecord(record)) { throw new IllegalValueException(MESSAGE_COOKED_RECIPE); } cookedRecord.addRecord(record); } return cookedRecord; - } + }*/ } diff --git a/src/main/java/seedu/recipe/storage/Storage.java b/src/main/java/seedu/recipe/storage/Storage.java index 936ed12de17..aa4b3e87241 100644 --- a/src/main/java/seedu/recipe/storage/Storage.java +++ b/src/main/java/seedu/recipe/storage/Storage.java @@ -5,7 +5,7 @@ import java.util.Optional; import seedu.recipe.commons.exceptions.DataConversionException; -import seedu.recipe.model.ReadOnlyCookedRecord; +import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.UserPrefs; @@ -13,7 +13,7 @@ /** * API of the Storage component */ -public interface Storage extends RecipeBookStorage, CookedRecordStorage, UserPrefsStorage { +public interface Storage extends RecipeBookStorage, CookedRecordBookStorage, UserPrefsStorage { @Override Optional readUserPrefs() throws DataConversionException, IOException; @@ -34,9 +34,9 @@ public interface Storage extends RecipeBookStorage, CookedRecordStorage, UserPre Path getCookedRecordFilePath(); @Override - Optional readCookedRecord() throws DataConversionException, IOException; + Optional readCookedRecord() throws DataConversionException, IOException; @Override - void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException; + void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException; } diff --git a/src/main/java/seedu/recipe/storage/StorageManager.java b/src/main/java/seedu/recipe/storage/StorageManager.java index 318fc318c5b..e395a36e2cf 100644 --- a/src/main/java/seedu/recipe/storage/StorageManager.java +++ b/src/main/java/seedu/recipe/storage/StorageManager.java @@ -7,11 +7,10 @@ import seedu.recipe.commons.core.LogsCenter; import seedu.recipe.commons.exceptions.DataConversionException; -import seedu.recipe.model.ReadOnlyCookedRecord; +import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.UserPrefs; -import seedu.recipe.model.cooked.CookedRecord; /** * Manages storage of RecipeBook data in local storage. @@ -20,11 +19,11 @@ public class StorageManager implements Storage { private static final Logger logger = LogsCenter.getLogger(StorageManager.class); private RecipeBookStorage recipeBookStorage; - private CookedRecordStorage cookedRecordStorage; + private CookedRecordBookStorage cookedRecordStorage; private UserPrefsStorage userPrefsStorage; - public StorageManager(RecipeBookStorage recipeBookStorage, CookedRecordStorage cookedRecordStorage, + public StorageManager(RecipeBookStorage recipeBookStorage, CookedRecordBookStorage cookedRecordStorage, UserPrefsStorage userPrefsStorage) { super(); this.recipeBookStorage = recipeBookStorage; @@ -79,7 +78,7 @@ public void saveRecipeBook(ReadOnlyRecipeBook recipeBook, Path filePath) throws recipeBookStorage.saveRecipeBook(recipeBook, filePath); } - // ================ CookedRecord methods ============================== + // ================ CookedRecordBook methods ============================== @Override public Path getCookedRecordFilePath() { @@ -87,23 +86,23 @@ public Path getCookedRecordFilePath() { } @Override - public Optional readCookedRecord() throws DataConversionException, IOException { + public Optional readCookedRecord() throws DataConversionException, IOException { return readCookedRecord(cookedRecordStorage.getCookedRecordFilePath()); } @Override - public Optional readCookedRecord(Path filePath) throws DataConversionException, IOException { + public Optional readCookedRecord(Path filePath) throws DataConversionException, IOException { logger.fine("Attempting to read data from file: " + filePath); return cookedRecordStorage.readCookedRecord(filePath); } @Override - public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord) throws IOException { + public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException { saveCookedRecord(cookedRecord, cookedRecordStorage.getCookedRecordFilePath()); } @Override - public void saveCookedRecord(ReadOnlyCookedRecord cookedRecord, Path filePath) throws IOException { + public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePath) throws IOException { logger.fine("Attempting to write to data file: " + filePath); cookedRecordStorage.saveCookedRecord(cookedRecord, filePath); } From a947c3d2fb475d2a006df0a41efc1c8a0e9cde95 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 01:46:13 +0800 Subject: [PATCH 04/15] fixed errors in storage and model, logic and file path needs to be fixed --- src/main/java/seedu/recipe/MainApp.java | 7 ++- .../recipe/logic/commands/CookedCommand.java | 2 +- .../seedu/recipe/model/cooked/Record.java | 21 ++----- .../recipe/model/util/SampleDataUtil.java | 22 ++++++++ .../recipe/storage/JsonAdaptedRecord.java | 55 ++++++++++++++++++- .../storage/JsonCookedRecordBookStorage.java | 9 +-- .../JsonSerializableCookedRecordBook.java | 27 ++++----- 7 files changed, 105 insertions(+), 38 deletions(-) diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index 78806fd58dc..1dfa4a30889 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -17,10 +17,12 @@ import seedu.recipe.logic.LogicManager; import seedu.recipe.model.Model; import seedu.recipe.model.ModelManager; +import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.RecipeBook; import seedu.recipe.model.UserPrefs; +import seedu.recipe.model.cooked.CookedRecordBook; import seedu.recipe.model.util.SampleDataUtil; import seedu.recipe.storage.CookedRecordBookStorage; import seedu.recipe.storage.JsonRecipeBookStorage; @@ -79,6 +81,9 @@ public void init() throws Exception { private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { Optional recipeBookOptional; ReadOnlyRecipeBook initialData; + //to be changed later + ReadOnlyCookedRecordBook stub = new CookedRecordBook(); + try { recipeBookOptional = storage.readRecipeBook(); if (!recipeBookOptional.isPresent()) { @@ -93,7 +98,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { initialData = new RecipeBook(); } - return new ModelManager(initialData, userPrefs); + return new ModelManager(initialData, userPrefs, stub); } private void initLogging(Config config) { diff --git a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java index 4b355ab2689..b36206d1a54 100644 --- a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java +++ b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java @@ -40,7 +40,7 @@ public CommandResult execute(Model model) throws CommandException { Recipe recipeCooked = mostRecentList.get(targetIndex[i].getZeroBased()); Date now = new Date(); - Record record = new Record(recipeCooked.getName(), now); + Record record = new Record(recipeCooked.getName()); model.addRecord(record); if (i == targetIndex.length - 1 && targetIndex.length != 1) { sb.append(" and "); diff --git a/src/main/java/seedu/recipe/model/cooked/Record.java b/src/main/java/seedu/recipe/model/cooked/Record.java index 99f2e52d843..d4af40533cb 100644 --- a/src/main/java/seedu/recipe/model/cooked/Record.java +++ b/src/main/java/seedu/recipe/model/cooked/Record.java @@ -11,24 +11,19 @@ public class Record { // Identity fields private final Name name; - private final Date date; /** * Every field must be present and not null. */ - public Record(Name name, Date date) { - requireAllNonNull(name, date); + public Record(Name name) { + requireAllNonNull(name); this.name = name; - this.date = date; } public Name getName() { return name; } - public Date getDate() { - return date; - } /** @@ -41,8 +36,7 @@ public boolean isSameRecord(Record otherRecord) { } return otherRecord != null - && otherRecord.getName().equals(getName()) - && (otherRecord.getDate().equals(getDate())); + && otherRecord.getName().equals(getName()); } /** @@ -61,22 +55,19 @@ public boolean equals(Object other) { Record otherRecord = (Record) other; - return otherRecord.getName().equals(getName()) - && otherRecord.getDate().equals(getDate()); + return otherRecord.getName().equals(getName()); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, date); + return Objects.hash(name); } @Override public String toString() { final StringBuilder builder = new StringBuilder(); - builder.append(getName()) - .append("\nDate: ") - .append(getDate()); + builder.append(getName()); return builder.toString(); } } diff --git a/src/main/java/seedu/recipe/model/util/SampleDataUtil.java b/src/main/java/seedu/recipe/model/util/SampleDataUtil.java index 9460c5ebfd6..83d6e5b331f 100644 --- a/src/main/java/seedu/recipe/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/recipe/model/util/SampleDataUtil.java @@ -6,8 +6,11 @@ import java.util.TreeSet; import java.util.stream.Collectors; +import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.RecipeBook; +import seedu.recipe.model.cooked.CookedRecordBook; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.goal.Goal; import seedu.recipe.model.recipe.Name; import seedu.recipe.model.recipe.Recipe; @@ -195,4 +198,23 @@ public static Set emptyGrainSet() { return new TreeSet(); } + public static Record[] getSampleRecords() { + return new Record[] { + new Record(new Name("Caesar Salad")), + new Record(new Name("Grilled Sandwich")), + new Record(new Name("Boiled Chicken")), + new Record(new Name("Chocolate Cake")), + new Record(new Name("Omelet")), + new Record(new Name("Tuna Bread")) + }; + } + + public static ReadOnlyCookedRecordBook getSampleRecordBook() { + CookedRecordBook sampleAb = new CookedRecordBook(); + for (Record sampleRecord : getSampleRecords()) { + sampleAb.addRecord(sampleRecord); + } + return sampleAb; + } + } diff --git a/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java index 48170792bef..71ecdcba9ac 100644 --- a/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java +++ b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java @@ -1,6 +1,57 @@ package seedu.recipe.storage; -public class JsonAdaptedRecord { - public void toModelType() { +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.recipe.commons.exceptions.IllegalValueException; +import seedu.recipe.model.cooked.Record; +import seedu.recipe.model.recipe.Name; +import seedu.recipe.model.recipe.Recipe; + + +/** + * Jackson-friendly version of {@link Record}. + */ +class JsonAdaptedRecord { + + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Record's %s field is missing!"; + + private final String name; + + /** + * Constructs a {@code JsonAdaptedRecord} with the given recipe details. + */ + @JsonCreator + public JsonAdaptedRecord(@JsonProperty("name") String name, @JsonProperty("date") String date) { + this.name = name; } + + /** + * Converts a given {@code Record} into this class for Jackson use. + */ + public JsonAdaptedRecord(Record source) { + name = source.getName().fullName; + + } + + /** + * Converts this Jackson-friendly adapted record object into the model's {@code Record} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted recipe. + */ + public Record toModelType() throws IllegalValueException { + + 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); + + return new Record(modelName); + } + } diff --git a/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java index ac6202fc212..5dbf2ddc8b5 100644 --- a/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java +++ b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.List; import java.util.Optional; import java.util.logging.Logger; @@ -45,14 +46,14 @@ public Optional readCookedRecord() throws DataConversi public Optional readCookedRecord(Path filePath) throws DataConversionException { requireNonNull(filePath); - Optional jsonCookedRecord = JsonUtil.readJsonFile( + Optional jsonCookedRecordBook = JsonUtil.readJsonFile( filePath, JsonSerializableCookedRecordBook.class); - if (!jsonCookedRecord.isPresent()) { + if (!jsonCookedRecordBook.isPresent()) { return Optional.empty(); } try { - return Optional.of(jsonCookedRecord.get().toModelType()); + return Optional.of(jsonCookedRecordBook.get().toModelType()); } catch (IllegalValueException ive) { logger.info("Illegal values found in " + filePath + ": " + ive.getMessage()); throw new DataConversionException(ive); @@ -74,7 +75,7 @@ public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePat requireNonNull(filePath); FileUtil.createIfMissing(filePath); - //JsonUtil.saveJsonFile(new JsonSerializableCookedRecordBook(cookedRecord), filePath); + JsonUtil.saveJsonFile(new JsonSerializableCookedRecordBook(cookedRecord), filePath); } } \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java index 4a4a2296c0e..eaa3ea4bc91 100644 --- a/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java +++ b/src/main/java/seedu/recipe/storage/JsonSerializableCookedRecordBook.java @@ -11,6 +11,7 @@ import seedu.recipe.commons.exceptions.IllegalValueException; import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.cooked.CookedRecordBook; +import seedu.recipe.model.cooked.Record; /** * An Immutable CookedRecordBook that is serializable to JSON format. @@ -20,48 +21,44 @@ class JsonSerializableCookedRecordBook { public static final String MESSAGE_COOKED_RECIPE = "Recipe has already been cooked."; - private final List records = new ArrayList<>(); + private final List records = new ArrayList<>(); /** * Constructs a {@code JsonSerializableCookedRecordBook} with the given records. */ @JsonCreator - public JsonSerializableCookedRecordBook(@JsonProperty("records") List recipes) { - this.records.addAll(recipes); - } - - public CookedRecordBook toModelType() { - return new CookedRecordBook(); + public JsonSerializableCookedRecordBook(@JsonProperty("records") List records) { + this.records.addAll(records); } /** - * Converts a given {@code ReadOnlyRecipeBook} into this class for Jackson use. + * Converts a given {@code ReadOnlyCookedRecordBook} into this class for Jackson use. * - * @param source future changes to this will not affect the created {@code JsonSerializableRecipeBook}. + * @param source future changes to this will not affect the created {@code JsonSerializableCookedRecordBook}. */ - /* + public JsonSerializableCookedRecordBook(ReadOnlyCookedRecordBook source) { records.addAll(source.getRecordsList().stream() .map(JsonAdaptedRecord::new).collect(Collectors.toList())); } -*/ + /** - * Converts this recipe book into the model's {@code RecipeBook} object. + * Converts this record book into the model's {@code CookedRecordBook} object. * * @throws IllegalValueException if there were any data constraints violated. */ - /* + public CookedRecordBook toModelType() throws IllegalValueException { CookedRecordBook cookedRecord = new CookedRecordBook(); for (JsonAdaptedRecord jsonAdaptedRecord : records) { - CookedRecordBook record = jsonAdaptedRecord.toModelType(); + Record record = jsonAdaptedRecord.toModelType(); if (cookedRecord.hasRecord(record)) { throw new IllegalValueException(MESSAGE_COOKED_RECIPE); } cookedRecord.addRecord(record); } return cookedRecord; - }*/ + } } From 954b1b62fa47f8c64f209b2c8b2884d38b5b12f1 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 01:54:47 +0800 Subject: [PATCH 05/15] added new json file --- data/cookedRecords.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 data/cookedRecords.json diff --git a/data/cookedRecords.json b/data/cookedRecords.json new file mode 100644 index 00000000000..efc3fc01293 --- /dev/null +++ b/data/cookedRecords.json @@ -0,0 +1,31 @@ +{ + "records" : [ { + "name" : "Vegan Thai Green Curry Soup" + }, { + "name" : "Thai Basil Ground Beef Bowl" + }, { + "name" : "Barley Pilaf" + }, { + "name" : "Asian BBQ Chicken" + }, { + "name" : "Sweet and Sour Chicken" + }, { + "name" : "Quick Carrot Daikon Stir-fry" + }, { + "name" : "Chinese Tomato Egg Stir-fry" + }, { + "name" : "5 Ingredient Spelt Spaghetti" + }, { + "name" : "Bacon, Spinach Caramelized Onion Pasta" + }, { + "name" : "Healthy Chicken Salad Sandwich" + }, { + "name" : "All Veggie Sandwich" + }, { + "name" : "Summer Asian Slaw" + }, { + "name" : "Avocado Couscous Grapefruit salad with honey lime dressing" + }, { + "name" : "testMissingIngredient" + } ] +} \ No newline at end of file From 52729f8cf37c66ae43d088041f424a757dd17c06 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 14:26:14 +0800 Subject: [PATCH 06/15] editted logic and model, successful build --- data/addressbook.json | 11 +++ data/cookedRecords.json | 18 ++-- src/main/java/seedu/recipe/MainApp.java | 21 ++++- src/main/java/seedu/recipe/logic/Logic.java | 7 ++ .../java/seedu/recipe/logic/LogicManager.java | 7 ++ .../recipe/logic/commands/CookedCommand.java | 6 +- src/main/java/seedu/recipe/model/Model.java | 6 ++ .../java/seedu/recipe/model/ModelManager.java | 20 +++- .../recipe/model/cooked/CookedRecordBook.java | 5 +- .../recipe/model/cooked/UniqueRecordList.java | 93 +++++++++++++++++-- 10 files changed, 166 insertions(+), 28 deletions(-) diff --git a/data/addressbook.json b/data/addressbook.json index 347c574157e..71313a1fe28 100644 --- a/data/addressbook.json +++ b/data/addressbook.json @@ -175,5 +175,16 @@ "others" : [ ], "steps" : [ ], "goals" : [ ] + }, { + "name" : "my gma Chicken RICE", + "time" : "20", + "isFavourite" : false, + "grains" : [ "50.0g, rice" ], + "vegetables" : [ ], + "proteins" : [ ], + "fruits" : [ ], + "others" : [ ], + "steps" : [ ], + "goals" : [ ] } ] } \ No newline at end of file diff --git a/data/cookedRecords.json b/data/cookedRecords.json index efc3fc01293..268679b1351 100644 --- a/data/cookedRecords.json +++ b/data/cookedRecords.json @@ -1,17 +1,5 @@ { "records" : [ { - "name" : "Vegan Thai Green Curry Soup" - }, { - "name" : "Thai Basil Ground Beef Bowl" - }, { - "name" : "Barley Pilaf" - }, { - "name" : "Asian BBQ Chicken" - }, { - "name" : "Sweet and Sour Chicken" - }, { - "name" : "Quick Carrot Daikon Stir-fry" - }, { "name" : "Chinese Tomato Egg Stir-fry" }, { "name" : "5 Ingredient Spelt Spaghetti" @@ -27,5 +15,11 @@ "name" : "Avocado Couscous Grapefruit salad with honey lime dressing" }, { "name" : "testMissingIngredient" + }, { + "name" : "Vegan Thai Green Curry Soup" + }, { + "name" : "Thai Basil Ground Beef Bowl" + }, { + "name" : "Barley Pilaf" } ] } \ No newline at end of file diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index 1dfa4a30889..fe776d90f75 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -82,7 +82,8 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { Optional recipeBookOptional; ReadOnlyRecipeBook initialData; //to be changed later - ReadOnlyCookedRecordBook stub = new CookedRecordBook(); + Optional recordBookOptional; + ReadOnlyCookedRecordBook initialRecords; try { recipeBookOptional = storage.readRecipeBook(); @@ -90,6 +91,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { logger.info("Data file not found. Will be starting with a sample RecipeBook"); } initialData = recipeBookOptional.orElseGet(SampleDataUtil::getSampleRecipeBook); + } catch (DataConversionException e) { logger.warning("Data file not in the correct format. Will be starting with an empty RecipeBook"); initialData = new RecipeBook(); @@ -98,7 +100,22 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { initialData = new RecipeBook(); } - return new ModelManager(initialData, userPrefs, stub); + try { + recordBookOptional = storage.readCookedRecord(); + if (!recordBookOptional.isPresent()) { + logger.info("Data file not found. Will be starting with a sample Recordbook"); + } + initialRecords = recordBookOptional.orElseGet(SampleDataUtil::getSampleRecordBook); + + } catch (DataConversionException e) { + logger.warning("Data file not in the correct format. Will be starting with an empty recordbook"); + initialRecords = new CookedRecordBook(); + } catch (IOException e) { + logger.warning("Problem while reading from the file. Will be starting with an empty recordbook"); + initialRecords = new CookedRecordBook(); + } + + return new ModelManager(initialData, userPrefs, initialRecords); } private void initLogging(Config config) { diff --git a/src/main/java/seedu/recipe/logic/Logic.java b/src/main/java/seedu/recipe/logic/Logic.java index aa060807f00..c3fc1a5e03d 100644 --- a/src/main/java/seedu/recipe/logic/Logic.java +++ b/src/main/java/seedu/recipe/logic/Logic.java @@ -8,6 +8,7 @@ import seedu.recipe.logic.commands.exceptions.CommandException; import seedu.recipe.logic.parser.exceptions.ParseException; import seedu.recipe.model.ReadOnlyRecipeBook; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.recipe.Recipe; /** @@ -47,4 +48,10 @@ public interface Logic { * Set the user prefs' GUI settings. */ void setGuiSettings(GuiSettings guiSettings); + + /** + * Returns an unmodifiable view of cooked records + * @return list + */ + ObservableList getFilteredRecordList(); } diff --git a/src/main/java/seedu/recipe/logic/LogicManager.java b/src/main/java/seedu/recipe/logic/LogicManager.java index cb930b44626..2f75439da3a 100644 --- a/src/main/java/seedu/recipe/logic/LogicManager.java +++ b/src/main/java/seedu/recipe/logic/LogicManager.java @@ -14,6 +14,7 @@ import seedu.recipe.logic.parser.exceptions.ParseException; import seedu.recipe.model.Model; import seedu.recipe.model.ReadOnlyRecipeBook; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.recipe.Recipe; import seedu.recipe.storage.Storage; @@ -43,6 +44,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE commandResult = command.execute(model); try { storage.saveRecipeBook(model.getRecipeBook()); + storage.saveCookedRecord(model.getRecordBook()); } catch (IOException ioe) { throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe); } @@ -74,4 +76,9 @@ public GuiSettings getGuiSettings() { public void setGuiSettings(GuiSettings guiSettings) { model.setGuiSettings(guiSettings); } + + @Override + public ObservableList getFilteredRecordList() { + return model.getFilteredRecordList(); + } } diff --git a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java index b36206d1a54..22bd011d5d0 100644 --- a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java +++ b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java @@ -21,6 +21,8 @@ public class CookedCommand extends Command { + "Parameters: INDEX NUMBER(s) (must be positive integers)\n" + "Example: " + COMMAND_WORD + " 1"; + public static final String MESSAGE_DUPLICATE_RECORD = "This recipe has already been added!"; + private final Index[] targetIndex; public CookedCommand(Index[] targetIndex) { @@ -37,10 +39,12 @@ public CommandResult execute(Model model) throws CommandException { if (targetIndex[i].getZeroBased() >= mostRecentList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_RECIPE_DISPLAYED_INDEX); } - Recipe recipeCooked = mostRecentList.get(targetIndex[i].getZeroBased()); Date now = new Date(); Record record = new Record(recipeCooked.getName()); + if (model.hasRecord(record)) { + throw new CommandException(MESSAGE_DUPLICATE_RECORD); + } model.addRecord(record); if (i == targetIndex.length - 1 && targetIndex.length != 1) { sb.append(" and "); diff --git a/src/main/java/seedu/recipe/model/Model.java b/src/main/java/seedu/recipe/model/Model.java index 0664ad152af..d8debf93094 100644 --- a/src/main/java/seedu/recipe/model/Model.java +++ b/src/main/java/seedu/recipe/model/Model.java @@ -136,4 +136,10 @@ public interface Model { */ void addRecord(Record record); + + ObservableList getFilteredRecordList(); + + ReadOnlyCookedRecordBook getRecordBook(); + + boolean hasRecord(Record record); } diff --git a/src/main/java/seedu/recipe/model/ModelManager.java b/src/main/java/seedu/recipe/model/ModelManager.java index d8764e12efb..e5773367d3b 100644 --- a/src/main/java/seedu/recipe/model/ModelManager.java +++ b/src/main/java/seedu/recipe/model/ModelManager.java @@ -29,7 +29,7 @@ public class ModelManager implements Model { private final VersionedRecipeBook states; private final PlannedRecipeMap plannedRecipes; private final CookedRecordBook cookedRecordBook; - private final FilteredList records; + private final FilteredList filteredRecords; /** * Initializes a ModelManager with the given recipeBook and userPrefs. @@ -46,7 +46,7 @@ public ModelManager(ReadOnlyRecipeBook recipeBook, ReadOnlyUserPrefs userPrefs, filteredRecipes = new FilteredList<>(this.recipeBook.getRecipeList()); this.states = new VersionedRecipeBook(recipeBook); this.cookedRecordBook = new CookedRecordBook(cookedRecordBook); - this.records = new FilteredList<>(this.cookedRecordBook.getRecordsList()); + this.filteredRecords = new FilteredList<>(this.cookedRecordBook.getRecordsList()); plannedRecipes = new PlannedRecipeMap(); // todo: planned recipes cant be saved currently } @@ -209,4 +209,20 @@ public void addRecord(Record record) { cookedRecordBook.addRecord(record); } + @Override + public ObservableList getFilteredRecordList() { + return filteredRecords; + } + + @Override + public ReadOnlyCookedRecordBook getRecordBook() { + return cookedRecordBook; + } + + @Override + public boolean hasRecord(Record record) { + requireNonNull(record); + return cookedRecordBook.hasRecord(record); + } + } diff --git a/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java b/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java index 928037849fc..1b2249f079f 100644 --- a/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java +++ b/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java @@ -6,6 +6,7 @@ import javafx.collections.ObservableList; import seedu.recipe.model.ReadOnlyCookedRecordBook; +import seedu.recipe.model.recipe.Recipe; /** * Wraps all data at the address-book level @@ -83,7 +84,7 @@ public void addRecord(Record p) { public void setRecord(Record target, Record editedRecord) { requireNonNull(editedRecord); - records.setRecipe(target, editedRecord); + records.setRecord(target, editedRecord); } /** @@ -117,6 +118,6 @@ public int hashCode() { @Override public ObservableList getRecordsList() { - return null; + return records.asUnmodifiableObservableList(); } } diff --git a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java index 48b013fc05c..5f59bb8790f 100644 --- a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java +++ b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java @@ -1,27 +1,102 @@ package seedu.recipe.model.cooked; +import static java.util.Objects.requireNonNull; +import static seedu.recipe.commons.util.CollectionUtil.requireAllNonNull; + import java.util.ArrayList; -import java.util.Collection; +import java.util.Iterator; import java.util.List; -public class UniqueRecordList { +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import seedu.recipe.model.recipe.Recipe; +import seedu.recipe.model.recipe.exceptions.DuplicateRecipeException; +import seedu.recipe.model.recipe.exceptions.RecipeNotFoundException; + +public class UniqueRecordList implements Iterable { + + private final ObservableList internalList = FXCollections.observableArrayList(); + private final ObservableList internalUnmodifiableList = + FXCollections.unmodifiableObservableList(internalList); + + public void setRecords(UniqueRecordList replacement) { + requireNonNull(replacement); + internalList.setAll(replacement.internalList); + } + + /** + * Replaces the contents of this list with {@code recipes}. + * {@code recipes} must not contain duplicate recipes. + */ public void setRecords(List records) { + requireAllNonNull(records); + if (!recordsAreUnique(records)) { + throw new DuplicateRecipeException(); + } + + internalList.setAll(records); } - public boolean contains(Record record) { - return false; + /** + * Returns true if {@code recipes} contains only unique recipes. + */ + private boolean recordsAreUnique(List records) { + for (int i = 0; i < records.size() - 1; i++) { + for (int j = i + 1; j < records.size(); j++) { + if (records.get(i).isSameRecord(records.get(j))) { + return false; + } + } + } + return true; } - public void add(Record p) { + public boolean contains(Record toCheck) { + requireNonNull(toCheck); + return internalList.stream().anyMatch(toCheck::isSameRecord); + } + + /** + * Adds a record to the list. + * The record must not already exist in the list. + */ + public void add(Record toAdd) { + requireNonNull(toAdd); + if (contains(toAdd)) { + throw new DuplicateRecipeException(); + } + internalList.add(toAdd); + } + + public void setRecord(Record target, Record editedRecord) { + requireAllNonNull(target, editedRecord); + + int index = internalList.indexOf(target); + if (index == -1) { + //exception to be changed + throw new RecipeNotFoundException(); + } + + if (!target.isSameRecord(editedRecord) && contains(editedRecord)) { + throw new DuplicateRecipeException(); + } + + internalList.set(index, editedRecord); } - public void setRecipe(Record target, Record editedRecord) { + public void remove(Record toRemove) { + requireNonNull(toRemove); + if (!internalList.remove(toRemove)) { + throw new RecipeNotFoundException(); + } } - public void remove(Record key) { + public ObservableList asUnmodifiableObservableList() { + return internalUnmodifiableList; } - public Collection asUnmodifiableObservableList() { - return new ArrayList<>(); + @Override + public Iterator iterator() { + return internalList.iterator(); } } From 23779d86faddef1391d6428d9805f90649f77a36 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 15:40:30 +0800 Subject: [PATCH 07/15] fixed naming of cookedrecordbook --- data/cookedRecords.json | 2 ++ src/main/java/seedu/recipe/MainApp.java | 10 +++++---- .../java/seedu/recipe/logic/LogicManager.java | 2 +- .../recipe/model/util/SampleDataUtil.java | 12 +++++----- .../storage/CookedRecordBookStorage.java | 19 ++++++++-------- .../storage/JsonCookedRecordBookStorage.java | 22 +++++++++---------- .../java/seedu/recipe/storage/Storage.java | 6 ++--- .../seedu/recipe/storage/StorageManager.java | 20 ++++++++--------- 8 files changed, 48 insertions(+), 45 deletions(-) diff --git a/data/cookedRecords.json b/data/cookedRecords.json index 268679b1351..9f72c66ac74 100644 --- a/data/cookedRecords.json +++ b/data/cookedRecords.json @@ -21,5 +21,7 @@ "name" : "Thai Basil Ground Beef Bowl" }, { "name" : "Barley Pilaf" + }, { + "name" : "Asian BBQ Chicken" } ] } \ No newline at end of file diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index fe776d90f75..f479f7a0c64 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -61,8 +61,9 @@ public void init() throws Exception { UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath()); UserPrefs userPrefs = initPrefs(userPrefsStorage); RecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(userPrefs.getRecipeBookFilePath()); - CookedRecordBookStorage cookedRecordStorage = new JsonCookedRecordBookStorage(userPrefs.getCookedRecordFilePath()); - storage = new StorageManager(recipeBookStorage, cookedRecordStorage, userPrefsStorage); + CookedRecordBookStorage cookedRecordBookStorage = new JsonCookedRecordBookStorage( + userPrefs.getCookedRecordFilePath()); + storage = new StorageManager(recipeBookStorage, cookedRecordBookStorage, userPrefsStorage); initLogging(config); @@ -96,12 +97,13 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { logger.warning("Data file not in the correct format. Will be starting with an empty RecipeBook"); initialData = new RecipeBook(); } catch (IOException e) { - logger.warning("Problem while reading from the file. Will be starting with an empty RecipeBook"); + logger.warning("Problem while reading from the file for recipes. " + + "Will be starting with an empty RecipeBook"); initialData = new RecipeBook(); } try { - recordBookOptional = storage.readCookedRecord(); + recordBookOptional = storage.readCookedRecordBook(); if (!recordBookOptional.isPresent()) { logger.info("Data file not found. Will be starting with a sample Recordbook"); } diff --git a/src/main/java/seedu/recipe/logic/LogicManager.java b/src/main/java/seedu/recipe/logic/LogicManager.java index 2f75439da3a..fedd6f6a828 100644 --- a/src/main/java/seedu/recipe/logic/LogicManager.java +++ b/src/main/java/seedu/recipe/logic/LogicManager.java @@ -44,7 +44,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE commandResult = command.execute(model); try { storage.saveRecipeBook(model.getRecipeBook()); - storage.saveCookedRecord(model.getRecordBook()); + storage.saveCookedRecordBook(model.getRecordBook()); } catch (IOException ioe) { throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe); } diff --git a/src/main/java/seedu/recipe/model/util/SampleDataUtil.java b/src/main/java/seedu/recipe/model/util/SampleDataUtil.java index 83d6e5b331f..830d1082d18 100644 --- a/src/main/java/seedu/recipe/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/recipe/model/util/SampleDataUtil.java @@ -200,12 +200,12 @@ public static Set emptyGrainSet() { public static Record[] getSampleRecords() { return new Record[] { - new Record(new Name("Caesar Salad")), - new Record(new Name("Grilled Sandwich")), - new Record(new Name("Boiled Chicken")), - new Record(new Name("Chocolate Cake")), - new Record(new Name("Omelet")), - new Record(new Name("Tuna Bread")) + new Record(new Name("Caesar Salad")), + new Record(new Name("Grilled Sandwich")), + new Record(new Name("Boiled Chicken")), + new Record(new Name("Chocolate Cake")), + new Record(new Name("Omelet")), + new Record(new Name("Tuna Bread")) }; } diff --git a/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java b/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java index d5f423af22c..410b9c003c4 100644 --- a/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java +++ b/src/main/java/seedu/recipe/storage/CookedRecordBookStorage.java @@ -16,7 +16,7 @@ public interface CookedRecordBookStorage { /** * Returns the file path of the data file. */ - Path getCookedRecordFilePath(); + Path getCookedRecordBookFilePath(); /** * Returns CookedRecordBook data as a {@link ReadOnlyCookedRecordBook}. @@ -24,23 +24,22 @@ public interface CookedRecordBookStorage { * @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 readCookedRecord() throws DataConversionException, IOException; + Optional readCookedRecordBook() throws DataConversionException, IOException; /** - * @see #getCookedRecordFilePath() + * @see #getCookedRecordBookFilePath() */ - Optional readCookedRecord(Path filePath) throws DataConversionException, IOException; + Optional readCookedRecordBook(Path filePath) throws DataConversionException, IOException; /** * Saves the given {@link ReadOnlyCookedRecordBook} to the storage. - * @param cookedRecord cannot be null. + * @param cookedRecordBook cannot be null. * @throws IOException if there was any problem writing to the file. */ - void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException; + void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook) throws IOException; /** - * @see #saveCookedRecord(ReadOnlyCookedRecordBook) + * @see #saveCookedRecordBook(ReadOnlyCookedRecordBook) */ - void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePath) throws IOException; - -} \ No newline at end of file + void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook, Path filePath) throws IOException; +} diff --git a/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java index 5dbf2ddc8b5..1ef9bb421ed 100644 --- a/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java +++ b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java @@ -28,22 +28,22 @@ public JsonCookedRecordBookStorage(Path filePath) { this.filePath = filePath; } - public Path getCookedRecordFilePath() { + public Path getCookedRecordBookFilePath() { return filePath; } @Override - public Optional readCookedRecord() throws DataConversionException { - return readCookedRecord(filePath); + public Optional readCookedRecordBook() throws DataConversionException { + return readCookedRecordBook(filePath); } /** - * Similar to {@link #readCookedRecord()}. + * Similar to {@link #readCookedRecordBook()}. * * @param filePath location of the data. Cannot be null. * @throws DataConversionException if the file is not in the correct format. */ - public Optional readCookedRecord(Path filePath) throws DataConversionException { + public Optional readCookedRecordBook(Path filePath) throws DataConversionException { requireNonNull(filePath); Optional jsonCookedRecordBook = JsonUtil.readJsonFile( @@ -61,21 +61,21 @@ public Optional readCookedRecord(Path filePath) throws } @Override - public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException { - saveCookedRecord(cookedRecord, filePath); + public void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook) throws IOException { + saveCookedRecordBook(cookedRecordBook, filePath); } /** - * Similar to {@link #saveCookedRecord(ReadOnlyCookedRecordBook)}. + * Similar to {@link #saveCookedRecordBook(ReadOnlyCookedRecordBook)}. * * @param filePath location of the data. Cannot be null. */ - public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePath) throws IOException { - requireNonNull(cookedRecord); + public void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook, Path filePath) throws IOException { + requireNonNull(cookedRecordBook); requireNonNull(filePath); FileUtil.createIfMissing(filePath); - JsonUtil.saveJsonFile(new JsonSerializableCookedRecordBook(cookedRecord), filePath); + JsonUtil.saveJsonFile(new JsonSerializableCookedRecordBook(cookedRecordBook), filePath); } } \ No newline at end of file diff --git a/src/main/java/seedu/recipe/storage/Storage.java b/src/main/java/seedu/recipe/storage/Storage.java index aa4b3e87241..119e1d50654 100644 --- a/src/main/java/seedu/recipe/storage/Storage.java +++ b/src/main/java/seedu/recipe/storage/Storage.java @@ -31,12 +31,12 @@ public interface Storage extends RecipeBookStorage, CookedRecordBookStorage, Use void saveRecipeBook(ReadOnlyRecipeBook recipeBook) throws IOException; @Override - Path getCookedRecordFilePath(); + Path getCookedRecordBookFilePath(); @Override - Optional readCookedRecord() throws DataConversionException, IOException; + Optional readCookedRecordBook() throws DataConversionException, IOException; @Override - void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException; + void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook) throws IOException; } diff --git a/src/main/java/seedu/recipe/storage/StorageManager.java b/src/main/java/seedu/recipe/storage/StorageManager.java index e395a36e2cf..5094857e91d 100644 --- a/src/main/java/seedu/recipe/storage/StorageManager.java +++ b/src/main/java/seedu/recipe/storage/StorageManager.java @@ -81,30 +81,30 @@ public void saveRecipeBook(ReadOnlyRecipeBook recipeBook, Path filePath) throws // ================ CookedRecordBook methods ============================== @Override - public Path getCookedRecordFilePath() { - return cookedRecordStorage.getCookedRecordFilePath(); + public Path getCookedRecordBookFilePath() { + return cookedRecordStorage.getCookedRecordBookFilePath(); } @Override - public Optional readCookedRecord() throws DataConversionException, IOException { - return readCookedRecord(cookedRecordStorage.getCookedRecordFilePath()); + public Optional readCookedRecordBook() throws DataConversionException, IOException { + return readCookedRecordBook(cookedRecordStorage.getCookedRecordBookFilePath()); } @Override - public Optional readCookedRecord(Path filePath) throws DataConversionException, IOException { + public Optional readCookedRecordBook(Path filePath) throws DataConversionException, IOException { logger.fine("Attempting to read data from file: " + filePath); - return cookedRecordStorage.readCookedRecord(filePath); + return cookedRecordStorage.readCookedRecordBook(filePath); } @Override - public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord) throws IOException { - saveCookedRecord(cookedRecord, cookedRecordStorage.getCookedRecordFilePath()); + public void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook) throws IOException { + saveCookedRecordBook(cookedRecordBook, cookedRecordStorage.getCookedRecordBookFilePath()); } @Override - public void saveCookedRecord(ReadOnlyCookedRecordBook cookedRecord, Path filePath) throws IOException { + public void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook, Path filePath) throws IOException { logger.fine("Attempting to write to data file: " + filePath); - cookedRecordStorage.saveCookedRecord(cookedRecord, filePath); + cookedRecordStorage.saveCookedRecordBook(cookedRecordBook, filePath); } } From 59d0ecce94e5d2921c6948a497f78a9e492da72a Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 19:28:51 +0800 Subject: [PATCH 08/15] tests pass --- src/main/java/seedu/recipe/MainApp.java | 2 +- .../recipe/logic/commands/CookedCommand.java | 4 +- .../logic/parser/CookedCommandParser.java | 3 ++ src/main/java/seedu/recipe/model/Model.java | 10 +++- .../model/ReadOnlyCookedRecordBook.java | 3 +- .../recipe/model/cooked/CookedRecordBook.java | 1 - .../seedu/recipe/model/cooked/Record.java | 5 +- .../recipe/model/cooked/UniqueRecordList.java | 25 ++++++++- .../recipe/storage/JsonAdaptedRecord.java | 4 -- .../storage/JsonCookedRecordBookStorage.java | 4 +- .../seedu/recipe/storage/StorageManager.java | 3 +- .../seedu/recipe/logic/LogicManagerTest.java | 11 ++-- .../commands/AddCommandIntegrationTest.java | 5 +- .../recipe/logic/commands/AddCommandTest.java | 22 ++++++++ .../logic/commands/ClearCommandTest.java | 5 +- .../logic/commands/DeleteCommandTest.java | 9 ++-- .../logic/commands/EditCommandTest.java | 16 ++++-- .../logic/commands/FindCommandTest.java | 5 +- .../logic/commands/ListCommandTest.java | 5 +- .../seedu/recipe/model/ModelManagerTest.java | 18 +++++-- .../recipe/storage/StorageManagerTest.java | 3 +- .../recipe/testutil/RecordBookBuilder.java | 35 ++++++++++++ .../seedu/recipe/testutil/RecordBuilder.java | 40 ++++++++++++++ .../seedu/recipe/testutil/TypicalRecords.java | 54 +++++++++++++++++++ 24 files changed, 250 insertions(+), 42 deletions(-) create mode 100644 src/test/java/seedu/recipe/testutil/RecordBookBuilder.java create mode 100644 src/test/java/seedu/recipe/testutil/RecordBuilder.java create mode 100644 src/test/java/seedu/recipe/testutil/TypicalRecords.java diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index f479f7a0c64..d1c8a0c7e3b 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -25,8 +25,8 @@ import seedu.recipe.model.cooked.CookedRecordBook; import seedu.recipe.model.util.SampleDataUtil; import seedu.recipe.storage.CookedRecordBookStorage; -import seedu.recipe.storage.JsonRecipeBookStorage; import seedu.recipe.storage.JsonCookedRecordBookStorage; +import seedu.recipe.storage.JsonRecipeBookStorage; import seedu.recipe.storage.JsonUserPrefsStorage; import seedu.recipe.storage.RecipeBookStorage; import seedu.recipe.storage.Storage; diff --git a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java index 22bd011d5d0..371720f9f46 100644 --- a/src/main/java/seedu/recipe/logic/commands/CookedCommand.java +++ b/src/main/java/seedu/recipe/logic/commands/CookedCommand.java @@ -1,6 +1,5 @@ package seedu.recipe.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.recipe.model.Model.PREDICATE_SHOW_ALL_RECIPES; import java.util.Arrays; import java.util.Date; @@ -13,6 +12,9 @@ import seedu.recipe.model.cooked.Record; import seedu.recipe.model.recipe.Recipe; +/** + * Adds cooked recipes identified by index into cookedRecordsBook. + */ public class CookedCommand extends Command { public static final String COMMAND_WORD = "cooked"; diff --git a/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java b/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java index eadaa351975..4c3315f83eb 100644 --- a/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java +++ b/src/main/java/seedu/recipe/logic/parser/CookedCommandParser.java @@ -6,6 +6,9 @@ import seedu.recipe.logic.commands.CookedCommand; import seedu.recipe.logic.parser.exceptions.ParseException; +/** + * Parses input arguments and creates a new CookedCommand object + */ public class CookedCommandParser implements Parser { /** diff --git a/src/main/java/seedu/recipe/model/Model.java b/src/main/java/seedu/recipe/model/Model.java index d8debf93094..a284cba37c0 100644 --- a/src/main/java/seedu/recipe/model/Model.java +++ b/src/main/java/seedu/recipe/model/Model.java @@ -5,9 +5,9 @@ import javafx.collections.ObservableList; import seedu.recipe.commons.core.GuiSettings; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.plan.Date; import seedu.recipe.model.recipe.Recipe; -import seedu.recipe.model.cooked.Record; /** * The API of the Model component. @@ -134,12 +134,18 @@ public interface Model { /** * Adds a record in the cookedRecord list */ - void addRecord(Record record); + /** Returns an unmodifiable view of the filtered record list */ ObservableList getFilteredRecordList(); + /** + * Replaces record book data with the data in {@code CookedRecordBook}. + */ ReadOnlyCookedRecordBook getRecordBook(); + /** + * Returns true if a record with the same identity as {@code record} exists in the record book. + */ boolean hasRecord(Record record); } diff --git a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java index 354f5d7ca84..dc4db366173 100644 --- a/src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java +++ b/src/main/java/seedu/recipe/model/ReadOnlyCookedRecordBook.java @@ -13,5 +13,4 @@ public interface ReadOnlyCookedRecordBook { * This list contains history of cooked meals */ ObservableList getRecordsList(); - -} \ No newline at end of file +} diff --git a/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java b/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java index 1b2249f079f..e16d087ff62 100644 --- a/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java +++ b/src/main/java/seedu/recipe/model/cooked/CookedRecordBook.java @@ -6,7 +6,6 @@ import javafx.collections.ObservableList; import seedu.recipe.model.ReadOnlyCookedRecordBook; -import seedu.recipe.model.recipe.Recipe; /** * Wraps all data at the address-book level diff --git a/src/main/java/seedu/recipe/model/cooked/Record.java b/src/main/java/seedu/recipe/model/cooked/Record.java index d4af40533cb..e92fcb225ed 100644 --- a/src/main/java/seedu/recipe/model/cooked/Record.java +++ b/src/main/java/seedu/recipe/model/cooked/Record.java @@ -2,11 +2,14 @@ import static seedu.recipe.commons.util.CollectionUtil.requireAllNonNull; -import java.util.Date; import java.util.Objects; import seedu.recipe.model.recipe.Name; +/** + * Represents a Record in the cooked records book. + * Guarantees: details are present and not null, field values are validated, immutable. + */ public class Record { // Identity fields diff --git a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java index 5f59bb8790f..c10e237825b 100644 --- a/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java +++ b/src/main/java/seedu/recipe/model/cooked/UniqueRecordList.java @@ -3,7 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.recipe.commons.util.CollectionUtil.requireAllNonNull; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -13,12 +12,24 @@ import seedu.recipe.model.recipe.exceptions.DuplicateRecipeException; import seedu.recipe.model.recipe.exceptions.RecipeNotFoundException; +/** + * A list of records that enforces uniqueness between its elements and does not allow nulls. + * A record is considered unique by comparing using {@code Record#isSameRecord(Record)}. As such, adding and updating of + * records uses Record#isSameRecord(Record) for equality so as to ensure that the recipe being added or updated is + * unique in terms of identity in the UniqueRecipeList. However, the removal of a record uses Record#equals(Object) so + * as to ensure that the record with exactly the same fields will be removed. + * + * Supports a minimal set of list operations. + * + * @see Recipe#isSameRecipe(Recipe) + */ public class UniqueRecordList implements Iterable { private final ObservableList internalList = FXCollections.observableArrayList(); private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); + public void setRecords(UniqueRecordList replacement) { requireNonNull(replacement); internalList.setAll(replacement.internalList); @@ -51,6 +62,9 @@ private boolean recordsAreUnique(List records) { return true; } + /** + * Returns true if the list contains an equivalent record as the given argument. + */ public boolean contains(Record toCheck) { requireNonNull(toCheck); return internalList.stream().anyMatch(toCheck::isSameRecord); @@ -68,6 +82,11 @@ public void add(Record toAdd) { internalList.add(toAdd); } + /** + * Replaces the record {@code target} in the list with {@code editedRecord}. + * {@code target} must exist in the list. + * The recipe identity of {@code editedRecord} must not be the same as another existing record in the list. + */ public void setRecord(Record target, Record editedRecord) { requireAllNonNull(target, editedRecord); @@ -84,6 +103,10 @@ public void setRecord(Record target, Record editedRecord) { internalList.set(index, editedRecord); } + /** + * Removes the equivalent record from the list. + * The record must exist in the list. + */ public void remove(Record toRemove) { requireNonNull(toRemove); if (!internalList.remove(toRemove)) { diff --git a/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java index 71ecdcba9ac..ee73a8b792b 100644 --- a/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java +++ b/src/main/java/seedu/recipe/storage/JsonAdaptedRecord.java @@ -1,15 +1,11 @@ package seedu.recipe.storage; -import java.util.Date; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import seedu.recipe.commons.exceptions.IllegalValueException; import seedu.recipe.model.cooked.Record; import seedu.recipe.model.recipe.Name; -import seedu.recipe.model.recipe.Recipe; - /** * Jackson-friendly version of {@link Record}. diff --git a/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java index 1ef9bb421ed..5b8f992312f 100644 --- a/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java +++ b/src/main/java/seedu/recipe/storage/JsonCookedRecordBookStorage.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.List; import java.util.Optional; import java.util.logging.Logger; @@ -77,5 +76,4 @@ public void saveCookedRecordBook(ReadOnlyCookedRecordBook cookedRecordBook, Path FileUtil.createIfMissing(filePath); JsonUtil.saveJsonFile(new JsonSerializableCookedRecordBook(cookedRecordBook), filePath); } - -} \ No newline at end of file +} diff --git a/src/main/java/seedu/recipe/storage/StorageManager.java b/src/main/java/seedu/recipe/storage/StorageManager.java index 5094857e91d..9041b710e3e 100644 --- a/src/main/java/seedu/recipe/storage/StorageManager.java +++ b/src/main/java/seedu/recipe/storage/StorageManager.java @@ -91,7 +91,8 @@ public Optional readCookedRecordBook() throws DataConv } @Override - public Optional readCookedRecordBook(Path filePath) throws DataConversionException, IOException { + public Optional readCookedRecordBook(Path filePath) throws DataConversionException, + IOException { logger.fine("Attempting to read data from file: " + filePath); return cookedRecordStorage.readCookedRecordBook(filePath); } diff --git a/src/test/java/seedu/recipe/logic/LogicManagerTest.java b/src/test/java/seedu/recipe/logic/LogicManagerTest.java index 383ae5e3d9a..fb8f8d55e70 100644 --- a/src/test/java/seedu/recipe/logic/LogicManagerTest.java +++ b/src/test/java/seedu/recipe/logic/LogicManagerTest.java @@ -31,6 +31,7 @@ import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.UserPrefs; import seedu.recipe.model.recipe.Recipe; +import seedu.recipe.storage.JsonCookedRecordBookStorage; import seedu.recipe.storage.JsonRecipeBookStorage; import seedu.recipe.storage.JsonUserPrefsStorage; import seedu.recipe.storage.StorageManager; @@ -50,7 +51,9 @@ public void setUp() { JsonRecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(temporaryFolder.resolve("recipeBook.json")); JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("userPrefs.json")); - StorageManager storage = new StorageManager(recipeBookStorage, userPrefsStorage); + JsonCookedRecordBookStorage recordBookStorage = + new JsonCookedRecordBookStorage(temporaryFolder.resolve("cookedRecordBook.json")); + StorageManager storage = new StorageManager(recipeBookStorage, recordBookStorage, userPrefsStorage); logic = new LogicManager(model, storage); } @@ -79,7 +82,9 @@ public void execute_storageThrowsIoException_throwsCommandException() { new JsonRecipeBookIoExceptionThrowingStub(temporaryFolder.resolve("ioExceptionRecipeBook.json")); JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("ioExceptionUserPrefs.json")); - StorageManager storage = new StorageManager(recipeBookStorage, userPrefsStorage); + JsonCookedRecordBookStorage recordBookStorage = + new JsonCookedRecordBookStorage(temporaryFolder.resolve("ioExceptionRecordBook.json")); + StorageManager storage = new StorageManager(recipeBookStorage, recordBookStorage, userPrefsStorage); logic = new LogicManager(model, storage); // Execute add command @@ -134,7 +139,7 @@ private void assertCommandException(String inputCommand, String expectedMessage) */ private void assertCommandFailure(String inputCommand, Class expectedException, String expectedMessage) { - Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs()); + Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); assertCommandFailure(inputCommand, expectedException, expectedMessage, expectedModel); } diff --git a/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java b/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java index 25a7ab8f673..f0082fdb396 100644 --- a/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java +++ b/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java @@ -3,6 +3,7 @@ import static seedu.recipe.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.recipe.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; +import static seedu.recipe.testutil.TypicalRecords.getTypicalRecordBook; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,14 +23,14 @@ public class AddCommandIntegrationTest { @BeforeEach public void setUp() { - model = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); + model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); } @Test public void execute_newRecipe_success() { Recipe validRecipe = new RecipeBuilder().build(); - Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs()); + Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); // System.out.println(validRecipe); // todo remove later expectedModel.addRecipe(validRecipe); diff --git a/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java b/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java index bcbed26776d..30c4d845374 100644 --- a/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java @@ -17,9 +17,11 @@ import seedu.recipe.commons.core.GuiSettings; import seedu.recipe.logic.commands.exceptions.CommandException; import seedu.recipe.model.Model; +import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.RecipeBook; +import seedu.recipe.model.cooked.Record; import seedu.recipe.model.plan.Date; import seedu.recipe.model.recipe.Recipe; import seedu.recipe.testutil.RecipeBuilder; @@ -188,6 +190,26 @@ public void updateFilteredRecipeList(Predicate predicate) { public void planRecipe(Recipe recipeToSet, Date atDate) { throw new AssertionError("This method should not be called."); } + + @Override + public void addRecord(Record record) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ObservableList getFilteredRecordList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public ReadOnlyCookedRecordBook getRecordBook() { + throw new AssertionError("This method should not be called."); + } + + @Override + public boolean hasRecord(Record record) { + throw new AssertionError("This method should not be called."); + } } /** diff --git a/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java b/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java index 7f36e0ad032..b6922069709 100644 --- a/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java @@ -2,6 +2,7 @@ import static seedu.recipe.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; +import static seedu.recipe.testutil.TypicalRecords.getTypicalRecordBook; import org.junit.jupiter.api.Test; @@ -22,8 +23,8 @@ public void execute_emptyRecipeBook_success() { @Test public void execute_nonEmptyRecipeBook_success() { - Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); - Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); + Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); + Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); expectedModel.setRecipeBook(new RecipeBook()); assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); diff --git a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java index 17076a9764d..1ed0c75eddd 100644 --- a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java @@ -8,6 +8,7 @@ import static seedu.recipe.testutil.TypicalIndexes.INDEX_FIRST_RECIPE; import static seedu.recipe.testutil.TypicalIndexes.INDEX_SECOND_RECIPE; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; +import static seedu.recipe.testutil.TypicalRecords.getTypicalRecordBook; import org.junit.jupiter.api.Test; @@ -15,6 +16,7 @@ import seedu.recipe.commons.core.index.Index; import seedu.recipe.model.Model; import seedu.recipe.model.ModelManager; +import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.UserPrefs; import seedu.recipe.model.recipe.Recipe; @@ -24,7 +26,8 @@ */ public class DeleteCommandTest { - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); + @Test public void execute_validIndexUnfilteredList_success() { @@ -34,7 +37,7 @@ public void execute_validIndexUnfilteredList_success() { String expectedMessageTemplate = "Deleted %1$s from recipe book!"; String expectedMessage = String.format(expectedMessageTemplate, recipeToDelete.getName().toString()); - ModelManager expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs()); + ModelManager expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); expectedModel.deleteRecipe(recipeToDelete); assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); @@ -58,7 +61,7 @@ public void execute_validIndexFilteredList_success() { String expectedMessageTemplate = "Deleted %1$s from recipe book!"; String expectedMessage = String.format(expectedMessageTemplate, recipeToDelete.getName().toString()); - Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs()); + Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); expectedModel.deleteRecipe(recipeToDelete); showNoRecipe(expectedModel); diff --git a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java index eff402b66a1..0efb599521d 100644 --- a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java @@ -15,6 +15,7 @@ import static seedu.recipe.testutil.TypicalIndexes.INDEX_FIRST_RECIPE; import static seedu.recipe.testutil.TypicalIndexes.INDEX_SECOND_RECIPE; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; +import static seedu.recipe.testutil.TypicalRecords.getTypicalRecordBook; import org.junit.jupiter.api.Test; @@ -25,6 +26,7 @@ import seedu.recipe.model.ModelManager; import seedu.recipe.model.RecipeBook; import seedu.recipe.model.UserPrefs; +import seedu.recipe.model.cooked.CookedRecordBook; import seedu.recipe.model.recipe.Recipe; import seedu.recipe.testutil.EditRecipeDescriptorBuilder; import seedu.recipe.testutil.RecipeBuilder; @@ -34,7 +36,7 @@ */ public class EditCommandTest { - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); // todo: bug: test might fail sometimes if recipe at TypicalRecipes index 0 has ingredients @Test @@ -45,7 +47,8 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), + new CookedRecordBook(model.getRecordBook())); expectedModel.setRecipe(model.getFilteredRecipeList().get(0), editedRecipe); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -66,7 +69,8 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), + new CookedRecordBook(model.getRecordBook())); expectedModel.setRecipe(lastRecipe, editedRecipe); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -79,7 +83,8 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), + new CookedRecordBook(model.getRecordBook())); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); } @@ -95,7 +100,8 @@ public void execute_filteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), + new CookedRecordBook(model.getRecordBook())); expectedModel.setRecipe(model.getFilteredRecipeList().get(0), editedRecipe); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java b/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java index 6551f7b2113..4b662ee7dda 100644 --- a/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java @@ -6,6 +6,7 @@ import static seedu.recipe.commons.core.Messages.MESSAGE_RECIPES_LISTED_OVERVIEW; import static seedu.recipe.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; +import static seedu.recipe.testutil.TypicalRecords.getTypicalRecordBook; import java.util.Arrays; import java.util.Collections; @@ -21,8 +22,8 @@ * Contains integration tests (interaction with the Model) for {@code FindCommand}. */ public class FindCommandTest { - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); - private Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); + private Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); @Test public void equals() { diff --git a/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java b/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java index 754297bb986..38237b5b674 100644 --- a/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java @@ -4,6 +4,7 @@ import static seedu.recipe.logic.commands.CommandTestUtil.showRecipeAtIndex; import static seedu.recipe.testutil.TypicalIndexes.INDEX_FIRST_RECIPE; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; +import static seedu.recipe.testutil.TypicalRecords.getTypicalRecordBook; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,8 +23,8 @@ public class ListCommandTest { @BeforeEach public void setUp() { - model = new ModelManager(getTypicalRecipeBook(), new UserPrefs()); - expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs()); + model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); + expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); } @Test diff --git a/src/test/java/seedu/recipe/model/ModelManagerTest.java b/src/test/java/seedu/recipe/model/ModelManagerTest.java index 796578a21ff..1b1ed6b747a 100644 --- a/src/test/java/seedu/recipe/model/ModelManagerTest.java +++ b/src/test/java/seedu/recipe/model/ModelManagerTest.java @@ -7,6 +7,9 @@ import static seedu.recipe.testutil.Assert.assertThrows; import static seedu.recipe.testutil.TypicalRecipes.CAESAR_SALAD; import static seedu.recipe.testutil.TypicalRecipes.GRILLED_SANDWICH; +import static seedu.recipe.testutil.TypicalRecords.CHOCOLATE_CAKE; +import static seedu.recipe.testutil.TypicalRecords.BOILED_CHICKEN; + import java.nio.file.Path; import java.nio.file.Paths; @@ -15,8 +18,10 @@ import org.junit.jupiter.api.Test; import seedu.recipe.commons.core.GuiSettings; +import seedu.recipe.model.cooked.CookedRecordBook; import seedu.recipe.model.recipe.NameContainsKeywordsPredicate; import seedu.recipe.testutil.RecipeBookBuilder; +import seedu.recipe.testutil.RecordBookBuilder; public class ModelManagerTest { @@ -97,11 +102,14 @@ public void getFilteredRecipeList_modifyList_throwsUnsupportedOperationException public void equals() { RecipeBook recipeBook = new RecipeBookBuilder().withRecipe(CAESAR_SALAD).withRecipe(GRILLED_SANDWICH).build(); RecipeBook differentRecipeBook = new RecipeBook(); + CookedRecordBook recordBook = new RecordBookBuilder().withRecord(BOILED_CHICKEN) + .withRecord(CHOCOLATE_CAKE).build(); + CookedRecordBook differentRecordBook = new CookedRecordBook(); UserPrefs userPrefs = new UserPrefs(); // same values -> returns true - modelManager = new ModelManager(recipeBook, userPrefs); - ModelManager modelManagerCopy = new ModelManager(recipeBook, userPrefs); + modelManager = new ModelManager(recipeBook, userPrefs, recordBook); + ModelManager modelManagerCopy = new ModelManager(recipeBook, userPrefs, recordBook); assertTrue(modelManager.equals(modelManagerCopy)); // same object -> returns true @@ -114,12 +122,12 @@ public void equals() { assertFalse(modelManager.equals(5)); // different recipeBook -> returns false - assertFalse(modelManager.equals(new ModelManager(differentRecipeBook, userPrefs))); + assertFalse(modelManager.equals(new ModelManager(differentRecipeBook, userPrefs, differentRecordBook))); // different filteredList -> returns false String[] keywords = CAESAR_SALAD.getName().fullName.split("\\s+"); modelManager.updateFilteredRecipeList(new NameContainsKeywordsPredicate(Arrays.asList(keywords))); - assertFalse(modelManager.equals(new ModelManager(recipeBook, userPrefs))); + assertFalse(modelManager.equals(new ModelManager(recipeBook, userPrefs, recordBook))); // resets modelManager to initial state for upcoming tests modelManager.updateFilteredRecipeList(PREDICATE_SHOW_ALL_RECIPES); @@ -127,6 +135,6 @@ public void equals() { // different userPrefs -> returns false UserPrefs differentUserPrefs = new UserPrefs(); differentUserPrefs.setRecipeBookFilePath(Paths.get("differentFilePath")); - assertFalse(modelManager.equals(new ModelManager(recipeBook, differentUserPrefs))); + assertFalse(modelManager.equals(new ModelManager(recipeBook, differentUserPrefs, recordBook))); } } diff --git a/src/test/java/seedu/recipe/storage/StorageManagerTest.java b/src/test/java/seedu/recipe/storage/StorageManagerTest.java index b17073c974c..ea587a67bf7 100644 --- a/src/test/java/seedu/recipe/storage/StorageManagerTest.java +++ b/src/test/java/seedu/recipe/storage/StorageManagerTest.java @@ -26,7 +26,8 @@ public class StorageManagerTest { public void setUp() { JsonRecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(getTempFilePath("ab")); JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(getTempFilePath("prefs")); - storageManager = new StorageManager(recipeBookStorage, userPrefsStorage); + JsonCookedRecordBookStorage recordBookStorage = new JsonCookedRecordBookStorage(getTempFilePath("rb")); + storageManager = new StorageManager(recipeBookStorage, recordBookStorage, userPrefsStorage); } private Path getTempFilePath(String fileName) { diff --git a/src/test/java/seedu/recipe/testutil/RecordBookBuilder.java b/src/test/java/seedu/recipe/testutil/RecordBookBuilder.java new file mode 100644 index 00000000000..f748555337f --- /dev/null +++ b/src/test/java/seedu/recipe/testutil/RecordBookBuilder.java @@ -0,0 +1,35 @@ +package seedu.recipe.testutil; + +import seedu.recipe.model.cooked.CookedRecordBook; +import seedu.recipe.model.cooked.Record; + +/** + * A utility class to help with building RecordBook objects. + * Example usage:
+ * {@code RecordBook ab = new RecordBookBuilder().withRecord("John", "Doe").build();} + */ +public class RecordBookBuilder { + + private CookedRecordBook cookedRecordBook; + + public RecordBookBuilder() { + cookedRecordBook = new CookedRecordBook(); + } + + public RecordBookBuilder(CookedRecordBook cookedRecordBook) { + this.cookedRecordBook = cookedRecordBook; + } + + /** + * Adds a new {@code Record} to the {@code RecordBook} that we are building. + * @return recordbookbuilder object. + */ + public RecordBookBuilder withRecord(Record record) { + cookedRecordBook.addRecord(record); + return this; + } + + public CookedRecordBook build() { + return cookedRecordBook; + } +} diff --git a/src/test/java/seedu/recipe/testutil/RecordBuilder.java b/src/test/java/seedu/recipe/testutil/RecordBuilder.java new file mode 100644 index 00000000000..8f5665967f3 --- /dev/null +++ b/src/test/java/seedu/recipe/testutil/RecordBuilder.java @@ -0,0 +1,40 @@ +package seedu.recipe.testutil; + +import seedu.recipe.model.cooked.Record; +import seedu.recipe.model.recipe.Name; + +/** + * A utility class to help with building Record objects. + */ +public class RecordBuilder { + + public static final String DEFAULT_NAME = "Egg Tomato Stir Fry"; + + private Name name; + + public RecordBuilder() { + name = new Name(DEFAULT_NAME); + } + + /** + * Initializes the RecordBuilder with the data of {@code recordToCopy}. + */ + public RecordBuilder(Record recordToCopy) { + name = recordToCopy.getName(); + } + + /** + * Sets the {@code Name} of the {@code Record} that we are building. + */ + public RecordBuilder withName(String name) { + this.name = new Name(name); + return this; + } + + + + public Record build() { + return new Record(name); + } + +} diff --git a/src/test/java/seedu/recipe/testutil/TypicalRecords.java b/src/test/java/seedu/recipe/testutil/TypicalRecords.java new file mode 100644 index 00000000000..43ba7312390 --- /dev/null +++ b/src/test/java/seedu/recipe/testutil/TypicalRecords.java @@ -0,0 +1,54 @@ +package seedu.recipe.testutil; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import seedu.recipe.model.cooked.CookedRecordBook; +import seedu.recipe.model.cooked.Record; + +/** + * A utility class containing a list of {@code Record} objects to be used in tests. + */ +public class TypicalRecords { + + public static final Record CAESAR_SALAD = new RecordBuilder().withName("Caesar Salad").build(); + + public static final Record GRILLED_SANDWICH = new RecordBuilder().withName("Grilled Sandwich").build(); + + public static final Record BOILED_CHICKEN = new RecordBuilder().withName("Boiled Chicken").build(); + + public static final Record CHOCOLATE_CAKE = new RecordBuilder().withName("Chocolate Cake").build(); + + public static final Record OMELET = new RecordBuilder().withName("Omelet").build(); + + public static final Record STEAMED_EGG = new RecordBuilder().withName("Steamed Egg").build(); + + public static final Record TUNA_BREAD = new RecordBuilder().withName("Tuna Bread").build(); + + // Manually added + public static final Record FISH_TACO = new RecordBuilder().withName("Fish Taco").build(); + + public static final Record VEGETARIAN_PIZZA = new RecordBuilder().withName("Vegetarian Pizza").build(); + + + public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER + + private TypicalRecords() {} // prevents instantiation + + /** + * Returns an {@code RecordBook} with all the typical Records. + */ + public static CookedRecordBook getTypicalRecordBook() { + CookedRecordBook ab = new CookedRecordBook(); + for (Record Record : getTypicalRecords()) { + ab.addRecord(Record); + } + return ab; + } + + public static List getTypicalRecords() { + return new ArrayList<>(Arrays.asList(CAESAR_SALAD, GRILLED_SANDWICH, BOILED_CHICKEN, CHOCOLATE_CAKE, + OMELET, STEAMED_EGG, TUNA_BREAD)); + } +} \ No newline at end of file From 5c147d6434408b6c2c05255e409e68018d21c7c5 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 19:34:41 +0800 Subject: [PATCH 09/15] passed all checks --- .../java/seedu/recipe/logic/commands/DeleteCommandTest.java | 1 - src/test/java/seedu/recipe/model/ModelManagerTest.java | 3 +-- src/test/java/seedu/recipe/testutil/TypicalRecords.java | 6 +++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java index 1ed0c75eddd..5ec5f112d41 100644 --- a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java @@ -16,7 +16,6 @@ import seedu.recipe.commons.core.index.Index; import seedu.recipe.model.Model; import seedu.recipe.model.ModelManager; -import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.UserPrefs; import seedu.recipe.model.recipe.Recipe; diff --git a/src/test/java/seedu/recipe/model/ModelManagerTest.java b/src/test/java/seedu/recipe/model/ModelManagerTest.java index 1b1ed6b747a..fe36d6cf274 100644 --- a/src/test/java/seedu/recipe/model/ModelManagerTest.java +++ b/src/test/java/seedu/recipe/model/ModelManagerTest.java @@ -7,9 +7,8 @@ import static seedu.recipe.testutil.Assert.assertThrows; import static seedu.recipe.testutil.TypicalRecipes.CAESAR_SALAD; import static seedu.recipe.testutil.TypicalRecipes.GRILLED_SANDWICH; -import static seedu.recipe.testutil.TypicalRecords.CHOCOLATE_CAKE; import static seedu.recipe.testutil.TypicalRecords.BOILED_CHICKEN; - +import static seedu.recipe.testutil.TypicalRecords.CHOCOLATE_CAKE; import java.nio.file.Path; import java.nio.file.Paths; diff --git a/src/test/java/seedu/recipe/testutil/TypicalRecords.java b/src/test/java/seedu/recipe/testutil/TypicalRecords.java index 43ba7312390..04859df00b2 100644 --- a/src/test/java/seedu/recipe/testutil/TypicalRecords.java +++ b/src/test/java/seedu/recipe/testutil/TypicalRecords.java @@ -41,8 +41,8 @@ private TypicalRecords() {} // prevents instantiation */ public static CookedRecordBook getTypicalRecordBook() { CookedRecordBook ab = new CookedRecordBook(); - for (Record Record : getTypicalRecords()) { - ab.addRecord(Record); + for (Record record : getTypicalRecords()) { + ab.addRecord(record); } return ab; } @@ -51,4 +51,4 @@ public static List getTypicalRecords() { return new ArrayList<>(Arrays.asList(CAESAR_SALAD, GRILLED_SANDWICH, BOILED_CHICKEN, CHOCOLATE_CAKE, OMELET, STEAMED_EGG, TUNA_BREAD)); } -} \ No newline at end of file +} From 46e4d8c676753f0901b604d3bdd6b80eef23386e Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Tue, 31 Mar 2020 20:57:49 +0800 Subject: [PATCH 10/15] fixed merge conflicts in commands --- .../commands/AddCommandIntegrationTest.java | 14 ++++------- .../recipe/logic/commands/AddCommandTest.java | 21 +++++++++-------- .../logic/commands/DeleteCommandTest.java | 23 ++++++------------- .../logic/commands/EditCommandTest.java | 5 ---- .../seedu/recipe/model/ModelManagerTest.java | 3 --- 5 files changed, 22 insertions(+), 44 deletions(-) diff --git a/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java b/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java index 9e431dba25f..491ddc4214c 100644 --- a/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java +++ b/src/test/java/seedu/recipe/logic/commands/AddCommandIntegrationTest.java @@ -24,23 +24,17 @@ public class AddCommandIntegrationTest { @BeforeEach public void setUp() { -<<<<<<< HEAD - model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); -======= - model = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook(), new PlannedBook()); } @Test public void execute_newRecipe_success() { Recipe validRecipe = new RecipeBuilder().build(); -<<<<<<< HEAD - Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); + Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), + model.getRecordBook(), new PlannedBook()); // System.out.println(validRecipe); // todo remove later -======= - Model expectedModel = new ModelManager(model.getRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + expectedModel.addRecipe(validRecipe); assertCommandSuccess(new AddCommand(validRecipe), model, diff --git a/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java b/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java index b57a66716ce..d13ae141adb 100644 --- a/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java @@ -214,25 +214,21 @@ public void removeAllPlannedMappingForRecipe(Recipe recipe) { } @Override -<<<<<<< HEAD public void addRecord(Record record) { -======= - public void setPlannedRecipe(Recipe target, Recipe editedRecipe) { ->>>>>>> upstream/master throw new AssertionError("This method should not be called."); } @Override -<<<<<<< HEAD public ObservableList getFilteredRecordList() { -======= + throw new AssertionError("This method should not be called."); + } + + @Override public ObservableList getFilteredPlannedList() { ->>>>>>> upstream/master throw new AssertionError("This method should not be called."); } @Override -<<<<<<< HEAD public ReadOnlyCookedRecordBook getRecordBook() { throw new AssertionError("This method should not be called."); } @@ -241,12 +237,17 @@ public ReadOnlyCookedRecordBook getRecordBook() { public boolean hasRecord(Record record) { throw new AssertionError("This method should not be called."); } -======= + + @Override public void updateFilteredPlannedList(Predicate predicate) { throw new AssertionError("This method should not be called."); } ->>>>>>> upstream/master + @Override + public void setPlannedRecipe(Recipe target, Recipe editedRecipe) { + throw new AssertionError("This method should not be called."); + } + } /** diff --git a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java index e2af867e37d..82a99b57e2c 100644 --- a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java @@ -26,12 +26,7 @@ */ public class DeleteCommandTest { -<<<<<<< HEAD - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); - -======= - private Model model = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook(), new PlannedBook()); @Test public void execute_validIndexUnfilteredList_success() { @@ -41,11 +36,9 @@ public void execute_validIndexUnfilteredList_success() { String expectedMessageTemplate = "Deleted %1$s from recipe book!"; String expectedMessage = String.format(expectedMessageTemplate, recipeToDelete.getName().toString()); -<<<<<<< HEAD - ModelManager expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); -======= - ModelManager expectedModel = new ModelManager(model.getRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + ModelManager expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), + model.getRecordBook(), new PlannedBook()); + expectedModel.deleteRecipe(recipeToDelete); assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); @@ -69,11 +62,9 @@ public void execute_validIndexFilteredList_success() { String expectedMessageTemplate = "Deleted %1$s from recipe book!"; String expectedMessage = String.format(expectedMessageTemplate, recipeToDelete.getName().toString()); -<<<<<<< HEAD - Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); -======= - Model expectedModel = new ModelManager(model.getRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), + model.getRecordBook(), new PlannedBook()); + expectedModel.deleteRecipe(recipeToDelete); showNoRecipe(expectedModel); diff --git a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java index 1f57773fa18..38a87986cc9 100644 --- a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java @@ -2,7 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; - import static seedu.recipe.logic.commands.CommandTestUtil.DESC_FISH; import static seedu.recipe.logic.commands.CommandTestUtil.DESC_TURKEY_SANDWICH; import static seedu.recipe.logic.commands.CommandTestUtil.VALID_GOAL_PROTEIN; @@ -11,7 +10,6 @@ import static seedu.recipe.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.recipe.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.recipe.logic.commands.CommandTestUtil.showRecipeAtIndex; - import static seedu.recipe.testutil.TypicalIndexes.INDEX_FIRST_RECIPE; import static seedu.recipe.testutil.TypicalIndexes.INDEX_SECOND_RECIPE; import static seedu.recipe.testutil.TypicalRecipes.getTypicalRecipeBook; @@ -26,11 +24,8 @@ import seedu.recipe.model.ModelManager; import seedu.recipe.model.RecipeBook; import seedu.recipe.model.UserPrefs; -<<<<<<< HEAD import seedu.recipe.model.cooked.CookedRecordBook; -======= import seedu.recipe.model.plan.PlannedBook; ->>>>>>> upstream/master import seedu.recipe.model.recipe.Recipe; import seedu.recipe.testutil.EditRecipeDescriptorBuilder; import seedu.recipe.testutil.RecipeBuilder; diff --git a/src/test/java/seedu/recipe/model/ModelManagerTest.java b/src/test/java/seedu/recipe/model/ModelManagerTest.java index 2237ddb7bb5..3dd7871aa28 100644 --- a/src/test/java/seedu/recipe/model/ModelManagerTest.java +++ b/src/test/java/seedu/recipe/model/ModelManagerTest.java @@ -17,11 +17,8 @@ import org.junit.jupiter.api.Test; import seedu.recipe.commons.core.GuiSettings; -<<<<<<< HEAD import seedu.recipe.model.cooked.CookedRecordBook; -======= import seedu.recipe.model.plan.PlannedBook; ->>>>>>> upstream/master import seedu.recipe.model.recipe.NameContainsKeywordsPredicate; import seedu.recipe.testutil.RecipeBookBuilder; import seedu.recipe.testutil.RecordBookBuilder; From f07326101aded7f3744e426aba280176c4a84004 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Wed, 1 Apr 2020 00:30:03 +0800 Subject: [PATCH 11/15] fixed all merge conflicts --- src/main/java/seedu/recipe/MainApp.java | 4 +- .../recipe/logic/commands/AddCommandTest.java | 6 --- .../logic/commands/ClearCommandTest.java | 12 +++--- .../logic/commands/EditCommandTest.java | 37 ++++--------------- .../logic/commands/FindCommandTest.java | 11 ++---- .../logic/commands/ListCommandTest.java | 12 +++--- .../recipe/storage/StorageManagerTest.java | 7 +--- 7 files changed, 25 insertions(+), 64 deletions(-) diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index 5d533b596c2..164b8fefd4f 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -68,7 +68,7 @@ public void init() throws Exception { CookedRecordBookStorage cookedRecordBookStorage = new JsonCookedRecordBookStorage( userPrefs.getCookedRecordFilePath()); PlannedBookStorage plannedBookStorage = new JsonPlannedBookStorage(userPrefs.getPlannedBookFilePath()); - storage = new StorageManager(recipeBookStorage, cookedRecordBookStorage, plannedBookStorage,userPrefsStorage); + storage = new StorageManager(recipeBookStorage, cookedRecordBookStorage, plannedBookStorage, userPrefsStorage); initLogging(config); @@ -123,7 +123,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { initialRecords = new CookedRecordBook(); } - try{ + try { plannedBookOptional = storage.readPlannedBook(); if (!plannedBookOptional.isPresent()) { logger.info("Data file for planned recipes not found. Will be starting with a blank PlannedBook"); diff --git a/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java b/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java index d13ae141adb..2acd2b9848d 100644 --- a/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/AddCommandTest.java @@ -14,22 +14,16 @@ import org.junit.jupiter.api.Test; import javafx.collections.ObservableList; - import seedu.recipe.commons.core.GuiSettings; - import seedu.recipe.logic.commands.exceptions.CommandException; import seedu.recipe.model.Model; import seedu.recipe.model.ReadOnlyCookedRecordBook; import seedu.recipe.model.ReadOnlyRecipeBook; import seedu.recipe.model.ReadOnlyUserPrefs; import seedu.recipe.model.RecipeBook; -<<<<<<< HEAD import seedu.recipe.model.cooked.Record; -import seedu.recipe.model.plan.Date; -======= import seedu.recipe.model.plan.PlannedRecipe; import seedu.recipe.model.plan.ReadOnlyPlannedBook; ->>>>>>> upstream/master import seedu.recipe.model.recipe.Recipe; import seedu.recipe.testutil.RecipeBuilder; diff --git a/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java b/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java index 2eeac06f249..286a24fa067 100644 --- a/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/ClearCommandTest.java @@ -24,13 +24,11 @@ public void execute_emptyRecipeBook_success() { @Test public void execute_nonEmptyRecipeBook_success() { -<<<<<<< HEAD - Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); - Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); -======= - Model model = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); - Model expectedModel = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), + getTypicalRecordBook(), new PlannedBook()); + Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), + getTypicalRecordBook(), new PlannedBook()); + expectedModel.setRecipeBook(new RecipeBook()); assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); diff --git a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java index 38a87986cc9..936c1d545de 100644 --- a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java @@ -35,11 +35,7 @@ */ public class EditCommandTest { -<<<<<<< HEAD - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); -======= - private Model model = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook(), new PlannedBook()); // todo: bug: test might fail sometimes if recipe at TypicalRecipes index 0 has ingredients @Test @@ -50,13 +46,9 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); -<<<<<<< HEAD Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), - new CookedRecordBook(model.getRecordBook())); -======= - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new PlannedBook(), - new UserPrefs()); ->>>>>>> upstream/master + new CookedRecordBook(model.getRecordBook()), new PlannedBook()); + expectedModel.setRecipe(model.getFilteredRecipeList().get(0), editedRecipe); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -77,13 +69,9 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); -<<<<<<< HEAD Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), - new CookedRecordBook(model.getRecordBook())); -======= - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new PlannedBook(), - new UserPrefs()); ->>>>>>> upstream/master + new CookedRecordBook(model.getRecordBook()), new PlannedBook()); + expectedModel.setRecipe(lastRecipe, editedRecipe); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -96,13 +84,8 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); -<<<<<<< HEAD Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), - new CookedRecordBook(model.getRecordBook())); -======= - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new PlannedBook(), - new UserPrefs()); ->>>>>>> upstream/master + new CookedRecordBook(model.getRecordBook()), new PlannedBook()); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); } @@ -118,13 +101,9 @@ public void execute_filteredList_success() { String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_RECIPE_SUCCESS, editedRecipe); -<<<<<<< HEAD Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new UserPrefs(), - new CookedRecordBook(model.getRecordBook())); -======= - Model expectedModel = new ModelManager(new RecipeBook(model.getRecipeBook()), new PlannedBook(), - new UserPrefs()); ->>>>>>> upstream/master + new CookedRecordBook(model.getRecordBook()), new PlannedBook()); + expectedModel.setRecipe(model.getFilteredRecipeList().get(0), editedRecipe); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java b/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java index ae3bb67190d..cf4e90b6b38 100644 --- a/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/FindCommandTest.java @@ -23,13 +23,10 @@ * Contains integration tests (interaction with the Model) for {@code FindCommand}. */ public class FindCommandTest { -<<<<<<< HEAD - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); - private Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); -======= - private Model model = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); - private Model expectedModel = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), + getTypicalRecordBook(), new PlannedBook()); + private Model expectedModel = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), + getTypicalRecordBook(), new PlannedBook()); @Test public void equals() { diff --git a/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java b/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java index cc700fd0213..805e1389ba0 100644 --- a/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/ListCommandTest.java @@ -24,13 +24,11 @@ public class ListCommandTest { @BeforeEach public void setUp() { -<<<<<<< HEAD - model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook()); - expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook()); -======= - model = new ModelManager(getTypicalRecipeBook(), new PlannedBook(), new UserPrefs()); - expectedModel = new ModelManager(model.getRecipeBook(), new PlannedBook(), new UserPrefs()); ->>>>>>> upstream/master + + model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook(), new PlannedBook()); + expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), + model.getRecordBook(), new PlannedBook()); + } @Test diff --git a/src/test/java/seedu/recipe/storage/StorageManagerTest.java b/src/test/java/seedu/recipe/storage/StorageManagerTest.java index 99ea4679284..64d301a037c 100644 --- a/src/test/java/seedu/recipe/storage/StorageManagerTest.java +++ b/src/test/java/seedu/recipe/storage/StorageManagerTest.java @@ -27,15 +27,10 @@ public class StorageManagerTest { public void setUp() { JsonRecipeBookStorage recipeBookStorage = new JsonRecipeBookStorage(getTempFilePath("ab")); JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(getTempFilePath("prefs")); -<<<<<<< HEAD JsonCookedRecordBookStorage recordBookStorage = new JsonCookedRecordBookStorage(getTempFilePath("rb")); - storageManager = new StorageManager(recipeBookStorage, recordBookStorage, userPrefsStorage); -======= JsonPlannedBookStorage plannedBookStorage = new JsonPlannedBookStorage(getTempFilePath("pb")); - - storageManager = new StorageManager(recipeBookStorage, plannedBookStorage, userPrefsStorage); ->>>>>>> upstream/master + storageManager = new StorageManager(recipeBookStorage, recordBookStorage, plannedBookStorage, userPrefsStorage); } private Path getTempFilePath(String fileName) { From 7da4e25a71ad6b90772f2cbfcb6efd19b7bfee14 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Wed, 1 Apr 2020 00:32:57 +0800 Subject: [PATCH 12/15] passed all checks --- src/test/java/seedu/recipe/logic/LogicManagerTest.java | 6 ++++-- .../java/seedu/recipe/logic/commands/DeleteCommandTest.java | 3 ++- .../java/seedu/recipe/logic/commands/EditCommandTest.java | 3 ++- src/test/java/seedu/recipe/model/ModelManagerTest.java | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/test/java/seedu/recipe/logic/LogicManagerTest.java b/src/test/java/seedu/recipe/logic/LogicManagerTest.java index 8114b63d126..65a357953ae 100644 --- a/src/test/java/seedu/recipe/logic/LogicManagerTest.java +++ b/src/test/java/seedu/recipe/logic/LogicManagerTest.java @@ -57,7 +57,8 @@ public void setUp() { JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("userPrefs.json")); JsonCookedRecordBookStorage recordBookStorage = new JsonCookedRecordBookStorage(temporaryFolder.resolve("cookedRecordBook.json")); - StorageManager storage = new StorageManager(recipeBookStorage, recordBookStorage, plannedBookStorage, userPrefsStorage); + StorageManager storage = new StorageManager(recipeBookStorage, recordBookStorage, + plannedBookStorage, userPrefsStorage); logic = new LogicManager(model, storage); } @@ -150,7 +151,8 @@ private void assertCommandException(String inputCommand, String expectedMessage) private void assertCommandFailure(String inputCommand, Class expectedException, String expectedMessage) { - Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), model.getRecordBook(), new PlannedBook()); + Model expectedModel = new ModelManager(model.getRecipeBook(), new UserPrefs(), + model.getRecordBook(), new PlannedBook()); assertCommandFailure(inputCommand, expectedException, expectedMessage, expectedModel); } diff --git a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java index 82a99b57e2c..8711007f8b1 100644 --- a/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/DeleteCommandTest.java @@ -26,7 +26,8 @@ */ public class DeleteCommandTest { - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook(), new PlannedBook()); + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), + getTypicalRecordBook(), new PlannedBook()); @Test public void execute_validIndexUnfilteredList_success() { diff --git a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java index 936c1d545de..15d05ad5795 100644 --- a/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/recipe/logic/commands/EditCommandTest.java @@ -35,7 +35,8 @@ */ public class EditCommandTest { - private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), getTypicalRecordBook(), new PlannedBook()); + private Model model = new ModelManager(getTypicalRecipeBook(), new UserPrefs(), + getTypicalRecordBook(), new PlannedBook()); // todo: bug: test might fail sometimes if recipe at TypicalRecipes index 0 has ingredients @Test diff --git a/src/test/java/seedu/recipe/model/ModelManagerTest.java b/src/test/java/seedu/recipe/model/ModelManagerTest.java index 3dd7871aa28..2ee0c24a0c0 100644 --- a/src/test/java/seedu/recipe/model/ModelManagerTest.java +++ b/src/test/java/seedu/recipe/model/ModelManagerTest.java @@ -125,7 +125,8 @@ public void equals() { // different recipeBook -> returns false - assertFalse(modelManager.equals(new ModelManager(differentRecipeBook, userPrefs, differentRecordBook, plannedBook))); + assertFalse(modelManager.equals(new ModelManager(differentRecipeBook, userPrefs, + differentRecordBook, plannedBook))); // different filteredList -> returns false String[] keywords = CAESAR_SALAD.getName().fullName.split("\\s+"); From 6f6c1e697c9f414f258ded9a464e91b9aa97a34f Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Wed, 1 Apr 2020 00:35:30 +0800 Subject: [PATCH 13/15] fixed EOF error --- data/addressbook.json | 2 +- data/cookedRecords.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/addressbook.json b/data/addressbook.json index f29fa553435..59edb19ebf4 100644 --- a/data/addressbook.json +++ b/data/addressbook.json @@ -154,4 +154,4 @@ "steps" : [ "Boil chicken", "While chicken is cooking, add sesame oil and crushed ginger into rice and cook it", "When chicken is done, dip it into iced water", "Serve while rice is hot" ], "goals" : [ "Bulk like the Hulk" ] } ] -} \ No newline at end of file +} diff --git a/data/cookedRecords.json b/data/cookedRecords.json index 9f72c66ac74..0b423595f94 100644 --- a/data/cookedRecords.json +++ b/data/cookedRecords.json @@ -24,4 +24,4 @@ }, { "name" : "Asian BBQ Chicken" } ] -} \ No newline at end of file +} From c32ea070ba957507928d95508316737c5737fb28 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Wed, 1 Apr 2020 01:08:47 +0800 Subject: [PATCH 14/15] camelcase string --- src/main/java/seedu/recipe/MainApp.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/recipe/MainApp.java b/src/main/java/seedu/recipe/MainApp.java index 164b8fefd4f..d21ccadffe8 100644 --- a/src/main/java/seedu/recipe/MainApp.java +++ b/src/main/java/seedu/recipe/MainApp.java @@ -116,10 +116,10 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { initialRecords = recordBookOptional.orElseGet(SampleDataUtil::getSampleRecordBook); } catch (DataConversionException e) { - logger.warning("Data file not in the correct format. Will be starting with an empty recordbook"); + logger.warning("Data file not in the correct format. Will be starting with an empty Recordbook"); initialRecords = new CookedRecordBook(); } catch (IOException e) { - logger.warning("Problem while reading from the file. Will be starting with an empty recordbook"); + logger.warning("Problem while reading from the file. Will be starting with an empty Recordbook"); initialRecords = new CookedRecordBook(); } From e4755502a9fde9e806366a8ff92570a829dc3a84 Mon Sep 17 00:00:00 2001 From: tharshita <> Date: Wed, 1 Apr 2020 02:31:42 +0800 Subject: [PATCH 15/15] modified plannedDate to Date class --- .../recipe/logic/commands/PlanCommand.java | 6 ++-- .../seedu/recipe/logic/parser/ParserUtil.java | 13 ++++---- .../logic/parser/PlanCommandParser.java | 4 +-- .../logic/parser/ViewCommandParser.java | 4 +-- .../{plan/PlannedDate.java => Date.java} | 32 +++++++++---------- .../recipe/model/plan/PlannedRecipe.java | 9 +++--- ...PlannedRecipeWithinDateRangePredicate.java | 10 +++--- .../storage/plan/JsonAdaptedPlannedDate.java | 20 ++++++------ .../plan/JsonAdaptedPlannedRecipe.java | 4 +-- .../seedu/recipe/ui/PlanningListCard.java | 4 +-- 10 files changed, 54 insertions(+), 52 deletions(-) rename src/main/java/seedu/recipe/model/{plan/PlannedDate.java => Date.java} (73%) diff --git a/src/main/java/seedu/recipe/logic/commands/PlanCommand.java b/src/main/java/seedu/recipe/logic/commands/PlanCommand.java index aa77a35996b..0d09f263272 100644 --- a/src/main/java/seedu/recipe/logic/commands/PlanCommand.java +++ b/src/main/java/seedu/recipe/logic/commands/PlanCommand.java @@ -9,8 +9,8 @@ import seedu.recipe.commons.core.Messages; import seedu.recipe.commons.core.index.Index; import seedu.recipe.logic.commands.exceptions.CommandException; +import seedu.recipe.model.Date; import seedu.recipe.model.Model; -import seedu.recipe.model.plan.PlannedDate; import seedu.recipe.model.plan.PlannedRecipe; import seedu.recipe.model.recipe.Recipe; @@ -33,12 +33,12 @@ public class PlanCommand extends Command { public static final String MESSAGE_SUCCESS = "Recipe planned: %1$s, %2$s"; private final Index index; - private final PlannedDate atDate; + private final Date atDate; /** * Creates an PlanCommand to set the specified {@code Recipe} on a certain date */ - public PlanCommand(Index index, PlannedDate date) { + public PlanCommand(Index index, Date date) { requireNonNull(index); requireNonNull(date); this.index = index; diff --git a/src/main/java/seedu/recipe/logic/parser/ParserUtil.java b/src/main/java/seedu/recipe/logic/parser/ParserUtil.java index e62a72a29ae..e1d23f436e4 100644 --- a/src/main/java/seedu/recipe/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/recipe/logic/parser/ParserUtil.java @@ -14,12 +14,11 @@ import seedu.recipe.commons.core.index.Index; import seedu.recipe.commons.util.StringUtil; import seedu.recipe.logic.parser.exceptions.ParseException; +import seedu.recipe.model.Date; import seedu.recipe.model.goal.Goal; -import seedu.recipe.model.plan.PlannedDate; import seedu.recipe.model.recipe.Name; import seedu.recipe.model.recipe.Step; import seedu.recipe.model.recipe.Time; - import seedu.recipe.model.recipe.ingredient.Fruit; import seedu.recipe.model.recipe.ingredient.Grain; import seedu.recipe.model.recipe.ingredient.Ingredient; @@ -514,16 +513,16 @@ public static Set parseOthersNameOnly(Collection others) throws P } /** - * Parses {@code String date} into a {@code PlannedDate}. + * Parses {@code String date} into a {@code Date}. * * @throws ParseException if the given {@code date} is invalid. */ - public static PlannedDate parseDate(String date) throws ParseException { + public static Date parseDate(String date) throws ParseException { requireNonNull(date); String trimmedDate = date.trim(); - if (!PlannedDate.isValidDate(trimmedDate)) { - throw new ParseException(PlannedDate.MESSAGE_CONSTRAINTS); + if (!Date.isValidDate(trimmedDate)) { + throw new ParseException(Date.MESSAGE_CONSTRAINTS); } - return new PlannedDate(trimmedDate); + return new Date(trimmedDate); } } diff --git a/src/main/java/seedu/recipe/logic/parser/PlanCommandParser.java b/src/main/java/seedu/recipe/logic/parser/PlanCommandParser.java index 22fbad9e87c..baaba37f93c 100644 --- a/src/main/java/seedu/recipe/logic/parser/PlanCommandParser.java +++ b/src/main/java/seedu/recipe/logic/parser/PlanCommandParser.java @@ -8,7 +8,7 @@ import seedu.recipe.commons.core.index.Index; import seedu.recipe.logic.commands.PlanCommand; import seedu.recipe.logic.parser.exceptions.ParseException; -import seedu.recipe.model.plan.PlannedDate; +import seedu.recipe.model.Date; /** * Parses input arguments and creates a new PlanCommand object @@ -35,7 +35,7 @@ public PlanCommand parse(String args) throws ParseException { if (!arePrefixesPresent(argMultimap, PREFIX_DATE)) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, PlanCommand.MESSAGE_USAGE)); } - PlannedDate date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()); + Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()); return new PlanCommand(index, date); } diff --git a/src/main/java/seedu/recipe/logic/parser/ViewCommandParser.java b/src/main/java/seedu/recipe/logic/parser/ViewCommandParser.java index f249654f9ed..3511bc13a25 100644 --- a/src/main/java/seedu/recipe/logic/parser/ViewCommandParser.java +++ b/src/main/java/seedu/recipe/logic/parser/ViewCommandParser.java @@ -6,7 +6,7 @@ import seedu.recipe.logic.commands.ViewCommand; import seedu.recipe.logic.parser.exceptions.ParseException; -import seedu.recipe.model.plan.PlannedDate; +import seedu.recipe.model.Date; import seedu.recipe.model.plan.PlannedRecipeWithinDateRangePredicate; /** @@ -27,7 +27,7 @@ public ViewCommand parse(String args) throws ParseException { } PlannedRecipeWithinDateRangePredicate predicate = new PlannedRecipeWithinDateRangePredicate( - new PlannedDate(LocalDate.parse("2020-03-30")), new PlannedDate(LocalDate.parse("2020-04-06"))); + new Date(LocalDate.parse("2020-03-30")), new Date(LocalDate.parse("2020-04-06"))); // model.updateFilteredRecipeList(predicate); return new ViewCommand(predicate); } diff --git a/src/main/java/seedu/recipe/model/plan/PlannedDate.java b/src/main/java/seedu/recipe/model/Date.java similarity index 73% rename from src/main/java/seedu/recipe/model/plan/PlannedDate.java rename to src/main/java/seedu/recipe/model/Date.java index 9780049112c..77ab9e96afd 100644 --- a/src/main/java/seedu/recipe/model/plan/PlannedDate.java +++ b/src/main/java/seedu/recipe/model/Date.java @@ -1,4 +1,4 @@ -package seedu.recipe.model.plan; +package seedu.recipe.model; import static java.time.temporal.TemporalAdjusters.lastDayOfMonth; import static java.util.Objects.requireNonNull; @@ -9,14 +9,14 @@ import java.time.format.DateTimeParseException; /** - * Represents a date in the planned recipes book. + * Represents a date in the recipes book. * Guarantees: immutable; is valid as declared in {@link #isValidDate(String)} */ -public class PlannedDate implements Comparable { +public class Date implements Comparable { public static final String MESSAGE_CONSTRAINTS = - "PlannedDate should be written in the format YYYY-MM-DD"; + "Date should be written in the format YYYY-MM-DD"; public static final String VALIDATION_REGEX = "^[0-9-]+"; public static final DateTimeFormatter DAY_OF_WEEK = DateTimeFormatter.ofPattern("EEEE"); @@ -25,17 +25,17 @@ public class PlannedDate implements Comparable { private final LocalDate date; /** - * Constructs a {@code PlannedDate}. + * Constructs a {@code Date}. * * @param date A valid date. */ - public PlannedDate(String date) { + public Date(String date) { requireNonNull(date); checkArgument(isValidDate(date), MESSAGE_CONSTRAINTS); this.date = LocalDate.parse(date); } - public PlannedDate(LocalDate date) { + public Date(LocalDate date) { requireNonNull(date); this.date = date; } @@ -57,12 +57,12 @@ public static boolean isValidDate(String test) { } } - public PlannedDate onFirstDayOfMonth() { - return new PlannedDate(date.withDayOfMonth(1)); + public seedu.recipe.model.Date onFirstDayOfMonth() { + return new seedu.recipe.model.Date(date.withDayOfMonth(1)); } - public PlannedDate onLastDayOfMonth() { - return new PlannedDate(date.with(lastDayOfMonth())); + public seedu.recipe.model.Date onLastDayOfMonth() { + return new seedu.recipe.model.Date(date.with(lastDayOfMonth())); } public int getDateOfMonth() { @@ -73,7 +73,7 @@ public int getDateOfMonth() { * * Not inclusive! */ - public boolean isWithinRange(PlannedDate start, PlannedDate end) { + public boolean isWithinRange(seedu.recipe.model.Date start, seedu.recipe.model.Date end) { return date.isAfter(start.date) && date.isBefore(end.date); } @@ -82,7 +82,7 @@ public String toStringForJson() { } @Override - public int compareTo(PlannedDate other) { + public int compareTo(seedu.recipe.model.Date other) { LocalDate otherLocalDate = other.date; if (date.isBefore(otherLocalDate)) { return -1; @@ -101,8 +101,8 @@ public String toString() { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof PlannedDate // instanceof handles nulls - && date.equals(((PlannedDate) other).date)); // state check + || (other instanceof seedu.recipe.model.Date // instanceof handles nulls + && date.equals(((seedu.recipe.model.Date) other).date)); // state check } @Override @@ -110,5 +110,5 @@ public int hashCode() { return date.hashCode(); } - } + diff --git a/src/main/java/seedu/recipe/model/plan/PlannedRecipe.java b/src/main/java/seedu/recipe/model/plan/PlannedRecipe.java index dd3b83fe280..3915210cfb2 100644 --- a/src/main/java/seedu/recipe/model/plan/PlannedRecipe.java +++ b/src/main/java/seedu/recipe/model/plan/PlannedRecipe.java @@ -2,6 +2,7 @@ import java.util.Objects; +import seedu.recipe.model.Date; import seedu.recipe.model.recipe.Recipe; /** @@ -11,9 +12,9 @@ public class PlannedRecipe { private Recipe recipe; - private PlannedDate date; + private Date date; - public PlannedRecipe(Recipe recipe, PlannedDate date) { + public PlannedRecipe(Recipe recipe, Date date) { this.recipe = recipe; this.date = date; } @@ -26,14 +27,14 @@ public void setRecipe(Recipe recipe) { this.recipe = recipe; } - public PlannedDate getDate() { + public Date getDate() { return date; } /** * Checks whether the date of this planned recipe falls within the {@code start} date and the {@code end} date. */ - public boolean isWithinRange(PlannedDate start, PlannedDate end) { + public boolean isWithinRange(Date start, Date end) { return date.isWithinRange(start, end); } diff --git a/src/main/java/seedu/recipe/model/plan/PlannedRecipeWithinDateRangePredicate.java b/src/main/java/seedu/recipe/model/plan/PlannedRecipeWithinDateRangePredicate.java index 4fa9b81a952..bd3ea108862 100644 --- a/src/main/java/seedu/recipe/model/plan/PlannedRecipeWithinDateRangePredicate.java +++ b/src/main/java/seedu/recipe/model/plan/PlannedRecipeWithinDateRangePredicate.java @@ -2,15 +2,17 @@ import java.util.function.Predicate; +import seedu.recipe.model.Date; + /** - * Tests that a {@code PlannedRecipe}'s {@code PlannedDate} falls within the specified PlannedDate range. + * Tests that a {@code PlannedRecipe}'s {@code Date} falls within the specified Date range. */ public class PlannedRecipeWithinDateRangePredicate implements Predicate { - private PlannedDate start; - private PlannedDate end; + private Date start; + private Date end; - public PlannedRecipeWithinDateRangePredicate(PlannedDate start, PlannedDate end) { + public PlannedRecipeWithinDateRangePredicate(Date start, Date end) { this.start = start; this.end = end; } diff --git a/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedDate.java b/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedDate.java index 135a25140db..34827a00829 100644 --- a/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedDate.java +++ b/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedDate.java @@ -4,10 +4,10 @@ import com.fasterxml.jackson.annotation.JsonValue; import seedu.recipe.commons.exceptions.IllegalValueException; -import seedu.recipe.model.plan.PlannedDate; +import seedu.recipe.model.Date; /** - * Jackson-friendly version of {@link PlannedDate}. + * Jackson-friendly version of {@link Date}. */ public class JsonAdaptedPlannedDate { @@ -24,7 +24,7 @@ public JsonAdaptedPlannedDate(String plannedDate) { /** * Converts a given {@code plannedDate} into this class for Jackson use. */ - public JsonAdaptedPlannedDate(PlannedDate plannedDate) { + public JsonAdaptedPlannedDate(Date plannedDate) { date = plannedDate.toStringForJson(); } @@ -34,15 +34,15 @@ public String getDate() { } /** - * Converts this Jackson-friendly adapted plannedDate object into the model's {@code PlannedDate} object. - * @return PlannedDate object that the adapted plannedDate was converted into. - * @throws IllegalValueException if there were any data constraints violated in the adapted PlannedDate. + * Converts this Jackson-friendly adapted plannedDate object into the model's {@code Date} object. + * @return Date object that the adapted plannedDate was converted into. + * @throws IllegalValueException if there were any data constraints violated in the adapted Date. */ - public PlannedDate toModelType() throws IllegalValueException { - if (!PlannedDate.isValidDate(date)) { - throw new IllegalValueException(PlannedDate.MESSAGE_CONSTRAINTS); + public Date toModelType() throws IllegalValueException { + if (!Date.isValidDate(date)) { + throw new IllegalValueException(Date.MESSAGE_CONSTRAINTS); } - return new PlannedDate(date); + return new Date(date); } } diff --git a/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedRecipe.java b/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedRecipe.java index a03d338416d..0f329cc6d83 100644 --- a/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedRecipe.java +++ b/src/main/java/seedu/recipe/storage/plan/JsonAdaptedPlannedRecipe.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.recipe.commons.exceptions.IllegalValueException; -import seedu.recipe.model.plan.PlannedDate; +import seedu.recipe.model.Date; import seedu.recipe.model.plan.PlannedRecipe; import seedu.recipe.model.recipe.Recipe; import seedu.recipe.storage.JsonAdaptedRecipe; @@ -43,7 +43,7 @@ public JsonAdaptedPlannedRecipe(PlannedRecipe plannedRecipe) { */ public PlannedRecipe toModelType() throws IllegalValueException { Recipe modelRecipe = recipe.toModelType(); - PlannedDate modelPlannedDate = date.toModelType(); + Date modelPlannedDate = date.toModelType(); return new PlannedRecipe(modelRecipe, modelPlannedDate); } diff --git a/src/main/java/seedu/recipe/ui/PlanningListCard.java b/src/main/java/seedu/recipe/ui/PlanningListCard.java index dba1d60d3c4..a4b578576ad 100644 --- a/src/main/java/seedu/recipe/ui/PlanningListCard.java +++ b/src/main/java/seedu/recipe/ui/PlanningListCard.java @@ -16,7 +16,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; -import seedu.recipe.model.plan.PlannedDate; +import seedu.recipe.model.Date; import seedu.recipe.model.plan.PlannedRecipe; import seedu.recipe.model.recipe.Recipe; @@ -36,7 +36,7 @@ public class PlanningListCard extends UiPart { */ public final PlannedRecipe plannedRecipeObject; - public final PlannedDate plannedDate; + public final Date plannedDate; public final Recipe recipe; private final String styleIngredientsAndSteps = "-fx-font-size: 11pt;\n" + "-fx-font-family: \"Segoe UI\";\n"