Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1819S1#65 from dioptrique/AddCommand
Browse files Browse the repository at this point in the history
Add command, Date and UUID
  • Loading branch information
dioptrique authored Oct 23, 2018
2 parents a65df9e + 8dfaeae commit 75f298f
Show file tree
Hide file tree
Showing 98 changed files with 1,259 additions and 842 deletions.
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private Model initModelManager(Storage storage, UserPrefs userPrefs) {
}
initialData = wishBookOptional.orElseGet(SampleDataUtil::getSampleWishBook);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty WishBook");
logger.warning("Data file not in the correct FORMAT. Will be starting with an empty WishBook");
initialData = new WishBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty WishBook");
Expand All @@ -124,7 +124,7 @@ private WishTransaction initWishTransaction(Storage storage, UserPrefs userPrefs
}
initialData = wishTransactionOptional.orElseGet(SampleDataUtil::getSampleWishTransaction);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty WishBook");
logger.warning("Data file not in the correct FORMAT. Will be starting with an empty WishBook");
initialData = new WishTransaction();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty WishBook");
Expand Down Expand Up @@ -160,7 +160,7 @@ protected Config initConfig(Path configFilePath) {
Optional<Config> configOptional = ConfigUtil.readConfig(configFilePathUsed);
initializedConfig = configOptional.orElse(new Config());
} catch (DataConversionException e) {
logger.warning("Config file at " + configFilePathUsed + " is not in the correct format. "
logger.warning("Config file at " + configFilePathUsed + " is not in the correct FORMAT. "
+ "Using default config properties");
initializedConfig = new Config();
}
Expand Down Expand Up @@ -188,7 +188,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
Optional<UserPrefs> prefsOptional = storage.readUserPrefs();
initializedPrefs = prefsOptional.orElse(new UserPrefs());
} catch (DataConversionException e) {
logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct format. "
logger.warning("UserPrefs file at " + prefsFilePath + " is not in the correct FORMAT. "
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
Expand Down Expand Up @@ -227,7 +227,7 @@ public void stop() {
} catch (IOException e) {
logger.severe("Failed to save preferences " + StringUtil.getDetails(e));
} catch (DataConversionException e) {
logger.severe("Failed to convert file contents to correct format " + StringUtil.getDetails(e));
logger.severe("Failed to convert file contents to correct FORMAT " + StringUtil.getDetails(e));
}
Platform.exit();
System.exit(0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command FORMAT! \n%1$s";
public static final String MESSAGE_INVALID_WISH_DISPLAYED_INDEX = "The wish index provided is invalid";
public static final String MESSAGE_WISHES_LISTED_OVERVIEW = "%1$d wishes listed!";
public static final String MESSAGE_INVALID_AMOUNT = "Invalid amount! \n%1$s";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean isEarlyAccess() {
}

/**
* Parses a version number string in the format V1.2.3.
* Parses a version number string in the FORMAT V1.2.3.
* @param versionString version number string
* @return a Version object
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.commons.exceptions;

/**
* Represents an error during conversion of data from one format to another
* Represents an error during conversion of data from one FORMAT to another
*/
public class DataConversionException extends Exception {
public DataConversionException(Exception cause) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/util/JsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static <T> T deserializeObjectFromJsonFile(Path jsonFile, Class<T> classOfObject
* If any values are missing from the file, default values will be used, as long as the file is a valid json file.
* @param filePath cannot be null.
* @param classOfObjectToDeserialize Json file has to correspond to the structure in the class given here.
* @throws DataConversionException if the file format is not as expected.
* @throws DataConversionException if the file FORMAT is not as expected.
*/
public static <T> Optional<T> readJsonFile(
Path filePath, Class<T> classOfObjectToDeserialize) throws DataConversionException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/util/XmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class XmlUtil {
* @param classToConvert The class corresponding to the xml data.
* Cannot be null.
* @throws FileNotFoundException Thrown if the file is missing.
* @throws JAXBException Thrown if the file is empty or does not have the correct format.
* @throws JAXBException Thrown if the file is empty or does not have the correct FORMAT.
*/
@SuppressWarnings("unchecked")
public static <T> T getDataFromFile(Path file, Class<T> classToConvert)
Expand All @@ -44,7 +44,7 @@ public static <T> T getDataFromFile(Path file, Class<T> classToConvert)
}

/**
* Saves the data in the file in xml format.
* Saves the data in the file in xml FORMAT.
*
* @param file Points to a valid xml file containing data that match the {@code classToConvert}.
* Cannot be null.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE

@Override
public ObservableList<Wish> getFilteredWishList() {
return model.getFilteredWishList();
return model.getFilteredSortedWishList();
}

@Override
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRICE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -23,17 +23,17 @@ public class AddCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a wish to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PRICE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_URL + "ADDRESS "
+ PREFIX_PRICE + "PRICE "
+ PREFIX_DATE + "DATE "
+ "[" + PREFIX_URL + "URL] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PRICE + "60.50 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_NAME + "iPad 10 "
+ PREFIX_PRICE + "6080.50 "
+ PREFIX_DATE + "20/11/2021 "
+ PREFIX_URL + "https://www.amazon.com/gp/product/B07D998212 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_TAG + "electronics "
+ PREFIX_TAG + "personal ";

public static final String MESSAGE_SUCCESS = "New wish added: %1$s";
public static final String MESSAGE_DUPLICATE_WISH = "This wish already exists in the address book";
Expand Down Expand Up @@ -67,4 +67,14 @@ public boolean equals(Object other) {
|| (other instanceof AddCommand // instanceof handles nulls
&& toAdd.equals(((AddCommand) other).toAdd));
}

/**
* A weaker notion of equality between {@code AddCommand}.
*/
public boolean isSameAs(AddCommand other) {
return other == this
|| toAdd.getName().equals(other.toAdd.getName())
&& toAdd.getPrice().equals(other.toAdd.getPrice())
&& toAdd.getDate().equals(other.toAdd.getDate());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Wish> lastShownList = model.getFilteredWishList();
List<Wish> lastShownList = model.getFilteredSortedWishList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_WISH_DISPLAYED_INDEX);
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRICE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -10,10 +10,10 @@

import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
Expand All @@ -23,7 +23,7 @@

import seedu.address.model.Model;
import seedu.address.model.tag.Tag;
import seedu.address.model.wish.Email;
import seedu.address.model.wish.Date;
import seedu.address.model.wish.Name;
import seedu.address.model.wish.Price;
import seedu.address.model.wish.Remark;
Expand All @@ -45,12 +45,12 @@ public class EditCommand extends Command {
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PRICE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_DATE + "EMAIL] "
+ "[" + PREFIX_URL + "URL] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PRICE + "60.60 "
+ PREFIX_EMAIL + "[email protected]";
+ PREFIX_DATE + "[email protected]";

public static final String MESSAGE_EDIT_WISH_SUCCESS = "Edited Wish: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand All @@ -74,7 +74,7 @@ public EditCommand(Index index, EditWishDescriptor editWishDescriptor) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Wish> lastShownList = model.getFilteredWishList();
List<Wish> lastShownList = model.getFilteredSortedWishList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_WISH_DISPLAYED_INDEX);
Expand Down Expand Up @@ -102,16 +102,15 @@ private static Wish createEditedWish(Wish wishToEdit, EditWishDescriptor editWis

Name updatedName = editWishDescriptor.getName().orElse(wishToEdit.getName());
Price updatedPrice = editWishDescriptor.getPrice().orElse(wishToEdit.getPrice());
Email updatedEmail = editWishDescriptor.getEmail().orElse(wishToEdit.getEmail());
Date updatedDate = editWishDescriptor.getDate().orElse(wishToEdit.getDate());
Url updatedUrl = editWishDescriptor.getUrl().orElse(wishToEdit.getUrl());
SavedAmount savedAmount = wishToEdit.getSavedAmount(); // edit command does not allow editing remarks
Remark remark = wishToEdit.getRemark(); // cannot modify remark with edit command
Set<Tag> updatedTags = editWishDescriptor.getTags().orElse(wishToEdit.getTags());
LinkedList<Wish> transactions = wishToEdit.getTransactions(); // no editing of transactions
UUID originalUuid = wishToEdit.getId();

return new Wish(updatedName, updatedPrice, updatedEmail, updatedUrl, savedAmount, remark,
updatedTags,
transactions);
return new Wish(updatedName, updatedPrice, updatedDate, updatedUrl,
savedAmount, remark, updatedTags, originalUuid);
}

@Override
Expand Down Expand Up @@ -139,7 +138,7 @@ public boolean equals(Object other) {
public static class EditWishDescriptor {
private Name name;
private Price price;
private Email email;
private Date date;
private Url url;
private Set<Tag> tags;

Expand All @@ -152,7 +151,7 @@ public EditWishDescriptor() {}
public EditWishDescriptor(EditWishDescriptor toCopy) {
setName(toCopy.name);
setPrice(toCopy.price);
setEmail(toCopy.email);
setDate(toCopy.date);
setUrl(toCopy.url);
setTags(toCopy.tags);
}
Expand All @@ -161,7 +160,7 @@ public EditWishDescriptor(EditWishDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, price, email, url, tags);
return CollectionUtil.isAnyNonNull(name, price, date, url, tags);
}

public void setName(Name name) {
Expand All @@ -180,12 +179,12 @@ public Optional<Price> getPrice() {
return Optional.ofNullable(price);
}

public void setEmail(Email email) {
this.email = email;
public void setDate(Date date) {
this.date = date;
}

public Optional<Email> getEmail() {
return Optional.ofNullable(email);
public Optional<Date> getDate() {
return Optional.ofNullable(date);
}

public void setUrl(Url url) {
Expand Down Expand Up @@ -230,7 +229,7 @@ public boolean equals(Object other) {

return getName().equals(e.getName())
&& getPrice().equals(e.getPrice())
&& getEmail().equals(e.getEmail())
&& getDate().equals(e.getDate())
&& getUrl().equals(e.getUrl())
&& getTags().equals(e.getTags());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredWishList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_WISHES_LISTED_OVERVIEW, model.getFilteredWishList().size()));
String.format(Messages.MESSAGE_WISHES_LISTED_OVERVIEW, model.getFilteredSortedWishList().size()));
}

@Override
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/seedu/address/logic/commands/RemarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public RemarkCommand(Index index, Remark remark) {

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
List<Wish> lastShownList = model.getFilteredWishList();
List<Wish> lastShownList = model.getFilteredSortedWishList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_WISH_DISPLAYED_INDEX);
Expand All @@ -61,9 +61,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
* with updated Remark.
*/
private static Wish createUpdatedRemarkWish(Wish wishToEdit, Remark remark) {
return new Wish(wishToEdit.getName(), wishToEdit.getPrice(), wishToEdit.getEmail(),
wishToEdit.getUrl(), wishToEdit.getSavedAmount(), remark, wishToEdit.getTags(),
wishToEdit.getTransactions());
return new Wish(wishToEdit.getName(), wishToEdit.getPrice(), wishToEdit.getDate(),
wishToEdit.getUrl(), wishToEdit.getSavedAmount(), remark, wishToEdit.getTags(), wishToEdit.getId());
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/SaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SaveCommand(Index index, Amount amountToSave) {

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
List<Wish> lastShownList = model.getFilteredWishList();
List<Wish> lastShownList = model.getFilteredSortedWishList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_WISH_DISPLAYED_INDEX);
Expand All @@ -59,9 +59,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
String differenceString = "";

try {
Wish editedWish = new Wish(wishToEdit.getName(), wishToEdit.getPrice(), wishToEdit.getEmail(),
Wish editedWish = new Wish(wishToEdit.getName(), wishToEdit.getPrice(), wishToEdit.getDate(),
wishToEdit.getUrl(), wishToEdit.getSavedAmount().incrementSavedAmount(amountToSave),
wishToEdit.getRemark(), wishToEdit.getTags(), wishToEdit.getTransactions());
wishToEdit.getRemark(), wishToEdit.getTags(), wishToEdit.getId());

model.updateWish(wishToEdit, editedWish);
model.updateFilteredWishList(PREDICATE_SHOW_ALL_WISHES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SelectCommand(Index targetIndex) {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

List<Wish> filteredWishList = model.getFilteredWishList();
List<Wish> filteredWishList = model.getFilteredSortedWishList();

if (targetIndex.getZeroBased() >= filteredWishList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_WISH_DISPLAYED_INDEX);
Expand Down
Loading

0 comments on commit 75f298f

Please sign in to comment.