diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index 4e1cf42ffc..7ecaafda17 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -29,6 +29,26 @@ public String deleteItem(int index) { return output; } + /** + * DO LET ME KNOW IF THE METHOD NAME IS WEIRD. IM RETURNING A STRING REPRESENTATION INSTEAD + * OF CALLING SOUT TO STAY CONSISTENT WITH THE OTHER COMMANDS BEHAVIOUR. SO IT DOESN'T ACTUALLY + * PRINT THE LIST. IF THERES A BETTER NAME LMK THANKS + * + * Returns a string representation of all the items in the list. Each item's string + * representation is obtained by calling its `toString` method. + * + * @return A concatenated string of all item representations in the list, each on a new line. + */ + public String printList() { + String output = ""; + + for (Item item: itemList) { + output += item.toString() + System.lineSeparator(); + } + + return output; + } + @Override public String toString() { return itemList.toString(); diff --git a/src/main/java/seedu/binbash/command/ListCommand.java b/src/main/java/seedu/binbash/command/ListCommand.java new file mode 100644 index 0000000000..1eac5c4804 --- /dev/null +++ b/src/main/java/seedu/binbash/command/ListCommand.java @@ -0,0 +1,20 @@ +package seedu.binbash.command; + +import seedu.binbash.ItemList; +import java.util.regex.Pattern; + +public class ListCommand extends Command { + + public static final String COMMAND_STRING = "list"; + public static final Pattern COMMAND_FORMAT = + Pattern.compile("^list"); + + + public ListCommand(ItemList itemList) { + super(itemList); + } + + public String execute() { + return itemList.printList(); + } +}