Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ListCommand.java #29

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading