From 0a7ba07aba56f9d2166a2bcf728201bdee8cd490 Mon Sep 17 00:00:00 2001 From: XavierLiau34 Date: Thu, 14 Mar 2024 01:30:30 +0800 Subject: [PATCH] Parser --- src/main/java/seedu/binbash/Parser.java | 2 ++ src/main/java/seedu/duke/Parser.java | 46 ------------------------- 2 files changed, 2 insertions(+), 46 deletions(-) create mode 100644 src/main/java/seedu/binbash/Parser.java delete mode 100644 src/main/java/seedu/duke/Parser.java diff --git a/src/main/java/seedu/binbash/Parser.java b/src/main/java/seedu/binbash/Parser.java new file mode 100644 index 0000000000..09d25b3c17 --- /dev/null +++ b/src/main/java/seedu/binbash/Parser.java @@ -0,0 +1,2 @@ +package seedu.binbash;public class Parser { +} diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java deleted file mode 100644 index 97ee21be0b..0000000000 --- a/src/main/java/seedu/duke/Parser.java +++ /dev/null @@ -1,46 +0,0 @@ -package seedu.binbash.parser; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import seedu.binbash.ItemList; -import seedu.binbash.command.Command; -import seedu.binbash.command.DeleteCommand; -import seedu.binbash.command.ListCommand; - -public class Parser { - private final ItemList itemList; - - public Parser(ItemList itemList) { - this.itemList = itemList; - } - - public Command parseCommand(String userInput) { - String[] tokens = userInput.trim().split("\\s+", 2); - String commandString = tokens[0].toLowerCase(); - String arguments = tokens.length > 1 ? tokens[1] : ""; - - switch (commandString) { - case "delete": - return parseDeleteCommand(arguments); - case "list": - return parseListCommand(arguments); - default: - return null; - } - } - - private Command parseDeleteCommand(String arguments) { - Matcher matcher = DeleteCommand.COMMAND_FORMAT.matcher(arguments); - if (matcher.matches()) { - int index = Integer.parseInt(matcher.group("index")); - return new DeleteCommand(itemList, index); - } else { - return null; - } - } - - private Command parseListCommand(String arguments) { - return new ListCommand(itemList); - } -}