forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from PureUsagi/feature-DeleteCommand
Command and DeleteCommand Feature
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package seedu.binbash.command; | ||
|
||
import java.util.regex.Pattern; | ||
import seedu.binbash.ItemList; | ||
|
||
public abstract class Command { | ||
public static final String COMMAND_STRING = "command"; | ||
public static final Pattern COMMAND_FORMAT = | ||
Pattern.compile("(?<command>\\S+)(?<arguments>.*)"); | ||
protected ItemList itemList; | ||
|
||
protected Command(ItemList itemList) { | ||
this.itemList = itemList; | ||
} | ||
|
||
public abstract String execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package seedu.binbash.command; | ||
|
||
import java.util.regex.Pattern; | ||
import seedu.binbash.ItemList; | ||
|
||
public class DeleteCommand extends Command { | ||
public static final String COMMAND_STRING = "delete"; | ||
public static final Pattern COMMAND_FORMAT = | ||
Pattern.compile("delete\\s(?<index>\\d+)"); | ||
protected int index; | ||
|
||
public DeleteCommand(ItemList itemList, int index) { | ||
super(itemList); | ||
|
||
this.index = index; | ||
} | ||
|
||
public String execute() { | ||
return itemList.deleteItem(index); | ||
} | ||
} |