So I'm trying to write an application that has an in-program console interface (I.e. you don't have to run the program from the console with a different command each time), and I want to have a parser object that parses commands/options that come in from the user. The structure is similar to this -
ArrayList<String> example = new ArrayList<>();
/* PARSING */
ConsoleParser parser = new ConsoleParser();
Scanner input = new Scanner(System.in);
String parserArgs = input.nextLine();
while (parserArgs != "quit")
{
execute(parser.parse(parserArgs));
parserArgs = input.nextLine();
}
So the idea is to have a console (within the application), where I can type commands like 'add x' or 'contains x' which would then be assigned to 'parserArgs.' Then the command string would be passed to the ConsoleParser where it would be dissected and searched for valid commands. If the command is valid (and has necessary options/arguments), the parse() method of ConsoleParser would somehow return the method (or name of method) to main, along with any arguments that method needs. So if I want to add the string "foo" to my ArrayList, then at the console I could type 'add foo' and that would be passed to the parser, which would then return to main some kind of instruction that the add() method of ArrayList needs to be called on 'example' with the argument 'foo.' I Know this could be easily done with an arraylist, but I just use it here for simplicity.