From f0a04b45407e1833598c479f73f4b865f0c63d95 Mon Sep 17 00:00:00 2001 From: Denise-Ng Date: Thu, 9 Apr 2020 23:00:48 +0800 Subject: [PATCH] Minor changes --- docs/AboutUs.adoc | 2 +- docs/team/{deniseng.adoc => denise-ng.adoc} | 0 .../logic/commands/CopyCommand.java | 4 +-- .../logic/commands/ExpiringCommand.java | 23 ++++++--------- .../logic/commands/GoToCommand.java | 1 + .../logic/commands/ListCommand.java | 29 +++++++++++++++---- 6 files changed, 37 insertions(+), 22 deletions(-) rename docs/team/{deniseng.adoc => denise-ng.adoc} (100%) diff --git a/docs/AboutUs.adoc b/docs/AboutUs.adoc index 63e454e4f71..40fb0808817 100644 --- a/docs/AboutUs.adoc +++ b/docs/AboutUs.adoc @@ -50,7 +50,7 @@ Responsibilities: Remind Feature of Coupon Stash === Denise Ng image::denise-ng.png[width="150", align="left"] -{empty}[http://github.com/denise-ng[github]] [<>] +{empty}[http://github.com/denise-ng[github]] [<>] Role: Developer + Responsibilities: Expiring, copy and goto features & calendar in Coupon Stash. diff --git a/docs/team/deniseng.adoc b/docs/team/denise-ng.adoc similarity index 100% rename from docs/team/deniseng.adoc rename to docs/team/denise-ng.adoc diff --git a/src/main/java/csdev/couponstash/logic/commands/CopyCommand.java b/src/main/java/csdev/couponstash/logic/commands/CopyCommand.java index ee2d44cc32e..7f7d34d92e8 100644 --- a/src/main/java/csdev/couponstash/logic/commands/CopyCommand.java +++ b/src/main/java/csdev/couponstash/logic/commands/CopyCommand.java @@ -64,6 +64,7 @@ public CommandResult execute(Model model, String commandText) throws CommandExce } public String getCopiedString(Coupon coupon) { + assert coupon != null : "coupon should not be null"; Savings savings = coupon.getSavingsForEachUse(); String totalSavings = ""; if (savings.hasMonetaryAmount()) { @@ -87,8 +88,7 @@ public String getCopiedString(Coupon coupon) { conditionString = PREFIX_CONDITION + condition.value + " "; } - String copyCommand = couponAsAddCommand(coupon, totalSavings, conditionString); - return copyCommand; + return couponAsAddCommand(coupon, totalSavings, conditionString); } /** diff --git a/src/main/java/csdev/couponstash/logic/commands/ExpiringCommand.java b/src/main/java/csdev/couponstash/logic/commands/ExpiringCommand.java index 4c4163861ea..8a412250297 100644 --- a/src/main/java/csdev/couponstash/logic/commands/ExpiringCommand.java +++ b/src/main/java/csdev/couponstash/logic/commands/ExpiringCommand.java @@ -33,11 +33,13 @@ public class ExpiringCommand extends Command { private final String date; public ExpiringCommand(DateIsEqualsPredicate predicate) { + requireNonNull(predicate); this.predicate = predicate; this.date = predicate.getDate(); } public ExpiringCommand(DateIsInMonthYearPredicate predicate) { + requireNonNull(predicate); this.predicate = predicate; this.date = predicate.getDate(); } @@ -57,20 +59,13 @@ public CommandResult execute(Model model, String commandText) { model.updateFilteredCouponList(predicate); int filteredListSize = model.getFilteredCouponList().size(); - if (filteredListSize > 0) { - if (DateUtil.isValidDate(date)) { - model.updateMonthView(DateUtil.formatDateStringToYearMonthString(date)); - return new CommandResult(String.format(Messages.MESSAGE_COUPONS_EXPIRING_ON_DATE, - filteredListSize, date)); - } else { - model.updateMonthView(date); - return new CommandResult(String.format(Messages.MESSAGE_COUPONS_EXPIRING_DURING_YEAR_MONTH, - filteredListSize, date)); - } - } else { // Empty list - assert filteredListSize == 0 : "Filtered list should be empty."; - model.updateMonthView(DateUtil.formatYearMonthToString(YearMonth.now())); - return new CommandResult(String.format(Messages.MESSAGE_NO_COUPONS_EXPIRING, date)); + if (DateUtil.isValidDate(date)) { + model.updateMonthView(DateUtil.formatDateStringToYearMonthString(date)); + return new CommandResult(String.format(Messages.MESSAGE_COUPONS_EXPIRING_ON_DATE,filteredListSize, date)); + } else { + model.updateMonthView(date); + return new CommandResult(String.format(Messages.MESSAGE_COUPONS_EXPIRING_DURING_YEAR_MONTH, + filteredListSize, date)); } } diff --git a/src/main/java/csdev/couponstash/logic/commands/GoToCommand.java b/src/main/java/csdev/couponstash/logic/commands/GoToCommand.java index 9d400fb1fd2..6f37e6c9f13 100644 --- a/src/main/java/csdev/couponstash/logic/commands/GoToCommand.java +++ b/src/main/java/csdev/couponstash/logic/commands/GoToCommand.java @@ -23,6 +23,7 @@ public class GoToCommand extends Command { private String value; public GoToCommand(String yearMonth) { + requireNonNull(yearMonth); this.value = yearMonth; } diff --git a/src/main/java/csdev/couponstash/logic/commands/ListCommand.java b/src/main/java/csdev/couponstash/logic/commands/ListCommand.java index 4237045eb48..bb9dc0e7d16 100644 --- a/src/main/java/csdev/couponstash/logic/commands/ListCommand.java +++ b/src/main/java/csdev/couponstash/logic/commands/ListCommand.java @@ -30,6 +30,8 @@ public class ListCommand extends Command { + COMMAND_WORD + " " + PREFIX_USAGE + " (used coupons list)\n"; private Prefix prefixToList; + private Views view; + public ListCommand() { this.prefixToList = new Prefix(""); @@ -44,18 +46,18 @@ public ListCommand(Prefix prefixToList) { public CommandResult execute(Model model, String commandText) { requireNonNull(model); model.updateMonthView(DateUtil.formatYearMonthToString(YearMonth.now())); - String view = ""; + if (prefixToList.toString().isEmpty()) { model.updateFilteredCouponList(Model.PREDICATE_SHOW_ALL_ACTIVE_COUPONS); - view = "active"; + view = Views.ACTIVE; } else if (prefixToList.equals(PREFIX_ARCHIVE)) { model.updateFilteredCouponList(Model.PREDICATE_SHOW_ALL_ARCHIVED_COUPONS); - view = "archived"; + view = Views.ARCHIVED; } else if (prefixToList.equals(PREFIX_USAGE)) { model.updateFilteredCouponList(Model.PREDICATE_SHOW_ALL_USED_COUPONS); - view = "used"; + view = Views.USED; } - return new CommandResult(String.format(MESSAGE_SUCCESS, view)); + return new CommandResult(String.format(MESSAGE_SUCCESS, view.getView())); } @Override @@ -74,4 +76,21 @@ public boolean equals(Object other) { ListCommand e = (ListCommand) other; return prefixToList.equals((e).prefixToList); } + + + private enum Views { + ACTIVE ("active"), + ARCHIVED ("archived"), + USED ("used"); + + private final String view; + + Views(String view) { + this.view = view; + } + + String getView() { + return this.view; + } + } }