diff --git a/src/main/java/seedu/foodrem/commons/core/Messages.java b/src/main/java/seedu/foodrem/commons/core/Messages.java index 8ad6e0c6f2a..d58af023923 100644 --- a/src/main/java/seedu/foodrem/commons/core/Messages.java +++ b/src/main/java/seedu/foodrem/commons/core/Messages.java @@ -7,11 +7,17 @@ public class Messages { public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command. Enter \"help\" to view all commands."; public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_ITEMS_DISPLAYED_INDEX = "The item index provided is invalid."; - // TODO: Fix "1 items listed" grammar bug instead of "1 item listed" - public static final String MESSAGE_ITEMS_LISTED_OVERVIEW = "%1$d items listed!"; - // TODO: Fix "1 items sorted" grammar bug instead of "1 item sorted" + + // Singular + public static final String MESSAGE_ITEMS_LISTED_OVERVIEW = "%1$d item listed!"; + public static final String MESSAGE_ITEM_SORTED_OVERVIEW = "%1$d item sorted!"; + public static final String MESSAGE_ITEM_FILTERED_OVERVIEW = "%1$d item after filtering!"; + + // Plural or Zero + public static final String MESSAGE_ITEM_LISTED_OVERVIEW = "%1$d items listed!"; public static final String MESSAGE_ITEMS_SORTED_OVERVIEW = "%1$d items sorted!"; public static final String MESSAGE_ITEMS_FILTERED_OVERVIEW = "%1$d items after filtering!"; + public static final String MESSAGE_NON_POSITIVE_INDEX = "The index of an item should be a positive number."; } diff --git a/src/main/java/seedu/foodrem/logic/commands/itemcommands/FilterTagCommand.java b/src/main/java/seedu/foodrem/logic/commands/itemcommands/FilterTagCommand.java index 035d47326ea..7c987657c62 100644 --- a/src/main/java/seedu/foodrem/logic/commands/itemcommands/FilterTagCommand.java +++ b/src/main/java/seedu/foodrem/logic/commands/itemcommands/FilterTagCommand.java @@ -40,7 +40,10 @@ public CommandResult execute(Model model) throws CommandException { model.updateFilteredItemList(predicate); String primaryMessage = "Filtered by tag:"; - String secondaryMessage = String.format("%s items filtered", model.getCurrentList().size()); + String secondaryMessage = String.format(model.getCurrentList().size() == 1 + ? "%s item filtered" + : "%s items filtered", + model.getCurrentList().size()); return CommandResult.from(new FilterByTag(tag, primaryMessage, secondaryMessage)); } diff --git a/src/main/java/seedu/foodrem/logic/commands/itemcommands/FindCommand.java b/src/main/java/seedu/foodrem/logic/commands/itemcommands/FindCommand.java index c1787166620..bf9c0f1bb41 100644 --- a/src/main/java/seedu/foodrem/logic/commands/itemcommands/FindCommand.java +++ b/src/main/java/seedu/foodrem/logic/commands/itemcommands/FindCommand.java @@ -31,7 +31,10 @@ public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredItemList(predicate); return CommandResult.from( - String.format(Messages.MESSAGE_ITEMS_LISTED_OVERVIEW, model.getCurrentList().size())); + String.format(model.getCurrentList().size() == 1 + ? Messages.MESSAGE_ITEM_FILTERED_OVERVIEW + : Messages.MESSAGE_ITEMS_FILTERED_OVERVIEW, + model.getCurrentList().size())); } /** diff --git a/src/main/java/seedu/foodrem/logic/commands/itemcommands/SortCommand.java b/src/main/java/seedu/foodrem/logic/commands/itemcommands/SortCommand.java index a83b22fad97..eacce232fdc 100644 --- a/src/main/java/seedu/foodrem/logic/commands/itemcommands/SortCommand.java +++ b/src/main/java/seedu/foodrem/logic/commands/itemcommands/SortCommand.java @@ -40,7 +40,9 @@ public SortCommand(Comparator comparator) { public CommandResult execute(Model model) { requireNonNull(model); model.updateSortedItemList(comparator); - return CommandResult.from(String.format(Messages.MESSAGE_ITEMS_SORTED_OVERVIEW, + return CommandResult.from(String.format(model.getCurrentList().size() == 1 + ? Messages.MESSAGE_ITEM_SORTED_OVERVIEW + : Messages.MESSAGE_ITEMS_SORTED_OVERVIEW, model.getCurrentList().size())); } diff --git a/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java b/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java index ab833f84abd..4ee838b0e46 100644 --- a/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java +++ b/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static seedu.foodrem.commons.core.Messages.MESSAGE_ITEMS_LISTED_OVERVIEW; +import static seedu.foodrem.commons.core.Messages.MESSAGE_ITEMS_FILTERED_OVERVIEW; import static seedu.foodrem.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.foodrem.testutil.TypicalFoodRem.getTypicalFoodRem; import static seedu.foodrem.testutil.TypicalItems.CUCUMBERS; @@ -54,7 +54,7 @@ public void equals() { @Test public void execute_zeroKeywords_noItemsFound() { - String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 2); + String expectedMessage = String.format(MESSAGE_ITEMS_FILTERED_OVERVIEW, 2); NameContainsKeywordsPredicate predicate = preparePredicate(" "); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredItemList(predicate); @@ -63,8 +63,8 @@ public void execute_zeroKeywords_noItemsFound() { } @Test - public void execute_multipleKeywords_multipleItemsFound() { - String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 0); + public void execute_multipleKeywords_zeroItemsFound() { + String expectedMessage = String.format(MESSAGE_ITEMS_FILTERED_OVERVIEW, 0); NameContainsKeywordsPredicate predicate = preparePredicate("Potatoes Cucumbers Carrots"); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredItemList(predicate);