Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.core;
- public enum Response {
- BYE("(?i)^b(ye)?\\s*", (i, s) -> {
- Printer.printString("Bye. Hope to see you again soon!");
- s.toExit = true;
- s.lastError = false;
- return true;
- }),
- RESPONDER_NAME("regex", (commandInput, programState) -> {
- // carry out command
- return true; // capture is valid, end checking other commands
- return false; // even though match, keep checking other commands match
- });
- private String regex;
- private ResponseFunc func;
- Response(String r, ResponseFunc f) {
- regex = r;
- func = f;
- }
- /**
- * Given a string and program state, if string matches regex this enum will call its response
- * function.
- *
- * @param i input string
- * @param s state object
- * @return boolean if the string has matched
- */
- public boolean call(String i, State s) {
- if (i.matches(regex)) {
- return func.funcCall(i, s);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement