Skip to content

Commit

Permalink
Merge pull request #29 from nur-haziq/AddListCommand
Browse files Browse the repository at this point in the history
Add ListCommand.java
  • Loading branch information
YHWong20 authored Mar 13, 2024
2 parents ab50b47 + 24d8f4c commit f1621c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/seedu/binbash/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/seedu/binbash/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit f1621c4

Please sign in to comment.